[osg-users] Switch between primitive and model

Charlie Tan chen.qunhan at gmail.com
Sun Nov 11 18:26:10 PST 2018


Hi,

I am trying to toggle between a model that I have loaded (a unit cube) and a colored surface (a unit triangle). Thus, the triangle rendered should be half the area of the unit cube's face. In addition, the triangle rendered should lie on the cube face itself.

// Model
auto loadedModel = readRefNodeFiles(...);
auto swtch = new Switch();

scene->addChild(swtch);
swtch->addChild(loadedModel); //swtch[0]


// Colored surface
Node* geode;
auto polyGeom = Geometry();
polyGeom->setVertexArray(...);  //Set to (0,0,0), (1,0,0), (1,1,0)
polyGeom->setColorArray(...);
polyGeom->setNormalArray(...);
geode->addDrawable(polyGeom);

swtch->addChild(geode); //swtch[1]


However, when I toggle between:
swtch->setSingleChildOn(0);
and
swtch->setSingleChildOn(1);

The size, position and the orientation of the colored surface is way off as compared to my cube model.

Initially I thought it has something to do with my transformation matrix not being in the global frame, so I did this:

auto nodePath = scene->getChild(0)->asGroup()->getChild(0)->getParentalNodePaths()[0];
	auto matrix = osg::computeLocalToWorld(nodePath);
auto trans1 = MatrixTransform;
trans1->setMatrix(matrix);
trans1->addChild(geode);

swtch->addChild(trans1);

But it did not work too. Any help is much appreciated!


Thank you!

Cheers,
Charlie

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75185#75185







More information about the osg-users mailing list