[Solved] Create a DzFacetMesh for a node?

shoei321shoei321 Posts: 103

What is the correct way to programatically create a DzFacetMesh and set it as the geometry for a DzNode?

I am doing this : 

// Create a material
DzMaterial *m = new DzDefaultMaterial();
m->setName("Material");
m->setDiffuseColor(QColor(128, 128, 128, 255));

// Create Shape and Mesh
DzFacetShape* shape = new DzFacetShape();
DzFacetMesh* mesh = new DzFacetMesh();
shape->setFacetMesh(mesh);
shape->addMaterial(m);

mesh->beginEdit();

// Create a UVSet with four coords for entire texture
DzUVSet* uvSet = new DzUVSet();
uvSet->setMapType(DzMap::FLOAT2_MAP);
uvSet->appendPnt2Vec(DzVec3(0, 0, 0));
uvSet->appendPnt2Vec(DzVec3(1, 0, 0));
uvSet->appendPnt2Vec(DzVec3(1, 1, 0));
uvSet->appendPnt2Vec(DzVec3(0, 1, 0));
mesh->setUVList(uvSet);
mesh->activateMaterial(0);

// Create a single quad
int vertIds[4];
vertIds[0] = mesh->addVertex(DzVec3(0, 0, 0));
vertIds[1] = mesh->addVertex(DzVec3(1, 0, 0));
vertIds[2] = mesh->addVertex(DzVec3(1, 1, 0));
vertIds[3] = mesh->addVertex(DzVec3(0, 1, 0));

int uvIds[4] = { 0, 1, 2, 3 };
mesh->addFace(vertIds, uvIds)
mesh->finishEdit();

DzObject* object = new DzObject();
object->addShape(shape);
node->setObject(object);

 

I find that the geometry isn't visible in the normal viewport, but I can select it's faces in the Geometry Editor tool.   And if I switch the Geometry Editor tool to Edge selection mode, DAZ Studio crashes.

Can someone post an example of the correct way to programatically create and add a DzFacetMesh/Shape to a DzNode?

 

Thanks

 

 

Post edited by shoei321 on

Comments

  • shoei321shoei321 Posts: 103
    edited July 2017

    Thanks Chris, that example is essentially what I was already doing.    I've now replicated it in C++ line for line but still no dice.

    I'm very confused by this because my geometry is definitely getting created - I can interact with it in the Geometry Editor and the Surfaces tool, and the bounding box grows to encompass the shape as well.   When I select the surface in the Surfaces tool the yellow border outline around the faces is drawn, and similarly I can select the faces/verts in the Geometry Editor.   It just doesn't get drawn on its own in the viewport otherwise though, in any drawstyle.    Wireframe drawstyles don't even show the mesh edges.     I've attached a screenshot of a DzNode with a single facet, shown selected in the Geometry Editor tool.   

    Interestingly, when I render the scene using IRAY or 3Delight the geometry shows up just fine, with correct material and texture maps.    Neither Basic nor Intermediate OpenGL renderers work however, so the problem appears to be specific to OpenGL.  

    Post-creation I've verified vertices, uvs, facets, normals, and everything looks legit.    Any ideas what's going wrong here?

     

    Thanks

     

     

    Screen Shot 2017-07-03 at 6.06.55 PM.png
    2688 x 1532 - 230K
    Post edited by shoei321 on
  • shoei321shoei321 Posts: 103

    Finally figured this out -- I had overridden DzNode::draw() to draw a custom representation of my node in the viewport, and forgot to make a call to the superclass method.   The superclass method is of course what actually draws the geometry.    Doh!

     

     

     

Sign In or Register to comment.