feat: Implement Translations

Also fixes bug: Translations and Rotations should not be inherited
  into inner grouping nodes.
This commit is contained in:
Glen Whitney 2024-02-13 21:33:28 -08:00
parent 1409d39665
commit 8f79352f43
3 changed files with 8 additions and 3 deletions

View File

@ -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

View File

@ -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',

View File

@ -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'