@kroxilon/usda-parser
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

@kroxilon/usda-parser

Version Node.js CI

Allows parsing of USDA files in NodeJS and the browser.

yarn install @kroxilon/usda-parser

Getting Started

import {parse} from "@kroxilon/usda-parser";

const file = `#usda 1.0
(
    defaultPrim = "hello"
)

def Xform "hello"
{
    custom double3 xformOp:translate = (4, 5, 6)
    uniform token[] xformOpOrder = ["xformOp:translate"]

    def Sphere "world"
    {
        float3[] extent = [(-2, -2, -2), (2, 2, 2)]
        color3f[] primvars:displayColor = [(0, 0, 1)]
        double radius = 2
    }
}`;

const parseResult = parse(inputFile);

console.log(parsedResult, null, '  ');
This should produce:
{
  "version": 1,
  "descriptor": {
    "description": null,
    "assignments": [
      {
        "type": "assignment",
        "keyword": null,
        "identifier": "defaultPrim",
        "value": "hello"
      }
    ]
  },
  "statements": [
    {
      "type": "definition",
      "subType": "def",
      "defType": "Xform",
      "name": "hello",
      "args": [],
      "statements": [
        {
          "type": "declaration",
          "keyword": "custom",
          "defineType": "double3",
          "reference": "xformOp:translate",
          "value": [
            4,
            5,
            6
          ],
          "descriptor": null
        },
        {
          "type": "declaration",
          "keyword": "uniform",
          "defineType": "token[]",
          "reference": "xformOpOrder",
          "value": [
            "xformOp:translate"
          ],
          "descriptor": null
        },
        {
          "type": "definition",
          "subType": "def",
          "defType": "Sphere",
          "name": "world",
          "args": [],
          "statements": [
            {
              "type": "declaration",
              "keyword": null,
              "defineType": "float3[]",
              "reference": "extent",
              "value": [
                [
                  -2,
                  -2,
                  -2
                ],
                [
                  2,
                  2,
                  2
                ]
              ],
              "descriptor": null
            },
            {
              "type": "declaration",
              "keyword": null,
              "defineType": "color3f[]",
              "reference": "primvars:displayColor",
              "value": [
                [
                  0,
                  0,
                  1
                ]
              ],
              "descriptor": null
            },
            {
              "type": "declaration",
              "keyword": null,
              "defineType": "double",
              "reference": "radius",
              "value": 2,
              "descriptor": null
            }
          ]
        }
      ]
    }
  ]
}

Package Sidebar

Install

npm i @kroxilon/usda-parser

Weekly Downloads

460

Version

0.0.4

License

MIT

Unpacked Size

411 kB

Total Files

16

Last publish

Collaborators

  • firtoz