[osg-users] Smooth shading
Hello, I'm working on a project in which we need to output 3D objects constructed by the code. We generate vertices and then triangles. When the normal binding is per_primitive, every thing works fine. When it is per_vertex, either the osgProducer::Viewer crashes or the result is incorrect (badly shaded triangles). Here is the code: if(geo->getNormalBinding() == osg::Geometry::BIND_PER_PRIMITIVE) { for(unsigned int i=0; iat(A) - vertices->at(B); osg::Vec3f CB = vertices->at(B) - vertices->at(C); osg::Vec3f N = BA ^ CB; N.normalize(); normals->push_back(N); } } else if(geo->getNormalBinding() == osg::Geometry::BIND_PER_VERTEX) { for(unsigned int i=0; igetNumElements(); i++) normals->push_back(osg::Vec3f(0.0, 0.0, 0.0)); for(unsigned int i=0; iat(A) - vertices->at(B); osg::Vec3f CB = vertices->at(B) - vertices->at(C); osg::Vec3f N = BA ^ CB; (*normals)[A] += N; (*normals)[B] += N; (*normals)[C] += N; } for(unsigned int i=0; igetNumElements(); i++) normals->at(i).normalize(); } thanks ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Analyzing the Topology of osg::Geometry
Hello, Is there a way to tell which vertices (of the vertex array) in an osg::Geometry instance belong to a given face i, regardless of the PrimitiveSet type? The query is: Given face Id (i), and vertex index (j=0,1,2 if the face is a triangle) in this face, What is the index of this vertex in the VertexArray of the osg::Geometry? Thanks ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org