Skip to main content

A VRML (.wrl) parser library

Project description

wrlparser

Python library to parse VRML files (.wrl) using an LALR parser with a Context-Free Grammar.

Getting started

Installing

pip install wrlparser

Sample program

This program parses the file which name has been given as a command line argument. Two sample models have been provided in the tests/models folder.

from wrlparser import parse
import sys

file = sys.argv[1]
with open(file) as f:
    l = "".join(f.readlines())
    f.close()

scene = parse(l)

Documentation

Context-Free Grammar

This parser is based on the grammar provided by the VRML97 specification. The grammar described in the specification is a Context-Sensitive Grammar which isn't deterministic. The following changes have been made to make it a Context-Free Grammar.

  • Recursive rules have been generalized to allow collections to be empty as this will resolve shift/reduce conflicts. This should only broaden the spectrum of parsable files.
elements : element                  elements : element elements
         | element elements    ->            | empty      
         | empty                     
  • IDs have been optimized to the raw ID type

  • Field values have been optimized to the raw type

sffloatValue :
sfcolorValue :
sfvec2fValue :  ->  sffloatValues : FLOAT sffloatValues
sfvec3fValue :                    | empty
...

Intermediate Representation (IR)

Once parsed, the file's content is returned to the user as classes. Their structure strictly corresponds to the one described in the specification.

For instance, a material node has the following fields :

  - ambientIntensity : float
  - diffuseColor     : list[3]
  - specularColor    : list[3]
  - emissiveColor    : list[3]
  - transparency     : float
  - shininess        : float

It should be noted that the specification doesn't require a file to specify every field of a node. They should therefore be check before accessed as follows:

m = Material()
if m.ambientIntensity != None:
  # Use the value

Tests

This parser has been tester with models from the KiCad catalog.

Issues

Even though the parser fully supports VRML's grammar, a very small subset of the intermediate representation has been implemented. This is due to the lack of test models for specific node types.

If you every need to parse a file which has an unimplemented feature, feel free to share the file in a ticket so that I can support it.

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wrlparser-1.0.tar.gz (75.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wrlparser-1.0-py3-none-any.whl (65.7 kB view details)

Uploaded Python 3

File details

Details for the file wrlparser-1.0.tar.gz.

File metadata

  • Download URL: wrlparser-1.0.tar.gz
  • Upload date:
  • Size: 75.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for wrlparser-1.0.tar.gz
Algorithm Hash digest
SHA256 fd13a14b45b050516a9cf34d2d2f4364ca1cd15b371ce625bb7399250e8c55fa
MD5 62f2b32fed554374a3fc3ece030d04cb
BLAKE2b-256 91ebd3b11e00c17c2432f9557bbb38b9997f8af69e53402c7b5334e0ee9f3b99

See more details on using hashes here.

File details

Details for the file wrlparser-1.0-py3-none-any.whl.

File metadata

  • Download URL: wrlparser-1.0-py3-none-any.whl
  • Upload date:
  • Size: 65.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for wrlparser-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 89ea20615b755f1d36f83ded9d20d3d13c1927f5a44d0b0199cf702dee4e488d
MD5 07172a465e698527d61e4acc0559b4b5
BLAKE2b-256 dc0321b61bd0d06e952161766f941b6d2f6f6980d56a74b9872475500eeb30a5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page