Hi,
I have the following code:
Code:
osg::ref_ptr<Geode> geode=qe2osg(qe);
objWriteCell(qe, "temp.obj");
grp->addChild(osgDB::readNodeFile("temp.obj"));
grp->addChild(geode);
and it produces the attached result. The yellow object is geode (code below
assigns yellow color), while the node is gray (no color gets saved to .obj
file). The point is that these two objects are not in the same position! Can
anyone explain that? The QuadEdge to OSG conversion function is given below, as
well as objWriteCell, if you think it matters.
Code:
osg::ref_ptr<Geode> qe2osg(Cell *qe)
//converts quadedge structure into osg geode
{
osg::ref_ptr<Geode> geode = new osg::Geode();
osg::ref_ptr<Geometry> geom = new osg::Geometry();
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
osg::ref_ptr<osg::Vec3Array> osgtr = new osg::Vec3Array;
osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
CellFaceIterator cellFaces(qe);
Face *f;
while ((f = cellFaces.next()) != 0)
{
osg::Vec4 color;
osg::Vec3 p1, p2, p3;
osg::Vec3 normal;
Edge *e=f->getEdge();
Vertex *v=e->Org(); //origin of this edge
p1=v->pos;
osgtr->push_back(p1);
normals->push_back(v->normal);
e=e->Lnext();
v=e->Org();
p2=v->pos;
osgtr->push_back(p2);
normals->push_back(v->normal);
e=e->Lnext();
v=e->Org();
p3=v->pos;
osgtr->push_back(p3);
normals->push_back(v->normal);
}
geom->setVertexArray(osgtr);
geom->setNormalArray(normals);
geom->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,0.5f));
geom->setColorArray(colors);
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
geom->addPrimitiveSet(new
osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,0,osgtr->size()));
geode->addDrawable(geom);
return geode.get();
}
Code:
static void objWriteCell(Cell *cell, ostream &s, const char *streamname)
{
s << "# " << cell->countVertices() << " vertices\n";
{
CellVertexIterator vertices(cell);
Vertex *vertex;
while ((vertex = vertices.next())!=0)
s << "v " << vertex->pos[0] << " "
<< vertex->pos[1] << " "
<< vertex->pos[2] << "\n";
}
// write faces in any order
s << "# " << cell->countFaces() << " faces\n";
{
CellFaceIterator faces(cell);
Face *face;
while ((face = faces.next())!=0)
{
s << "f";
FaceEdgeIterator edges(face);
Edge *edge;
while ((edge = edges.next())!=0)
s << " " << edge->Org()->getID();
s <<endl;
}
}
}
Maybe I am not seeing something obvious here, or it is some intricacy or even
bug of OSG. Any comment is appreciated.
Thank you!
Cheers,
Dženan[/code]
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=28113#28113
Attachments:
http://forum.openscenegraph.org//files/load_file_routine_proglems_582.png
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org