npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

obj-model-parser

v1.0.13

Published

This is a simple parser for the Wavefront .obj file format.

Downloads

8

Readme

obj-model-parser

This is a simple parser for the Wavefront .obj file format.

If you like it, give me a star on GitHub stars

To use the parser, simply import parseObj, which is a function that takes a string, the content of the obj file, and returns the parsed object.

For example,

import parseObj from "obj-model-parser";

const objContent = `
v 0.0 0.0 0.0
`;

const parsedObj = parseObj(objContent);

The following code will present you with its return type.

In the following code, d is import * as d from "obj-parser/directives/base";, which contains certain structures that saves the corresponding data. For example, for geometric vertices, d.GeometricVertex is a structure that contains the x, y, and z coordinates of the vertex.

The returned type is as follows,

{
    vertexData: {
        geometricVertices: d.GeometricVertex[];
        vertexNormals: d.VertexNormal[];
        parameterSpaceVertices: d.ParameterSpaceVertex[];
        textureVertices: d.TextureVertex[];
    },
    materialLibraries: d.MaterialLibraries[],
    objects: {
        name: string | undefined;
        groups: {
            groupNames: string[] | undefined;
            mergingGroup: d.MergingGroup | undefined;
            smoothingGroup: d.SmoothingGroup | undefined;
            componentsChunks: {
                attributes: ComponentsChunkAttributes;
                polygons: (d.Polygon | d.Line | d.Face)[];
                freeforms: {
                    attributes: {
                        uBmat: d.FreeformBmat | undefined;
                        vBmat: d.FreeformBmat | undefined;
                        uDegree: d.FreeformDegree | undefined;
                        vDegree: d.FreeformDegree | undefined;
                        uStep: d.FreeformStep | undefined;
                        vStep: d.FreeformStep | undefined;
                        type: d.FreeformType | undefined;
                    };
                    freeforms: {
                        directive: d.Curve | d.Curve2d | d.Surface;
                        body: {
                            holes: d.FreeformBodyHole[];
                            params: d.FreeformBodyParam[];
                            scrvs: d.FreeformBodyScrv[];
                            sps: d.FreeformBodySp[];
                            trims: d.FreeformBodyTrim[];
                        }
                    }[]
                }[]
                freeformConnections: d.Connection[];
            };
        }
    }[];
}

The structure above is not fully expanded for simplicity. It may seem kind of overwhelming, but if you are only working with polygons, the structure you need to care about is as follows,

{
    vertexData: VertexData;
    materialLibraries: MaterialLibraries[];
    objects: {
        name: string | undefined;
        groups: {
            groupNames: string[] | undefined;
            mergingGroup: d.MergingGroup | undefined;
            smoothingGroup: d.SmoothingGroup | undefined;
            componentsChunks: {
                attributes: ComponentsChunkAttributes;
                polygons: (d.Polygon | d.Line | d.Face)[];
            };
        }[];
    }[];
}

Other Notes

  • The parser is not fully tested, so there may be some bugs.
  • The order of the vertex data is the same as they appear in the file, so when indexing them, you just use the index.
  • Notwithstanding being chunked, the order of curv2d and surf is the same as they appear in the file. If you need to index them, as you may need in con directive, you just iterate through the chunks.
  • The relative index is automatically converted to an absolute index.
  • The model used for testing is from this page and this page respectively, all distributed under personal use license.