It was very easy to integrate Polyvox to OpenSceneGraph As you said, just a matter of copy of vertices and indices! here part of the code:
Code:
//Convienient access to the vertices and indices
const vector<uint32_t>& vecIndices = mesh.getIndices();
const vector<PositionMaterialNormal>& vecVertices = mesh.getVertices();
osg::ref_ptr<osg::DrawElementsUInt> indices = new osg::DrawElementsUInt(GL_TRIANGLES, mesh.getNoOfIndices());
for(int i = 0; i < mesh.getNoOfIndices(); i++){
PositionMaterialNormal vert0 = vecVertices[i];
(*indices)[i] = vecIndices[i];
}
// The vertex array shared by both the polygon and the border
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array(mesh.getNoOfVertices());
for(int i = 0; i < mesh.getNoOfVertices(); i++){
PositionMaterialNormal vert0 = vecVertices[i];
(*vertices)[i].set(vert0.getPosition().getX(),vert0.getPosition().getY(),vert0.getPosition().getZ());
}
// The normal array
osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array(mesh.getNoOfVertices());
for(int i = 0; i < mesh.getNoOfVertices(); i++){
PositionMaterialNormal vert0 = vecVertices[i];
(*normals)[0].set(vert0.getPosition().getX(),vert0.getPosition().getY(),vert0.getPosition().getZ());
}
// create white material
Material *material = new Material();
material->setDiffuse(Material::FRONT, Vec4(1.0, 1.0, 1.0, 1.0));
material->setSpecular(Material::FRONT, Vec4(0.0, 0.0, 0.0, 1.0));
material->setAmbient(Material::FRONT, Vec4(0.1, 0.1, 0.1, 1.0));
material->setEmission(Material::FRONT, Vec4(0.0, 0.0, 0.0, 1.0));
material->setShininess(Material::FRONT, 25.0);
// Construct the polygon geometry
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
geom->setDataVariance( osg::Object::DYNAMIC );
geom->setUseDisplayList( false );
geom->setUseVertexBufferObjects( true );
geom->setVertexArray( vertices.get() );
geom->setColorBinding( osg::Geometry::BIND_OVERALL );
geom->addPrimitiveSet( indices.get() );
geom->getOrCreateStateSet()->setAttribute(material);
// Add them to the scene graph
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->addDrawable( geom.get() );
i have also create a Cmake project , but it must be optimized. maybe i will open another topic for this.
Also consider that OSG has a lot of features even for optimize the geometry:
http://www.openscenegraph.org/documenta ... 01494.htmlbut i have to further explore in depth this field.