From 029bb7650cd51690af39e62d6e712d5e5ca0177f Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Mon, 4 Sep 2023 23:25:11 -0700 Subject: [PATCH] feat: Detect background color info in VRML 1 and encode it in VRML 97 Resolves #7 --- package.json5 | 2 +- src/index.civet | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/package.json5 b/package.json5 index 19b756e..23575a6 100644 --- a/package.json5 +++ b/package.json5 @@ -1,6 +1,6 @@ { name: 'vrml1to97', - version: '0.1.0', + version: '0.1.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 a9b6057..c627f2f 100644 --- a/src/index.civet +++ b/src/index.civet @@ -143,14 +143,27 @@ function parse(stream: Lexer, tree: Tree = {}): Tree else parse stream // discard the subgroup held = filtered stream - if not held or held.type === 'cbrace' then break {ht: 'word', hv: 'vertexOrdering', nt: 'word', nv: 'COUNTERCLOCKWISE'} tree.vertexOrdering = ['ccw'] held = filtered stream - if not held or held.type === 'cbrace' then break + {ht: 'word', hv: 'BackgroundColor', nt: 'word', nv: 'Info'} + opener := filtered stream + if opener and opener.type === 'obrace' + contents := toksUntilClose stream + // Find the first string token and assume it is the color + stok := contents.find .type[0] === 'string' + colorString := stok?.value[0] + if colorString and typeof colorString === 'string' + color := colorString.replace /^"|"$/g, '' + addChild `Background { + groundColor [ ${color} ] + skyColor [ ${color} ] + }\n`, tree + held = filtered stream + else held = opener else held = next // ignore unknown words - if not held or held.type === 'cbrace' then break + if not held or held.type === 'cbrace' then break if held and held.type !== 'cbrace' console.log 'Oddly ended up with held', held tree -- 2.34.1