I would like to ask how to set a normal vector when specifying control points in a curve. The purpose for this is to evaluate Frenet frame, evaluateFrenetFrame() at any point on the curve (e.g. to get position and normal vectors) - after the curve is constructed.
I have tried the example below for the NURBS Curve - evaluated normal is always a null vector:
// normal attribute - is this correct?
GA_AttributeOwner ao = GA_ATTRIB_POINT;
GA_RWAttributeRef normal_attrib = gdp->addNormalAttribute(ao, GA_STORE_REAL32);
// create a curve
GU_PrimNURBCurve *curve = GU_PrimNURBCurve::build(gdp, num_points, degree);
// set knot values values
for (int point_idx = 0; point_idx < num_points; point_idx++)
{
// compute position vector etc. …
point_offset = curve->getPointOffset(point_idx);
gdp->setPos4(point_offset, position_vec4);
if (normal_attrib)
{
GEO_Point *p = gdp->getGEOPoint(point_offset);
//p->setPos(position_vec4);
const UT_Vector4 normal(0, 1, 0, 1);
// either of the three methods should work, right?
// 1
p->set(normal_attrib, normal.data(), 4);
// 2
//p->setValue(normal_attrib, normal);
// 3
//p->setValue(normal_attrib, 0.0f, 0);
//p->setValue(normal_attrib, 1.0f, 1);
//p->setValue(normal_attrib, 0.0f, 2);
//p->setValue(normal_attrib, 1.0f, 3);
}
}
Setting normals in a curve; Frenet Frame
2885 4 1-
- Mike Vasiljevs
- Member
- 9 posts
- Joined: Dec. 2013
- Offline
-
- edward
- Member
- 8083 posts
- Joined: July 2005
- Offline
Normals are vector3's. For positions, use of vector4 is also kind of moot unless you actually want weighted NURBS knots which your example does not make use of. ie. Use UT_Vector3 and call setPos3() instead of setPos4(). There are internal optimizations that make setPos3() faster than setPos4().
GA_RWHandleV3 normal_attrib(gdp->addNormalAttribute(GA_ATTRIB_POINT, GA_STORE_REAL32));
if (normal_attrib.isInvalid())
return; // failed to create a *new* normal attribute.
// create a curve
GU_PrimNURBCurve *curve = GU_PrimNURBCurve::build(gdp, num_points, degree);
// set knot values values
for (int point_idx = 0; point_idx < num_points; point_idx++)
{
// compute position vector etc. …
point_offset = curve->getPointOffset(point_idx);
gdp->setPos3(point_offset, position_vec3);
const UT_Vector3 normal(0, 1, 0);
normal_attrib->set(point_offset, normal);
}
GA_RWHandleV3 normal_attrib(gdp->addNormalAttribute(GA_ATTRIB_POINT, GA_STORE_REAL32));
if (normal_attrib.isInvalid())
return; // failed to create a *new* normal attribute.
// create a curve
GU_PrimNURBCurve *curve = GU_PrimNURBCurve::build(gdp, num_points, degree);
// set knot values values
for (int point_idx = 0; point_idx < num_points; point_idx++)
{
// compute position vector etc. …
point_offset = curve->getPointOffset(point_idx);
gdp->setPos3(point_offset, position_vec3);
const UT_Vector3 normal(0, 1, 0);
normal_attrib->set(point_offset, normal);
}
-
- Mike Vasiljevs
- Member
- 9 posts
- Joined: Dec. 2013
- Offline
Thank you for the reply.
I believe you have meant to get the GA_RWHandleV3 variable first, as set() absent from GA_Attribute class - also discussed in another thread http://www.sidefx.com/index.php?option=com_forum&Itemid=172&page=viewtopic&t=22762 [sidefx.com]
However that does not seem to affect evaluate functions much either!
I believe you have meant to get the GA_RWHandleV3 variable first, as set() absent from GA_Attribute class - also discussed in another thread http://www.sidefx.com/index.php?option=com_forum&Itemid=172&page=viewtopic&t=22762 [sidefx.com]
However that does not seem to affect evaluate functions much either!
-
- edward
- Member
- 8083 posts
- Joined: July 2005
- Offline
-
- Mike Vasiljevs
- Member
- 9 posts
- Joined: Dec. 2013
- Offline
-
- Quick Links

