Jump to content

Computing normals using the HDK


Recommended Posts

Hello there

I posted this on the SESI forums already, I hope that's ok (I'm aware some people check both). :)

I am working on integrating an FRep Library into Houdini using the HDK. I can output the mesh just fine, but there is still some artefacts because of missing normals. When trying to set the normals to a mesh, it doesn't seem to make a difference. Here's my code:

    
    GEO_PrimPoly *prim_poly_ptr;
    GEO_Point* added_points[vertexCount];

    // Add new points to the gdp. This is optional - you can also
    // reuse existing points and add them to the polygon instead.
    for(unsigned int point_idx = 0; point_idx < vertexCount; point_idx++)
    {
        // Append a new point
        added_points[point_idx] = gdp->appendPoint();
        // Set its coordinates
        added_points[point_idx]->getPos().assign( polygonizer.getVertex(point_idx).x,
                                                  polygonizer.getVertex(point_idx).y,
                                                  polygonizer.getVertex(point_idx).z
                                                  );

        VECTOR<BASIC_TYPE> tmpNormal = polygonizer.getNormal(point_idx);
        UT_Vector3 nml(tmpNormal.X, tmpNormal.Y, tmpNormal.Z);
        gdp->computeNormal(*added_points[point_idx], nml );
    }

    // Create a primitive for every face and append
    for (unsigned int i = 0; i < faceCount; i++)
    {
       // Append a new polygon primitive. Primitive types are defined in GEO_PrimType.h
       prim_poly_ptr = dynamic_cast<GEO_PrimPoly *>(gdp->appendPrimitive(GEOPRIMPOLY));
       prim_poly_ptr->setSize(0);

       // Append vertices that form this primitive
       prim_poly_ptr->appendVertex(added_points[polygonizer.getFace(i*3)]);
       prim_poly_ptr->appendVertex(added_points[polygonizer.getFace(i*3+1)]);
       prim_poly_ptr->appendVertex(added_points[polygonizer.getFace(i*3+2)]);

       // Close the primitive to make it a polygon instead of a polyline.
       prim_poly_ptr->close();
    }
    // ----------------------------------------

Do I have to tell Houdini somehow that I am providing vertex normals? Or invoking calculation of face normals?

Help is greatly appreciated :)

Andy

post-6710-131169791675_thumb.jpg

Link to comment
Share on other sites

computeNormal() will calculate an average normal from the adjacent polygons, it does _not_ set the normal. Normals are just vector attributes in the HDK and you manipulate them as such. So you do something like addNormalAttribute(GEO_POINT_DICT) and then set your normals using the returned attribute ref. See: http://www.sidefx.co...attributes.html

// untested
GB_AttributeRef normal_attrib = gdp->addNormalAttribute(GEO_POINT_DICT);
for (int i = 0; i < vertexCount; i++)
{
 VECTOR<BASIC_TYPE> tmpN = polygonizer.getNormal(i);
 added_points[i]->setValue<UT_Vector3>(normal_attrib, UT_Vector3(tmpN.X, tmpN.Y, tmpN.Z));
}

Link to comment
Share on other sites

computeNormal() will calculate an average normal from the adjacent polygons, it does _not_ set the normal. Normals are just vector attributes in the HDK and you manipulate them as such. So you do something like addNormalAttribute(GEO_POINT_DICT) and then set your normals using the returned attribute ref. See: http://www.sidefx.co...attributes.html

// untested
GB_AttributeRef normal_attrib = gdp->addNormalAttribute(GEO_POINT_DICT);
for (int i = 0; i < vertexCount; i++)
{
 VECTOR<BASIC_TYPE> tmpN = polygonizer.getNormal(i);
 added_points[i]->setValue<UT_Vector3>(normal_attrib, UT_Vector3(tmpN.X, tmpN.Y, tmpN.Z));
}

Great, edward. That did the trick :) Thank you!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...