Wednesday 12 June 2013

Custom Node Types in SceneJS 3.0

This week I added support for custom node types to SceneJS 3.0. These provide an extension mechanism which allows you to create your own higher-level scene components that just slot straight into the scene graph as regular nodes that you can instantiate, update and query via the JSON API, just like any other node type.

Essentially, a custom node type works as a kind of facade which creates a sub-tree of nodes under itself, while providing setters and getters, callable via the JSON API, that can update and query the states of those nodes.

You provide each of your custom node definitions as a plugin script within a special subdirectory of your plugins directory. Then, when you create a scene node of a custom node type, SceneJS will dynamically load that plugin script on-demand. The script will define the node type, and then SceneJS will instantiate the type to create the node.

Documentation:
https://github.com/xeolabs/scenejs#custom-node-types

Trivial first demo:
http://scenejs.org/examples.html?page=basicCustomNodeDef

The Tron Tank is now a plugin too:
http://scenejs.org/examples.html?page=customNodesTank

A scene made entirely from custom nodes:
http://scenejs.org/examples.html?page=customNodesSkyGridAndTeapot

All custom node demos so far:
http://scenejs.org/examples.html?tags=customNodes

The repository has this collection of custom node types, which SceneJS hotloads from by default:
https://github.com/xeolabs/scenejs/tree/V3.0/api/latest/plugins/node

There are many possibilities for custom node types. They allow us to create abstract, domain-specific objects within our scenes, such as for physics, object hierarchies etc.  Since they can create further custom sub-nodes, they can also be used to create behaviour/control hierarchies within scenes.

More examples of these coming soon!