From 8f79352f438a145552079223110de626d2a69c8f Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Tue, 13 Feb 2024 21:33:28 -0800 Subject: [PATCH] feat: Implement Translations Also fixes bug: Translations and Rotations should not be inherited into inner grouping nodes. --- README.md | 2 +- package.json5 | 2 +- src/index.civet | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 29921ba..35c4d01 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ VRML 1.0. Overall, it recognizes and converts * All Light nodes * Grouping nodes including Transform, Separator, Group, Switch, and WWWAnchor * ShapeHints - * Rotations + * Rotations and Translations * All shape nodes including Cube, Cone, Cylinder, Sphere, IndexedFaceSet, IndexedLineSet, PointSet, Coordinate3, and Normal * All material nodes including Material, TextureCoordinate2, and Texture2 diff --git a/package.json5 b/package.json5 index 11ccdeb..e979332 100644 --- a/package.json5 +++ b/package.json5 @@ -1,6 +1,6 @@ { name: 'vrml1to97', - version: '0.3.0', + version: '0.3.1', 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 9572faf..60dc7d2 100644 --- a/src/index.civet +++ b/src/index.civet @@ -205,13 +205,16 @@ function parse(stream: Lexer, tree: DefTree = {}): DefTree matches GroupNode parent := held.value.endsWith('Separator') ? 'Transform' : 'Group' - {children, ...context} := tree + {children, Translation, Rotation, ...context} := tree subTree := parse stream, context if newKids := subTree.children newChild .= `${parent} {\n ` if 'Rotation' in subTree newChild += renderList subTree.Rotation newChild += "\n " + if 'Translation' in subTree + newChild += renderList subTree.Translation + newChild += "\n " newChild += `children [\n ${renderList newKids} ] }\n` addChild newChild, tree 'ShapeHints' @@ -227,6 +230,8 @@ function parse(stream: Lexer, tree: DefTree = {}): DefTree tree._definitions[lastDefinition] = [hints] 'Rotation' tree.Rotation = toksUntilClose stream + 'Translation' + tree.Translation = toksUntilClose stream 'Coordinate3' tree.Coordinate = toksUntilClose stream 'Normal' -- 2.34.1