<div dir="ltr">Hello,<div><br></div><div>I want to display my own BoundingBoxes (BBs) using osg. The way I am trying to do it is the following:</div><div>1) create a Geode and set it as Child of the overall scene. Create a global pointer to be able to add children to this Geode.</div><div>2) for every BoundingBox I find, create a new Geometry with a LINE_LOOP PrimitiveSet and add the draw-able as Child to the geode</div><div>3) after every iteration, multiple BBs could be generated and need to be deleted, because the objects in the BBs or the camera may have moved</div><div><br></div><div>I managed to show one BB in my scene by directly creating the Geode and the Box as child, but I cant get it working, using the above described method. I think that the Problem is with rerendering the previously created Geode, but I may be wrong. The other think, that may prevent stuff from rendering, is that I delete the BBs in the next "iteration".</div><div><br></div><div>Scene creation and Vertex positions are "correct", I've used the same code in my working example where I created Geode and DrawArray at once.</div><div><br></div><div>Here is a part of my Code, ill try to add some explanation:</div><div><br></div><div><div class="prettyprint" style="background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; overflow-wrap: break-word;"><code class="prettyprint"><div class="subprettyprint"><font color="#000088"><div class="subprettyprint">Visual.h<br>...<br><div class="subprettyprint">/** Create scene object for all the Bounding Boxes to be drawn into **/</div><div class="subprettyprint">osg::ref_ptr<osg::Geode> myGeode;</div><div>...</div><br>--------------------------------------------------<br>Visual.cpp<br><br>// called on plug-in load<br>void Visual::load()<br>{<br> ...<br> createBoundingBoxScene();<br>}<br><br>// called with 60fps<br>void Visual::update()<br>{<br><span style="white-space: pre;"> </span>// remove old BBs and create new one<br><div class="subprettyprint"><span style="white-space:pre"> </span>myGeode->removeDrawables(0, myGeode->getNumDrawables());</div> <span style="font-family: Arial, Helvetica, sans-serif; white-space: pre;"> </span><span style="font-family: Arial, Helvetica, sans-serif;">createBoundingBox();</span></div><div>}<br><br>/*</div><div class="subprettyprint">* \brief Visual create BoundingBox as Child to Geode</div><div class="subprettyprint">* creates a BoundingBox via DrawArray and lines over (later given) vertices, and adds them as child to the global Geode</div><div class="subprettyprint">*/</div><div class="subprettyprint">void Visual::createBoundingBox()</div><div class="subprettyprint">{</div><div class="subprettyprint"><span style="white-space:pre"> </span>osg::Geometry* geo = new osg::Geometry;</div><div class="subprettyprint"><span style="white-space:pre"> </span>osg::ref_ptr<osg::Vec3dArray> myBBPoints = new osg::Vec3dArray; // array of BB cordinates</div><div class="subprettyprint"><span style="white-space:pre"> </span>osg::ref_ptr<osg::Vec4dArray> color = new osg::Vec4dArray;</div><div class="subprettyprint"><span style="white-space:pre"> </span>color->push_back(osg::Vec4d(1.0, 0.0, 0.0, 1.0)); // create color: red</div><div class="subprettyprint"><span style="white-space:pre"> </span>osg::DrawArrays* da = new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP, 0, myBBPoints->size()); // LINE_LOOP, because BBs are a loop for sure</div><div class="subprettyprint"><br></div><div class="subprettyprint"><span style="white-space:pre"> </span>myBBPoints->push_back(osg::Vec3d(754.0, 3860.0, 11.0)); // 4 corner vertices, TODO: if working, pass Global Points as parameters in function</div><div class="subprettyprint"><span style="white-space:pre"> </span>myBBPoints->push_back(osg::Vec3d(760.0, 3860.0, 11.0));</div><div class="subprettyprint"><span style="white-space:pre"> </span>myBBPoints->push_back(osg::Vec3d(760.0, 3860.0, 13.0));</div><div class="subprettyprint"><span style="white-space:pre"> </span>myBBPoints->push_back(osg::Vec3d(754.0, 3860.0, 13.0));</div><div class="subprettyprint"><br></div><div class="subprettyprint"><span style="white-space:pre"> </span>geo->setVertexArray(myBBPoints);</div><div class="subprettyprint"><span style="white-space:pre"> </span>geo->addPrimitiveSet(da);</div><div class="subprettyprint"><span style="white-space:pre"> </span>geo->setColorArray(color);</div><div class="subprettyprint"><span style="white-space:pre"> </span>geo->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE);</div><div class="subprettyprint"><span style="white-space:pre"> </span>geo->setDataVariance(osg::Object::DYNAMIC);</div><div class="subprettyprint"><br> // add geometry to geode to be drawn</div><div class="subprettyprint"><span style="white-space:pre"> </span>myGeode->addDrawable(geo);</div><div class="subprettyprint"><br> // force scene / Geode to be redrawn ? all necessary, all useless?</div><div class="subprettyprint"><span style="white-space:pre"> </span>geo->dirtyDisplayList();</div><div class="subprettyprint"><span style="white-space:pre"> </span>geo->dirtyBound();</div><div class="subprettyprint"><span style="white-space:pre"> </span>da->dirty();</div><div class="subprettyprint"><span style="white-space:pre"> </span>myGeode->dirtyBound();</div><div class="subprettyprint">}</div><div class="subprettyprint"><br></div><div class="subprettyprint">/*</div><div class="subprettyprint">* \brief Visual create global Geode as child to scene</div><div class="subprettyprint">* get 3D scene of environment, create a (global) geode and add it as child to scene.</div><div class="subprettyprint">*/</div><div class="subprettyprint"><br></div><div class="subprettyprint">void Visual::createBoundingBoxScene()</div><div class="subprettyprint">{</div><div class="subprettyprint"><span style="white-space:pre"> </span>osg::Group * scene = findScene3D(dynamic_cast<osg::Group*>(myGraphicalContext->getScene())); //works</div><div class="subprettyprint"><span style="white-space:pre"> </span>if (scene)</div><div class="subprettyprint"><span style="white-space:pre"> </span>{</div><div class="subprettyprint"><span style="white-space:pre"> </span>myGeode = new osg::Geode;</div><div class="subprettyprint"><span style="white-space:pre"> </span>myGeode->setDataVariance(osg::Object::DYNAMIC);</div><div class="subprettyprint"><span style="white-space:pre"> </span>myGeode->setName("Geode");</div><div class="subprettyprint"><span style="white-space:pre"> </span>osg::MatrixTransform* mat = new osg::MatrixTransform;</div><div class="subprettyprint"><span style="white-space:pre"> </span>mat->setReferenceFrame(osg::Transform::ABSOLUTE_RF); // (?) use global coordinate system, not local</div><div class="subprettyprint"><span style="white-space:pre"> </span>osg::StateSet *stateset = myGeode->getOrCreateStateSet();</div><div class="subprettyprint"><br></div><div class="subprettyprint"><span style="white-space:pre"> </span>stateset->setMode(GL_LIGHTING, osg::StateAttribute::ON);</div><div class="subprettyprint"> <span style="font-family: Arial, Helvetica, sans-serif; white-space: pre;"> </span><span style="font-family: Arial, Helvetica, sans-serif;">stateset->setRenderBinDetails(INT_MAX, "RenderBin"); // make sure to print at last possible time</span><br></div><div class="subprettyprint"><br> // add global Geode as child to scene</div><div class="subprettyprint"><span style="white-space:pre"> </span>scene->addChild(mat);</div><div class="subprettyprint"><span style="white-space:pre"> </span>mat->addChild(myGeode);</div><div class="subprettyprint"><br></div><div class="subprettyprint"><span style="white-space:pre"> </span>std::cout << "Scene created successfully, name: " << scene->getName() << " with " << scene->getNumChildren() << " children." << std::endl;</div><div class="subprettyprint"><span style="white-space:pre"> </span>}</div><div class="subprettyprint"><span style="white-space:pre"> </span>else mySimulationContext->printErrorMessage("Failed to get scene node.");</div><div class="subprettyprint">}</div></font></div></code></div><div><br></div></div><div>I hope the code is not too long, but because I'm new to osg, I dont know what is important and what not.</div><div><br></div><div>Have a nice Day and thanks for your responses</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:osg-users+unsubscribe@googlegroups.com">osg-users+unsubscribe@googlegroups.com</a>.<br />
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/osg-users/b2866ce9-f4c2-4395-bf2a-06db06d84ed5%40googlegroups.com?utm_medium=email&utm_source=footer">https://groups.google.com/d/msgid/osg-users/b2866ce9-f4c2-4395-bf2a-06db06d84ed5%40googlegroups.com</a>.<br />