Hello,
In 3ds Max I have set up a very simple scene. I created a box,
sphere, and cone all offset from the origin, and then linked the
sphere and cone to the box to be children. I then exported into VRML
for loading into an opensg app.
In this application, I must be able to 'flatten' the scene graph
and break all dependencies, yet retain each objects position. I do
this with a depth-first tree-traversal and successively add all
objects to a new root (hence flattening the tree). It works great,
except for one issue...
It seems the sphere and cone are stored relative to the box and
when I break that link between the box and its children, the sphere
and cone both get moved back to the position where they were
originally created. I have attempted to store the matrix of the sphere
and cone before breaking the link, and then set their matrix to it
after the operation is complete, but they still remain at their
creation location, instead of where they should be (located near the
box).
Here is how I store and overwrite the matrix:
[code]
if (numChildren <= 0) // Do we have a leaf node?
{
// We only care about leaf nodes with Geometry Cores for now
if(nodeCore != osg::NullFC &&
nodeCore->getType().isDerivedFrom(osg::Geometry::getClassType()))
{
// save current world matrix of the object (the transform
node is located 2 levels up from the actual geometry faces)
osg::NodePtr parentPtr = node->getParent()->getParent();
osg::Node* parentNode = parentPtr.getCPtr();
osg::Matrix worldMatrix = parentNode->getToWorld();
// move parent node with transform core to new root and
overwrite its matrix
osg::beginEditCP(newRoot);
newRoot->addChild(parentPtr);
osg::TransformPtr parent_xform =
osg::TransformPtr::dcast(parentNode->getCore());
osg::beginEditCP(parent_xform);
parent_xform->setMatrix(worldMatrix); osg::endEditCP(parent_xform);
osg::endEditCP(newRoot);
}
}
[/code]
I would greatly appreciate any insight on this issue!
Thanks,
-Austin
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users