[osg-users] osgUtil::PlaneIntersector and Invalid Pointer and Tesselation Error
Théo NASSOUR
osgforum at tevs.eu
Thu Jun 23 04:48:48 PDT 2016
Hi,
I am using plane intersection to get the intersection of all meshes in my scene with a plane. :
Code:
osg::ref_ptr<osgUtil::PlaneIntersector> intersector = new osgUtil::PlaneIntersector(mIntersectionPlane);
intersector->setRecordHeightsAsAttributes(true);
intersector->setPrecisionHint(osgUtil::PlaneIntersector::PrecisionHint::USE_DOUBLE_CALCULATIONS);
osgUtil::IntersectionVisitor mIntersectionVisitor; // Defined as a member usually
mIntersectionVisitor.reset();
mIntersectionVisitor.setTraversalMask(utils::MASK_SCENE_DATA);
mIntersectionVisitor.setIntersector(intersector.get());
view->getSceneData()->accept(mIntersectionVisitor);
osgUtil::PlaneIntersector::Intersections& intersections = intersector->getIntersections();
and in another function : i am computing the corresponding geode to the intersections:
Code:
inline osg::ref_ptr<osg::Geode> getSlice(const osgUtil::PlaneIntersector::Intersections & intersections)
{
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry;
osgUtil::Tessellator tessellator;
// set the normal in the same way color.
osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
// Compute Vertices
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
for (const auto& intersection : intersections)
{
for (const auto& vertex : intersection.polyline)
{
vertices->push_back(vertex);
normals->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));
}
vertices->push_back(*intersection.polyline.begin());
normals->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));
vertices->push_back(*intersections.begin()->polyline.begin());
normals->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));
}
geometry->setVertexArray(vertices);
geometry->setNormalArray(normals, osg::Array::BIND_OVERALL);
geometry->addPrimitiveSet(new osg::DrawArrays(GL_POLYGON, 0, vertices->size()));
tessellator.setWindingType(osgUtil::Tessellator::WindingType::TESS_WINDING_NONZERO);
tessellator.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY);
tessellator.retessellatePolygons(*geometry);
geode->addDrawable(geometry.get());
geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::ON);
return geode.get();
}
Now :
My first Problem is : Somtimes thee last element in the NodePath of Intersections in the intersection is an invalid pointer, I don't Know why.
My Secend Problem is : Somtimes when i have meshes with Holes, the Holes are not Computed, all the mesh is filled.
Thank you!
Cheers,
Théo
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=67752#67752
More information about the osg-users
mailing list