vrml1to97/README.md
Glen Whitney 6752ab1348 feat: Handle additional syntax (#12)
* 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.

Reviewed-on: #12
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
Co-committed-by: Glen Whitney <glen@studioinfinity.org>
2023-09-11 07:15:17 +00:00

2.0 KiB

vrml1to97

JavaScript converter from VRML 1.0 to VRML97 file format, based on Wings 3D conversion logic.

Essentially, this is a JavaScript reimplementation of the algorithm of the "token rearranger" found in the Wings 3D x3d importer (which was written in Erlang).

Usage

From an es6 module under Node (for example)

import {convert} from 'vrml1to97'
const vrml1spec = '# VRML 1.0 ....'
const vrml97spec = convert(vrml1spec)

or from a script in a webpage

(async () => {
   const vrml1to97 = await import('./dist/vrml1to97/index.js')
   const vrml1spec = '# VRML 1.0 ....'
   const vrml97spec = vrml1to97.convert(vrml1spec)
})()

or from the command line via node

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.