From b95e2e21e34a884cc7a595ecb74a0d9643a102f1 Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Mon, 11 Sep 2023 00:12:44 -0700 Subject: [PATCH] feat: Handle additional syntax * Converts all Lighting nodes into the output * Translates Title Info and SceneInfo Info into a WorldInfo node * Translates Viewer Info into a NavigationInfo node * Captures the creaseAngle parameter * Also, this commit documents the API (such as it is) Resolves #9. Resolves #10. --- README.md | 23 ++++++++++++++++ package.json5 | 2 +- src/index.civet | 73 +++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 85 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 2f2dfc3..4ccf53b 100644 --- a/README.md +++ b/README.md @@ -33,3 +33,26 @@ or from the command line via node ```shell npx vrml1to97 < old.wrl > shinynew.wrl ``` + +## API + +Currently this package exports just two functions: + + * convert(vrml1: string): string + The main function, takes in VRML 1 syntax (note that it does not + actually check that its input is VRML 1, so its behavior is undefined + if given anything but valid VRML 1 syntax). Returns VRML 97 syntax for + the same scene, as nearly as it can translate. Note that not all of + VRML 1 is recognized, and some of the translations may be somewhat + approximate. + + * tree97(vrml1: string): Tree + Takes the same input as convert, but rathre than returning a string, it + returns a very rough syntax tree for the converted VRML97 scene. The + returned Tree data structure is an object whose keys are property names + and whose values are lists of either strings or sub-Trees. Note however + that this syntax tree does not represent a complete parse; since VRML 1 + and VRML97 are close, whole blocks of syntax are left as strings rather + than broken into node names and property values. If there is a need to + generate XML syntax output, for example, the code would need to be + modified to break the tree down further to be ready for conversion to XML. diff --git a/package.json5 b/package.json5 index 83646e2..d3bc019 100644 --- a/package.json5 +++ b/package.json5 @@ -1,6 +1,6 @@ { name: 'vrml1to97', - version: '0.1.3', + version: '0.2.0', description: 'JavaScript converter from VRML 1 to VRML97', scripts: { test: 'echo "Error: no test specified" && exit 1', diff --git a/src/index.civet b/src/index.civet index c627f2f..9b81221 100644 --- a/src/index.civet +++ b/src/index.civet @@ -74,6 +74,18 @@ function findNumbersAtTopLevel( function addChild(child: string | Tree, tree: Tree): void (tree.children ??= []).push child +type WorldInfoNode = {WorldInfo: (string|Tree)[]} | undefined +function addWorldParameter(name: string, value: string, tree: Tree): void + children := tree.children ??= [] + world .= (children.find (x) => + if x .filter .type[0] === 'string' + |> .map .value[0] + |> .join ' ' + addWorldParameter 'info', `[ ${info} ]`, tree + 'Viewer' + // Filter all of the strings, and translate them into + // current viewer names + tr: Record := {'"examiner"': '"EXAMINE"'} + viewers := contents + |> .filter .type[0] === 'string' + |> .map .value[0] as string + |> .map((x) => x in tr ? tr[x] : x.toUpperCase()) + |> .join ' ' + addChild `NavigationInfo { type [ ${viewers} ] }\n`, tree held = filtered stream else held = opener else -- 2.34.1