@xeographics bio photo

@xeographics

Lindsay Kay
3D graphics programmer

Twitter Google+ LinkedIn Github

Importing .OBJ, .MD2 and .3DS into SceneJS


Contents

I’ve made three new plugins for SceneJS, to import mesh geometry from these file formats:

  • OBJ - a lightweight geometry definition file format first developed by Wavefront Technologies which contains mesh data — namely, the position of each vertex, the UV position of each texture coordinate vertex, normals, and the faces that make each polygon defined as a list of vertices, and texture vertices.

  • MD2 - a model format used by id Software’s id Tech 2 engine in games such as Quake II and Soldier of Fortune. This format is primarily used for animated player models and uses keyframes for mesh positions, which SceneJS interpolates within a vertex shader to create smooth animation.

  • 3DS - one of the file formats used by the Autodesk 3ds Max 3D modeling, animation and rendering software. This format has become a de facto industry standard for transferring models between 3D programs, or for storing models for 3D resource catalogs.

Run .OBJ demo Run .MD2 demo Run .3DS demo

Usage

The plugins provide new scene node types, and like all plugins, are automatically loaded into the engine as you need them.

As usual, we’ll start by pointing SceneJS at where you keep your plugins:

SceneJS.setConfigs({
     pluginPath:"./plugins"
});

..then importing an .OBJ is as easy as:

SceneJS.createScene({
    nodes:[
        {
            type: "translate", y:-30, z:-200,

            nodes:[
                {
                    type: "texture",
                    src: "foo/bar/raptor.jpg",

                    nodes:[

                        // Import Wavefront .OBJ mesh
                        {
                            type: "import/obj",
                            src: "foo/bar/raptor.obj"
                        }
                    ]
                }
            ]
        }
    ]
});

Importing meshes from the other formats is similar. To import .MD2, your node would be:

{
    type: "import/md2", src: "foo/bar/lion.md2"
}

And to import .3DS:

{
    type: "import/3ds", src: "foo/bar/lexus.3ds"
}

Shouts out to:

  • K3D.JS - SceneJS uses this library for parsing. It’s nice and fast because it loads the files into typed arrays, which it then parses.




comments powered by Disqus