2023-08-31 07:05:29 +00:00
|
|
|
# vrml1to97
|
|
|
|
|
2023-09-01 15:20:34 +00:00
|
|
|
JavaScript converter from VRML 1.0 to VRML97 file format, based on Wings 3D
|
|
|
|
conversion logic.
|
|
|
|
|
2023-09-05 01:12:55 +00:00
|
|
|
Essentially, this is a JavaScript reimplementation of the algorithm of the
|
2023-09-01 15:20:34 +00:00
|
|
|
"token rearranger" found in the
|
|
|
|
[Wings 3D x3d importer](https://github.com/dgud/wings/blob/master/plugins_src/import_export/x3d_import.erl)
|
|
|
|
(which was written in Erlang).
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
2023-09-05 01:12:55 +00:00
|
|
|
From an es6 module under Node (for example)
|
2023-09-01 15:20:34 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
import {convert} from 'vrml1to97'
|
|
|
|
const vrml1spec = '# VRML 1.0 ....'
|
|
|
|
const vrml97spec = convert(vrml1spec)
|
|
|
|
```
|
|
|
|
|
2023-09-05 01:12:55 +00:00
|
|
|
or from a script in a webpage
|
2023-09-01 15:20:34 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
(async () => {
|
2023-09-01 21:32:25 +00:00
|
|
|
const vrml1to97 = await import('./dist/vrml1to97/index.js')
|
2023-09-01 15:20:34 +00:00
|
|
|
const vrml1spec = '# VRML 1.0 ....'
|
|
|
|
const vrml97spec = vrml1to97.convert(vrml1spec)
|
|
|
|
})()
|
|
|
|
```
|
|
|
|
|
|
|
|
or from the command line via node
|
|
|
|
|
|
|
|
```shell
|
|
|
|
npx vrml1to97 < old.wrl > shinynew.wrl
|
|
|
|
```
|
2023-09-11 07:15:17 +00:00
|
|
|
|
|
|
|
## API
|
|
|
|
|
|
|
|
Currently this package exports just two functions:
|
|
|
|
|
2023-09-12 06:35:29 +00:00
|
|
|
* convert(vrml1: string, source?: string): string
|
2023-09-11 07:17:45 +00:00
|
|
|
|
2023-09-11 07:15:17 +00:00
|
|
|
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.
|
|
|
|
|
2023-09-12 06:35:29 +00:00
|
|
|
If the optional second argument `source` is supplied, `convert` adds
|
|
|
|
a comment indicating that the original vrml1 came from the specified
|
|
|
|
source, before conversion to VRML97.
|
|
|
|
|
2023-09-11 07:15:17 +00:00
|
|
|
* tree97(vrml1: string): Tree
|
2023-09-11 07:17:45 +00:00
|
|
|
|
|
|
|
Takes the same input as convert, but rather than returning a string, it
|
2023-09-11 07:15:17 +00:00
|
|
|
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.
|
2024-02-12 21:10:49 +00:00
|
|
|
|
|
|
|
## Conversion notes
|
|
|
|
|
|
|
|
One sort of geometry common to VRML 1 and VRML97 is the IndexedFaceSet. These
|
|
|
|
often used to render solids. Indeed, the default in VRML97 is to assume they
|
|
|
|
do represent a solid, with the normals pointing outward. Unusual visual effects
|
|
|
|
ensue if the normals are not properly directed (basically, you see through the
|
|
|
|
"front" of the solid and see the "backs" of the faces on the opposite side).
|
|
|
|
As a result, unless the input VRML 1 explicitly includes an explicit
|
|
|
|
vertexOrdering of CLOCKWISE or COUNTERCLOCKWISE, the default solid treatment
|
|
|
|
will be turned off in the VRML97 output, meaning that all faces will be
|
|
|
|
rendered opaque in both directions.
|