Arthur~Chiu Posted June 22, 2014 Share Posted June 22, 2014 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? Quote Link to comment Share on other sites More sharing options...
Storm Keeper Posted June 22, 2014 Share Posted June 22, 2014 (edited) 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 June 22, 2014 by Dmitry Shurov Quote Link to comment Share on other sites More sharing options...
Arthur~Chiu Posted June 23, 2014 Author Share Posted June 23, 2014 thanks 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.