Hi,
I have successfully obtained the vertex Array with :
Code:
osg::ref_ptr<osg::Vec3Array> m_aVertexList =
dynamic_cast<osg::Vec3Array*>(prGeometry->getVertexArray());
and indexes with a functor.
Now i would like to create a new drawable, with index of vertices, which are
outside a bouding box and modify the vertex Array.
Here is my actual code.
Code:
osg::ref_ptr<osg::PrimitiveSet>
ExtractedVisitor::reduceTriangle(osg::ref_ptr<osg::PrimitiveSet> prPrimitive)
{
//Search triangle indexes
osg::TriangleIndexFunctor<TriangleIndexVisitor> tif;
prPrimitive->accept(tif);
//Get pointer Data (m_aVertexList = vertex Array)
osg::Vec3f* vertexData = (osg::Vec3f*) m_aVertexList->getDataPointer();
//Initialize the new index Array
unsigned int iSize=0;
GLushort* pIndices=new GLushort[tif.m_aTriangleIndex.size()];
for(unsigned int i = 0 ; i < tif.m_aTriangleIndex.size() ; i+=3)
{
//Get each vertex of the triangle
osg::Vec3f vec1=m_aVertexList->at(tif.m_aTriangleIndex[i]);
osg::Vec3f vec2=m_aVertexList->at(tif.m_aTriangleIndex[i+1]);
osg::Vec3f vec3=m_aVertexList->at(tif.m_aTriangleIndex[i+2]);
//Test of BoundingBox for each vertex
if(m_prBoundingBox->contains(vec1) && m_prBoundingBox->contains(vec2)
&& m_prBoundingBox->contains(vec3))
{
//If the triangle is inside, add indexes
pIndices[iSize]=tif.m_aTriangleIndex[i];
pIndices[iSize+1]=tif.m_aTriangleIndex[i+1];
pIndices[iSize+2]=tif.m_aTriangleIndex[i+2];
iSize+=3;
}
else if(m_prBoundingBox->contains(vec1))
{
//Clipping of outside Vertex
OsgExtract extract(m_prBoundingBox);
std::vector<double>
aClippedVector1=extract.CohenSutherland3D(vec1,vec2);
std::vector<double>
aClippedVector2=extract.CohenSutherland3D(vec1,vec3);
//Get clipped Vertex
osg::Vec3f
clipVec2(aClippedVector1[3],aClippedVector1[4],aClippedVector1[5]);
osg::Vec3f
clipVec3(aClippedVector2[3],aClippedVector2[4],aClippedVector2[5]);
//Add index
pIndices[iSize]=tif.m_aTriangleIndex[i];
pIndices[iSize+1]=tif.m_aTriangleIndex[i+1];
pIndices[iSize+2]=tif.m_aTriangleIndex[i+2];
//Update the vertex (no problem)
vertexData[pIndices[iSize]].set(vec1.x(),vec1.y(),vec1.z());
//Update the outside vertex (here is the problem : change the index
Array)
vertexData[pIndices[iSize+1]].set(clipVec2.x(),clipVec2.y(),clipVec2.z());
vertexData[pIndices[iSize+2]].set(clipVec3.x(),clipVec3.y(),clipVec3.z());
iSize+=3;
}
}
//Create a new Primitive with indexes
osg::DrawElementsUShort* pReducedPrimitive=new
osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES, iSize, pIndices);
//Add to the geometry
return pReducedPrimitive;
}
My problem is with the first update of the vertex, i have no problem, but the
second and the third modify my index Array "pIndices" (before i added to the
new primitive).Indeed, it add or delete some indexes, but i don't know the
reason :( (there is no relation between the two Array "pIndices" and
"vertexData" :? ).
Is anyome see a problem with my code ?
Thank you for your help.
Sincerly,
Baptiste
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=29577#29577
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org