PDA

View Full Version : Cracked Geometry Script


kogden
03-30-2009, 01:17 PM
Hi everyone!

I am just learning maxscript and saw a fracture geometry script ages ago on script spot called MBFracture (http://scripts.breidt.net/index.html#fracture)which gave me the initial idea :)

But first i wanted to learn the basic's...ie "For" loops and "if" statement!......Well this is what the basics turned into three days later:O

Basically I started on the weekend that has just finished, and made a similar little tool, no where in the realm of anything too fantastic and not really a tool for a team of people to use, but as it is my first attempt at a script (and i mean first!) so i am pretty happy with it overall result!

Also most of the reference came from watching the listener window and reading tones of maxscript help docs.

I hope it you guys like it :)

Suggestion are definitely welcome!

Next hopefully i will be moveing on to learning arrays...well understanding how to use them :)

Cool hope you enjoy!

--------------------------------------------------------------------
Okay to the script!

Things to know before hand....and this is because i am still learning and am grasping the concept of everything!

1. Currently the object it breaks needs to be under a file unit size of 100 (need to do a bounding box check on the object and feed that back to the script, but need to learn)
2. The object needs to be at world zero (need to move the cutting objects to the local position of the selected "to be cut" object)
3. For some reason the script crashes after a few goes...not sure why...
4. The object needs to be "water tight" ie haev not open edges, it crashs the script...not sure why.
5. Uncoment the "gc()" comand at own risk as this crashes the script when run (must have in incorrect place i gather)
6 You need to have the object you want to break selected first, before you execute the "Crack" button.(would like to make a list box for this, but need to learn more about how array's work ie actually write them)
7. This will only work in Max 09 and up. was made in 2009, but does work in v9.0.
8. Also i have managed to get this script to work up to 40 times without it crashing, but other times crash first go, not sure why, maybe a random seed it doesn't like.
9. Be kind! This is my very first attempt, but over-all i am happy with what i made!


/*
Created by Kieran Ogden-Brunell March 2009
This script should break a selected object into chunks
Good for stone/rock debris

--FOR LATER REVISION--
______________________
- Pick button for object
- List box for multi objects
- Bounding box function to drive crack plane sizes (currently this is a hard coded value of 120 in scene size)
- Dialog box for user enable cancel or continue
- Save "tick" option, so scene is saved before calculation
- Tick option to keep original mesh
- Iteration feature to run the simulation over the first pass cracks
- Minimum size threshold for breaking on first pass and iteration
_______________________

KNOW ISSUE"S
_______________________
- Crash's MAX randomly if used to much.
- Process breaks if the crack planes are too small compared to the user object
- Crash's the script if objects aren't "water tight"
- Crash's teh script if the object is too far from world zero.
- If the crack scripted is used on already cracked mesh, sometimes removes part of the orignal object.
_______________________

*/



rollout kobCracks "Crack Geometry"
(
edittext _oName "Name" fieldWidth: 160 height:16

spinner _pAmount "Crack Density" type:#integer range:[1,20,8]
spinner _pSegs "Crack Detail" type:#integer range:[10,30,20]
spinner _pNoiseHieght "Crack Shear" range:[0,120,55]
spinner _pSmoothAmount "Internal Smooth" range:[0,90,65]


button _create "Create Cracks" width:150 height:50 tooltip:"Crack Object!"--this should eventually name the seperate chunks!

-- create planes from the spinners value

on _create pressed do
(

if _pAmount.value >= 15 then messagebox "WARNING: Could become unstable!" --warns if you have too many planes need a cancel or continue dialog

DisableSceneRedraw
(
_firstPlane = null

for j = 1 to _pAmount.value do
(

p= (plane())
p.name = uniquename "cutPlanes"
if (j == 1) then _firstPlane = p
p.length = 150
p.width = 150
p.lengthsegs = _pSegs.value
p.widthsegs =_pSegs.value
p.wirecolor = [random 0 255,random 0 255,random 0 255]

--adding noise modifier to plane

addModifier p (Noisemodifier())
p.modifiers[#Noise].seed = random 1 1000
p.modifiers[#Noise].scale = random 45 85
p.modifiers[#Noise].fractal = on
p.modifiers[#Noise].strength = [(random 0.0 1),(random 0.0 1),(random _pNoiseHieght.value (_pNoiseHieght.value+5))]

--adding smooth modifier to plane

addModifier p (smooth())
p.modifiers[#smooth].autosmooth = on
p.modifiers[#smooth].threshold = _pSmoothAmount.value

--rotates planes in "for" a random value from 0 to 360 degrees

rotate p (eulerAngles (random 0 360) (random 0 360) (random 0 360))

--convert to edit poly
convertTo p (Editable_Poly)

if (j > 1) then polyop.attach _firstPlane p

)

-- this is the pro cutter section currently works with one cut
a = _firstPlane
c = $
ProCutter.CreateCutter #(a) 1 True True False True True
ProCutter.AddStocks a #(c) 1 1
Delete a

-- Rename objects to the name specified

all = $cutPlanes*
all.name = uniquename _oName.text

)

EnableSceneRedraw()

)

button _howToBox "Info" tooltip:"Info"

on _howToBox pressed do
(
messagebox "Create an Object or use an existing prop. \n Select the mesh you want to crack. \nPress Create Cracks to Run!"
)


button _aboutBox "About" tooltip:"About"

on _aboutBox pressed do
(
messagebox "This script creates cracks in selected objects\nCreated by Kieran Ogden-Brunell 2009"
)

)
createdialog kobCracks width:220 height:220




Enjoy!

kogden
04-02-2009, 03:28 AM
So any tips??

SoLiTuDe
04-05-2009, 12:34 AM
Things to know before hand....and this is because i am still learning and am grasping the concept of everything!

1. Currently the object it breaks needs to be under a file unit size of 100 (need to do a bounding box check on the object and feed that back to the script, but need to learn)
2. The object needs to be at world zero (need to move the cutting objects to the local position of the selected "to be cut" object)
3. For some reason the script crashes after a few goes...not sure why...
4. The object needs to be "water tight" ie haev not open edges, it crashs the script...not sure why.
5. Uncoment the "gc()" comand at own risk as this crashes the script when run (must have in incorrect place i gather)
6 You need to have the object you want to break selected first, before you execute the "Crack" button.(would like to make a list box for this, but need to learn more about how array's work ie actually write them)
7. This will only work in Max 09 and up. was made in 2009, but does work in v9.0.
8. Also i have managed to get this script to work up to 40 times without it crashing, but other times crash first go, not sure why, maybe a random seed it doesn't like.
9. Be kind! This is my very first attempt, but over-all i am happy with what i made!


1. You can use obj.max.x - obj.min.x to get dimensions of the object... do that for x, y and z, and find the biggest axis and use that + some extra as the dimensions of your cutter.
2. Cutter.position = stockobj.position
3. Because procutter is buggy as F.
4. Because procutter isn't meant for objects with holes. =) --maybe look for ways to fix or warn before cutting?
5. Probably related to procutter... maybe run the gc before you start, allow the whole script to run, and then maybe again when the whole process is over..?
6. I usually do one array to contain the objects, and then one array to contain the names of the objects for the listbox.
sel = selection as array --stores the actual objects
uinames = #() --create new array
for o in sel do append uinames o.name --take the names of the objects and put them in the uinames array
listbox.items = uinames --set the listbox items
I usually add some refresh button so you can make a new selection of objects and recollect them...
7. Really? Probooleans / Procutter was in max 9 i thought... I don't see anything you're using that isn't backward compatible, but either way, no biggie.
8. Probably procutter again. :)
9. Pfffft You suck! :wavey:

Good job dude!

--Ian

CGTalk Moderation
04-05-2009, 12:34 AM
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.