info-inventor-dev
[Top] [All Lists]

Face Set problems

To: info-inventor-dev@xxxxxxxxxxx
Subject: Face Set problems
From: Aubrey Holland <aubrey@xxxxxxxxxxx>
Date: Fri, 22 Sep 2000 16:37:39 -0400
Sender: owner-info-inventor-dev@xxxxxxxxxxx
Hello,

I'm trying to use the SoFaceSet node to tessellate polygons with a large
number of points.  I ran into a strange problem where it doesn't seem to
handle concave polygons very well.  The face set tessellates improperly
as the vertices are moved off of the screen and will disappear if
they're moved off in the right way.  Adding an ShapeHints node helps
with this problem but does not get rid of it entirely.  Using an
SoCoordinate3 instead of an SoVertexProperty solves the problem, but I
understand that this might be a good bit slower.  I have included a
piece of source code in this message that should demonstrate the
problem.

I'm also running into another problem where some of my face sets are
drawn in black (as if they were back-facing), even though the current
material is white.  This one may just be my fault, but I was wondering
if there are other known problems involving the SoFaceSet?  Is it
practical to try to use it to tessellate for faces with large numbers of
vertices?

Thanks,
Aubrey Holland

Here's a program that demonstrates my problem.  Using the middle mouse
button to move the parts of the face off of the screen will cause it to
show up:

#include <Inventor/Xt/SoXt.h>
#include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
#include <Inventor/nodes/SoFaceSet.h>
#include <Inventor/nodes/SoNormalBinding.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoShapeHints.h>
#include <Inventor/nodes/SoVertexProperty.h>

static float vertices[8][3] = 
{
    { 0.0, 0.0, 0.0}, { 1.0, 0.0, 0.0}, { 2.0, 0.5, 0.0},
    { 1.0, 1.0, 0.0}, { 0.5, 0.1, 0.0}, { 0.0, 1.0, 0.0},
    { -1.0, -2.0, 0.0}, { 0.0, -1.0, 0.0}
};

static int32_t numvertices = 8;

static float norms[3] = { 0.0, 0.0, 1.0 };

SoSeparator *
makeObeliskFaceSet()
{
   SoSeparator *obelisk = new SoSeparator();
   obelisk->ref();

   SoShapeHints *sh = new SoShapeHints();
   sh->vertexOrdering.setValue(SoShapeHints::COUNTERCLOCKWISE);
   sh->shapeType.setValue(SoShapeHints::UNKNOWN_SHAPE_TYPE);
   sh->faceType.setValue(SoShapeHints::UNKNOWN_FACE_TYPE);
   obelisk->addChild(sh);

   // Using the new SoVertexProperty node is more efficient
   SoVertexProperty *myVertexProperty = new SoVertexProperty;

   // Define the normals used:
   myVertexProperty->normal.setValues(0, 1, &norms);
   myVertexProperty->normalBinding = SoNormalBinding::PER_FACE;

   // Define material for obelisk
  
myVertexProperty->orderedRGBA.setValue(SbColor(.4,.4,.4).getPackedValue());

   // Define coordinates for vertices
   myVertexProperty->vertex.setValues(0, 8, vertices);

   // Define the FaceSet
   SoFaceSet *myFaceSet = new SoFaceSet;
   myFaceSet->numVertices.setValues(0, 1, &numvertices);
 
   myFaceSet->vertexProperty.setValue(myVertexProperty);
   obelisk->addChild(myFaceSet);

   obelisk->unrefNoDelete();
   return obelisk;
}

void
main(int, char **argv)
{
   // Initialize Inventor and Xt
   Widget myWindow = SoXt::init(argv[0]);
   if (myWindow == NULL) exit(1);

   SoSeparator *root = new SoSeparator;
   root->ref();

   root->addChild(makeObeliskFaceSet());

   SoXtExaminerViewer *myViewer = 
            new SoXtExaminerViewer(myWindow);
   myViewer->setSceneGraph(root);
   myViewer->setTitle("Face Set: Obelisk");
   myViewer->show();
   myViewer->viewAll();

   SoXt::show(myWindow);
   SoXt::mainLoop();
}

<Prev in Thread] Current Thread [Next in Thread>