aaweb Posted July 26, 2011 Share Posted July 26, 2011 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 Quote Link to comment Share on other sites More sharing options...
edward Posted July 27, 2011 Share Posted July 27, 2011 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)); } Quote Link to comment Share on other sites More sharing options...
aaweb Posted July 28, 2011 Author Share Posted July 28, 2011 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.