# Simple Convex Hull Creation?

I'm fairly new to scripting...just have been following a few tutorials.

I'm trying to work up to making a script which creates a convex hull mesh around complex shapes for use as collision volumes for game art. So I guess it would have to look at the overall silhouette of the mesh and create points at its largest and smallest areas.

Just trying to figure out how to get started.

On a much simpler note, I'd like to also have a siilar script which creates a simple box based off of an object's dimensions (I guess it would draw a box based off of an object's bounding box?)

## Comment viewing options

### box name: "bounding box"

box name: "bounding box" \
width: (geometry.max.x-geometry.min.x) \
length: (geometry.max.y-geometry.min.y)\
height: (geometry.max.z-geometry.min.z) \
pos: [geometry.center.x, geometry.center.y, \
(geometry.center.z- 0.5*(geometry.max.z-geometry.min.z))];

sphere name: "bounding sphere" \
pos: geometry.center \

\$'bounding box'.xray= true
\$'bounding sphere'.xray= true

--------------------------------------------------------------
This script generates 1 bounding box and 1 bounding sphere for all geometry in the scene. If you want them for a single mesh, replace geometry with \$'[name of your mesh]'. "xray" is optional, this just makes the bounding box and sphere see-through.

Thanks for your help seggaeman. This pretty much fulfills my simple box portion. I did simplify it for just the box and using the selected mesh. One thing that I would like to do is have the bounding mesh take on the name of the selected object with "_BV".

So if I have a teapot called teapot01 and hit the button I'd like for the teapot bounding mesh to be called "teapot01_BV"

Here was what I simplified it down to:

box name: "_BV"\
width: (\$.max.x-\$.min.x) \
length: (\$.max.y-\$.min.y)\
height: (\$.max.z-\$.min.z) \
pos: [\$.center.x, \$.center.y, \
(\$.center.z- 0.5*(\$.max.z-\$.min.z))];

\$'_BV'.xray= true

and I thought I could fuss with the box name to something like:

box name: (\$)+"_BV"\ and I also tried making a variable
x=\$.name

and doing
box name: (x)+"_BV"

and neither worked.

While I am on the topic of this code, I noticed I could select multiple objects and it would create 1 box. Would it be easy to select multiple objects and create multiple boxes centered to their axes?

Thanks again!

### check this scripts

you can check this (old and complicated) script:
http://www.scriptspot.com/3ds-max/scripts/bounding-boxer

http://www.scriptspot.com/3ds-max/scripts/translated-bounding-box

here is a snippet from his script:

```for i in selection do (
bb = nodeGetBoundingBox i i.transform
size = (bb[2]-bb[1])
in coordsys i (
b = box width:size[1] length:size[2] height:size[3]
CenterPivot b
b.transform = i.transform
b.pivot = i.pivot
b.pos = i.center
b.name = i.name + "_box"
)
)```

this code will create your b-boxes for all selected objects with "_box" suffix

### Awesome! This worked exactly

Awesome! This worked exactly as I needed for the simple box volume.

Much appreciated.

### I am actually adding just

I am actually adding just that to a script I am working on. However, the mathematics are FAR beyond my own skills. Luckily, there is a modifier called the PhysX Rigid Body Modifier provided by nVidia. It was included in the Max 2011 Action Pack (if you are on subscription). You can also get it at http://developer.nvidia.com/object/physx_dcc_plugins.html

Note that I was having all kindsof problems exporting any collision mesh it created into the SMD format for the Source Game Engine. But that doesn't mean you can't use it for your situation. If you are using it for Source and figure out a solution please share.

Also, I know that Michael Little is working on a Convex Hull creator in his next update to Convexity ( http://www.maple3d.com ). It might be available by the new year.

_______________________

Shawn Olson

Developer of Wall Worm

### Thanks for the information!

Thanks for the information! I'll have to check out the Action Pack and see how that works - I definitely would love to get soemthing like this in a script format though so I could avoid compatibility issues. If I come up with something I'll definitely give you any help I can! You're probably a lot further ahead than I am though...

Maybe some really smart coder will have some insight for us.