DAE Scenegraph
Andor Salga | 2 November, 2008 | 14:58
We have code which parses collada/DAE files, but to a limited degree. The parser only extracts the geometry data. Therefore if a file is ‘simple’, it loads correctly since the scene graph has only one transform node. However if the collada file contains many transform nodes, each node with different geometry will be placed at the origin. This happens because we currently don’t have a scene graph which the transform nodes should be placed inside. I have started working on a scene graph and realized some of my earlier code must be reworked.
some general requirements:
var plane = new Collada();
plane.init(“models/plane.dae”);
var plane2 = new Collada();
plane2.init(“models/plane.dae”);
It is likely that collada files will structure geometry using the scene graph, however users will probably not care. If they have a plane and want it to give it a linear velocity, they should not have to deal with the scene graph, so the following should be valid:
plane2.setLinearVel(makeVector(0,0,1));
This will be interpreted as giving the root node of the scene graph the linear velocity, so all the objects attached to the plane will move. If the user wants to rotate the plane’s propeller, they will have to deal with the scene graph since the propeller’s transform node is a child of the plane’s transform node.
// collada objects will have a scenegraph
var planesg = plane.getSceneGraph();
// all node’s will have a findNode() which will return the
// first node which matches the string specified by the user.
var propeller = planesg.getRoot().findNode(“propeller”).
propeller.setAngularVel(makeVector(0,0,0.001));
The issue with this is that the user must know the name of the node, but if they are doing things like moving the nodes in the graph, they would have to know at least that much.
The main issue I have implementing the scene graph is using inheritance, not surprisingly . I wanted to place simple methods like get/SetName() into an ‘abstract’ BranchNode class and have TransformNode and GeometryNode inherit it. The angular velocity transformations seemed to work when there was only one TransformNode with one GeometryNode, but when I created two TransformNodes, I had a some sort of infinite recursion as the browser got really busy and nothing was rendered. The TransformNode was supposed to push its matrix on the matrix stack and then call the base class (BranchNode) render(), but then the BranchNode just called transformNode’s render(). Without inheritance everything seems okay, until I resolve this I will have to go on without it.
some general requirements:
- Collada files must only be parsed once. Once the file is parsed there’s no reason it should be parsed again. Parsing is already slower than having the js arrays already defined, so it should be kept to the absolute minimum. We will know which files are parsed based on the path users provide, such as “models/plane.dae” or “dragon.dae”. It will be up to the user to prevent scenarios such as loading “models/plane.dae” and then loading “plane.dae” where both files are duplicates. In this case our checks will fail and the file will be parsed and loaded twice in memory.
- Once a collada file is parsed, it will reside in a table as a scene graph uniquely identifiable by a pathname.
- Loading models from collada files must be at least as easy as loading from JS arrays.
var plane = new Collada();
plane.init(“models/plane.dae”);
var plane2 = new Collada();
plane2.init(“models/plane.dae”);
It is likely that collada files will structure geometry using the scene graph, however users will probably not care. If they have a plane and want it to give it a linear velocity, they should not have to deal with the scene graph, so the following should be valid:
plane2.setLinearVel(makeVector(0,0,1));
This will be interpreted as giving the root node of the scene graph the linear velocity, so all the objects attached to the plane will move. If the user wants to rotate the plane’s propeller, they will have to deal with the scene graph since the propeller’s transform node is a child of the plane’s transform node.
// collada objects will have a scenegraph
var planesg = plane.getSceneGraph();
// all node’s will have a findNode() which will return the
// first node which matches the string specified by the user.
var propeller = planesg.getRoot().findNode(“propeller”).
propeller.setAngularVel(makeVector(0,0,0.001));
The issue with this is that the user must know the name of the node, but if they are doing things like moving the nodes in the graph, they would have to know at least that much.
The main issue I have implementing the scene graph is using inheritance, not surprisingly . I wanted to place simple methods like get/SetName() into an ‘abstract’ BranchNode class and have TransformNode and GeometryNode inherit it. The angular velocity transformations seemed to work when there was only one TransformNode with one GeometryNode, but when I created two TransformNodes, I had a some sort of infinite recursion as the browser got really busy and nothing was rendered. The TransformNode was supposed to push its matrix on the matrix stack and then call the base class (BranchNode) render(), but then the BranchNode just called transformNode’s render(). Without inheritance everything seems okay, until I resolve this I will have to go on without it.
