Pages

Friday, June 26, 2009

Bounding Sphere

All we know about Bounding Box in 3ds Max, but what about Bounding Sphere? Yep, there no mapped function for that purpose and the problem is interesting and discussed by game developers in GameDev, also by scripters in ScriptSpot. And as you guess, ScriptSpot's thread interested me. I know so always there exist "shortcut", so now after being free from my duty, I sat down to think for a short, clean and optimized code. You can see my short simple version out there or right here:

obj = selection[1] -- select EPoly or add EPoly_mod
allVerts = for i in 1 to obj.numVerts collect polyop.getVert obj i
vDist = for i in allVerts collect distance i obj.center
sort vDist
-- Optional step:
-- if obj is not EPoly and you wish to restore it then remove EPloly_mod

bs_radius = vDist[vDist.count] -- BSphere Radius
bs_pos = obj.center -- BSphere Center

That's all. Now you can test it on some object and also may try make a sphere in the view port:

s = sphere pos:bs_pos radius:bs_radius xray:on

No comments:

Post a Comment

Thanks for your comment