Hi Sebastian, Unless you explicitly ask the osg to clone your model's geometry it will share the geometry by default. It simply stores a pointer to the loaded model's vertices etc. So the below code should work for you. You can also set osgDB to cache the model in memory so that if you ever call osgDB::load() with the same path and filename it will just return a pointer to the cached model rather than reloading it. osg::Group* rootNode = new osg::Group;
osg::Node* loadedModel = osgDB::load(....); osg::PositudeAttitudeTransfrom* instance_1 = new osg::PositudeAttitudeTransfrom instance_1->setPosition( 10.f, 0.0, 0.0); instance_1->addChild(loadedModel); osg::PositudeAttitudeTransfrom* instance_2 = new osg::PositudeAttitudeTransfrom instance_2->setPosition( 20.f, 0.0, 0.0); instance_2->addChild(loadedModel); osg::PositudeAttitudeTransfrom* instance_3 = new osg::PositudeAttitudeTransfrom instance_3->setPosition( 30.f, 0.0, 0.0); instance_3->addChild(loadedModel); //now attach the instances to the graph rootNode->addChild(instance_1); rootNode->addChild(instance_2); rootNode->addChild(instance_3); viewer.setSceneData(rootNode); Regards, Kim. ________________________________ From: [email protected] on behalf of Sebastian Messerschmidt Sent: Sat 23/05/2009 14:42 To: OpenSceneGraph Users Subject: [osg-users] Referencing loaded models Hi, This might be a total beginners question, but I didn't find any sufficient information in the forum nor in the documentation. Let's assume I have a scene composed of some models, let's say a trees/houses which are the same model. If I want to load the model once and use it multiple times (with different transform/state) what is the best way to handle this. The naive way would be to load the model for each instance and add it to the scene graph. But there must be some way to share the node. What I had in mind is to load the model exactly once and sort of "clone" it in a way that the geometry/textures are still shared and only referenced multiple times. As I understand DRAW_INSTANCED, it performs something like this on GPU side. But what I want is more like a logical structure. I'm sort of lost. If I naively take a loaded model and just add it to the scene-graph with different transform nodes as parent it is still displayed only once :-( something like: osg::Node* loadedModel = osgDB::load(....); osg::Node* rootNode = new osg::Group; // create some transforms for different instances osg::Transform* instance_1 = new osg::PositudeAttitudeTransfrom ... set some position to instance_1 osg::Transform* instance_2 = new osg::PositudeAttitudeTransfrom ... set some position to instance_2 osg::Transform* instance_3 = new osg::PositudeAttitudeTransfrom ... set some position to instance_3 //now attach the instances to the graph rootNode.addChild(instance_1); rootNode.addChild(instance_2); rootNode.addChild(instance_3); Shouldn't that work? cheers Sebastian _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
<<winmail.dat>>
***************************************************************************************** To view the terms under which this email is distributed, please go to http://www.hull.ac.uk/legal/email_disclaimer.html *****************************************************************************************
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

