View Full Version : Center Vertex of Unexploded Object (Voxel Help!)

01 January 2008, 12:28 PM
I have a script that chops up any poly object but I don't explode the elements until later because I want to do a soft selection based on the center vertex.

Here's the snippet that does the work.
--dice it up
on btnDice pressed do


--check if an object is selected if not messagebox warning

if selection.count < 1 then


messagebox "Please select an object." Beep: on


--check if more than one object is selected if true messagebox warning

if selection.count > 1 then


messagebox "Only one object can be split at once." Beep: on


--check if object is a poly if not converts to poly

if selection.count ==1 and classof $ != Editable_Poly then


--$.pos = [0,0,0]



--checks if object count is 1 and poly then runs if true

if selection.count == 1 and classof $ == Editable_Poly thenundooff--when undo is on undoing operation crashes Max


setwaitcursor()--waitcursor = hourglass cursor while running script

--$.pos = [0,0,0]-- position object to world center

MoveMax = $.max-$.pivot--defines dimension of the object

MoveMin = $.min-$.pivot--defines dimension of the object

VarChops = spnChopLVL.value --create variable for # of chops

--Dice It up

for i = 1 to VarChops do


polyop.setFaceSelection $ #all--selects all faces of the selected object

polyops.startsliceplane($)--starts the slice plane

--Move and rotate slice plane randomly

Wm_SliceRotate = [(random -1.0 1.0),(random -1.0 1.0),(random -1.0 1.0)]--sets a random value for rotatioin of slice plane

Wm_SliceMove = [(random MoveMin.x MoveMax.x),(random MoveMin.y MoveMax.y),(random MoveMin.z MoveMax.z)]--sets a random value for movement of slice plane

$.split = true--turns on split option for slice plane

$.slice Wm_SliceRotate Wm_SliceMove --slices defined by the random values declared above

polyOp.capHolesByEdge $.baseobject #all--caps holes created by slice/split

polyOp.CollapseDeadStructs--removes any dead structures that could have possibly been created


It continues on from there to select a random face and extract the elements rename them, put them in an array, UVW wrap, unwrap then hide them etc.
---detach elements by selecting a face and create new objects from elements

01 January 2008, 05:20 PM
I'm going to change tactics on the select center. I've been thinking about the soft selection from the center vertex and this wouldn't work for most shapes. Instead I've decided to use theCopy as the voxel vertex collector and dynamically adjust the scale via a spinner. This will ensure collection of verts consistent with the center mass of any shape. Therefore no soft selection is needed. I've also decided against any type of off center (pivot point) noise assignment due to surface artifacting. The slice plane will still rotate around the pivot point thus smaller chunks and more chaos at the defined point of impact.

Now on to the problem at hand.
Updating the selected verts in real time in the viewport as the voxel object selects the verts dynamically as the spinner value changes. How do I dynamically update VertArray when the voxel object is scaled down, will it retain the values already collected when theCopy was larger? Do I need to clear the array then re-collect the verts on spn"X" changed?

Thanks for any input,


VertArray = #()

spinner spnVerts "Selection:" range:[1,100,99] type:#integer align:#center fieldwidth:36

spinner spnVox "Voxel Size:" range:[1,50,10] type:#integer align:#center fieldwidth:36
spinner spnNoise "Noise:" range:[1,100,5] type:#integer align:#center fieldwidth:36

on spnVerts changed val do
on spnNoise changed val do

VarScale = spnVerts.value
VarVox = spnVox.value

for i in selection do
( = uniquename "PolyObj"
copy PolyObj01

theObj = PolyObj01
theCopy = Polyobj02
theCopy scale: (VarScale,VarScale,VarScale)
theCopy.Initialize VarVox
theCopy.addnode theObj
theProxy = snapshotasmesh theObj
for v = 1 to theProxy.numverts do
VertPos = getVert theProxy v

Collect the verts inside theCopy -- scaled via spinner
append VertArray theVoxVerts

Select theObj
max modify mode
setVertSelection theObj 1 VertArray
SubObjectLevel = 1
Delete theCopy
Select theObj
--explode elements etc. etc.

01 January 2008, 05:34 PM
I just want to clarify exactly what we're talking about here.

3 spinners total.

1 for voxel size that does not need screen update. Shouldn't matter much except for calculation times.

The other two spinners will adjust the voxel object size and the noise modifier.

When the object is scaled more or less verts are selected.
When the noise in increased/decreased verts are moved around creating internal chaos inside the object.

Avoid surface artifacting when adding internal noise to the object before exploding it to bits.

The object will be set to "see through" so the artist can adjust vertex noise to scale and adjust the selection set to avoid surface artifacting.

Hope that is clear enough.

Thanks again,

01 January 2008, 04:47 PM
Never mind.

I got it all working now without voxels. I just used theCopy as the soft selection object.

CGTalk Moderation
01 January 2008, 04:47 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.