Jump to content

how to get radius of sphere primitive


Recommended Posts

i want to get sphere primitive radius and center 

i use 

 

//primitive type par
GEO_Primitive       *prim;
GA_FOR_ALL_PRIMITIVES(gdp, prim)
{
   UT_BoundingBox   *sphere_bbox;
 
   GEO_PrimSphere *ss=(GEO_PrimSphere*)prim->castTo();
 
    ss->getBBox(sphere_bbox);
 
}

 

To compile successfully,but when i run it in houdini ,is error and exit houdini

i do not konw where is mistake?

 

Link to comment
Share on other sites

There are two possible reasons why your code might crash. First is that your code doesn't allocate memory for sphere_bbox variable, and the second is that no checking is done to determine if the prim is actually an instance of GEO_PrimSphere class. And, by the way, calling the castTo() function does not work here. Can't tell exactly why, but it gives strange values. Maybe the call to this function destroys the information about the sphere itself, leaving only the basic data that belongs to GU_Primitive class? Would be interesting if someone more experienced explained this behavour.

 

So, the following code should work fine:

GEO_Primitive *prim;

GA_FOR_ALL_PRIMITIVES(gdp, prim)
{
    if (prim->getTypeId().get() != GA_PRIMSPHERE)
       continue;

    UT_BoundingBox *bb = new UT_BoundingBox();

    GEO_PrimSphere *ss=(GEO_PrimSphere*)prim;

    ss->getBBox(bb);
}
Edited by Dmitry Shurov
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...