/////////////////////////////////////////////////////////////////////////////////////////////////Disclaimer///////////////////////////////////////////////////////////////////////////////// //Written By Brian Keffer // //email brian@bk3d.com // // // //This script breaks an object up into chunks // // // // // // // // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// Cap Holes ////////////////////////////////////////////////////////////////////////////////////////// // // // // // // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// global proc Fracture_Union() { string $Sel_Objs[] = `selectedNodes`; string $Base_Obj[] = $Sel_Objs ; for ($c = 1; $c < `size Sel_Objs`; $c++) { if (`objExists $Base_Obj[0]` && `objExists $Sel_Objs[$c]`) { $Base_Obj = `polyBoolOp -op 1 -ch 0 $Base_Obj[0] $Sel_Objs[$c]`; }//end if }//end for c }//end proc ///////////////////////////////////////////////////////////////////////////////////////////////////Find open border edges global proc string[] BK_Find_Open_Edges() { ConvertSelectionToEdges; polySelectConstraint -w 1 -m 2 -bo true -sh false -t 0x8000;//select only border edges $Open_edges =`ls -sl -fl`; polySelectConstraint -m 0 -bo false ;//set constraint to nothing return $Open_edges; }//end proc ///////////////////////////////////////////////////////////////////////////////////////////////////Cap Holes global proc Fracture_Cap_Holes() { $Selected_Object = `selectedNodes`; string $Open_edges[] = BK_Find_Open_Edges(); while (`size $Open_edges` > 0) { select $Open_edges[0]; SelectEdgeLoop; //Extrude edges and collapse polyExtrudeEdge; MergeToCenter; //find open edges // select -r $Selected_Object; $Open_edges = BK_Find_Open_Edges(); }//end while select -r $Selected_Object; }//end proc //////////////////////////////////////////////////////////////////////////////////////// Fracture ////////////////////////////////////////////////////////////////////////////////////////// // // // // // // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////Shader global proc Fracture_Shader() { $Sel_Shader = `ls -sl`; textField -e -tx $Sel_Shader TF_Fracture_Shader; } ///////////////////////////////////////////////////////////////////////////////////////////////////Seperate Unsperated Chunks global proc string[] BK_Seperate_Chunks() //needs to have an object selected { $Chunk_Name = `textField -q -tx TF_Fracture_Chunk_Name`; $Chunk = `ls -sl -fl`; string $New_Chunks[]; ConvertSelectionToFaces; string $Chunk_Faces[] = `ls -sl -fl`; //get faces and seperate if not seperated // select -r $Chunk_Faces[0]; polyConvertToShell; $Face_Shell = `ls -sl -fl`; if (`size $Chunk_Faces` != `size $Face_Shell`) { polySeparate -ch 0 $Chunk; string $parent_Group[] = `listRelatives -p`;//unparent chunks select -r $parent_Group[0]; ungroup; $New_Chunks = `ls -sl -fl`; //rename the new chunks // for ($r = 0; $r < `size $New_Chunks`; $r++) { xform -cp $New_Chunks[$r];//Centers pivot rename $New_Chunks[$r] $Chunk_Name; } $New_Chunks = `ls -sl -fl`; }//end if return $New_Chunks; }//end proc ///////////////////////////////////////////////////////////////////////////////////////////////////Create Fracture Plane global proc string Create_Fracture_Object(float $Cen[], float $Extent) { //get UI settings // float $Noise_Amount =`floatSliderGrp -q -value FF_Noise`; float $Face_Size = `floatSliderGrp -q -value FF_Face_Size`; int $Divisions = ((($Extent * 2) / $Face_Size) - 1);//Calculate divisions progressBar -edit -pr 0 Noise_progress;//reset progress bar to 0 //string $Fracture_Shader = `textField -q -tx TF_Fracture_Shader`; //Create the Cutting Plane // $Cut_Plane = `polyPlane -name "Fracture" -ch on -o on -ax 0 0 1 -w ($Extent * 2) -h ($Extent * 2) -sw $Divisions -sh $Divisions -cuv 2 `; //add Shader // //if ($Fracture_Shader != "") // { // sets -e -forceElement $Fracture_Shader $Cut_Plane; // } //set location of crack // move -a $Cen[0] $Cen[1] $Cen[2] ; ConvertSelectionToVertices; $Selected_Verts = `ls -sl -fl`; progressBar -edit -maxValue (`size $Selected_Verts`) Noise_progress; //Add random noise // if ($Noise_Amount != 0)//dont add noise if noise is zero { for ($v = 0; $v < `size $Selected_Verts`; $v++) { $Displace_Z = `rand ($Noise_Amount * -1) $Noise_Amount`; //select -r $Selected_Verts[$v]; move -r 0 0 $Displace_Z $Selected_Verts[$v]; progressBar -edit -step 1 Noise_progress; }//end for $v }//end if return $Cut_Plane[0]; }//end proc ///////////////////////////////////////////////////////////////////////////////////////////////////BK_Fracture global proc BK_Fracture() { $X_percent = `intSliderGrp -q -v X_percent`; $Y_percent = `intSliderGrp -q -v Y_percent`; $Z_percent = `intSliderGrp -q -v Z_percent`; $Fill_Holes = `checkBox -q -v cb_Fill_Holes`; $Crop_Fracture = `checkBox -q -v cb_Crop_Fracture`; $Create_Group = `checkBox -q -v CB_Group_Chunks`; $Fracture_Group = `textField -q -tx TF_Fracture_Group_Name`; $Chunk_Name = `textField -q -tx TF_Fracture_Chunk_Name`; $Seperate_Chunks =`checkBox -q -v cb_Seperate_Chunks`; $Delete_Slivers = `checkBox -q -v cb_Delete_Slivers`; $Sliver_Size = `intField -q -v sliver_size`; int $Cuts = `intSliderGrp -q -value FF_Cuts`; float $Rand_Rot = `intSliderGrp -q -value FF_Rot`; $Selected_Objs = `ls -sl -l -fl`;//store selected objects string $Chunk; float $Object_Area[]; progressBar -edit -maxValue ($Cuts - 1 ) Fracture_progress; for ($o = 0; $o < `size $Selected_Objs`; $o++) { $Object_Area =`polyEvaluate -a`; string $Chunk_Array[] = {}; progressBar -edit -pr 0 Fracture_progress;//reset progress bar to 0 string $Chunks[] = {};//clear out the array select -r $Selected_Objs[$o]; for ($b = 0; $b < ($Cuts - 1); $b++) { //Fill Holes // if ($Fill_Holes == 1) { Fracture_Cap_Holes(); } $Selected_Obj = `ls -sl -fl`; float $Obj_Bounds[] = `polyEvaluate -b $Selected_Obj`; float $X_Bounds = ($Obj_Bounds[1] - $Obj_Bounds[0]); float $Y_Bounds = ($Obj_Bounds[3] - $Obj_Bounds[2]); float $Z_Bounds = ($Obj_Bounds[5] - $Obj_Bounds[4]); //check for largest extents // float $Extent; if ($X_Bounds >= $Y_Bounds && $X_Bounds >= $Z_Bounds) { $Extent = $X_Bounds; } if ($Y_Bounds >= $X_Bounds && $Y_Bounds >= $Z_Bounds) { $Extent = $Y_Bounds; } if ($Z_Bounds >= $X_Bounds && $Z_Bounds >= $Y_Bounds) { $Extent = $Z_Bounds; } $Dup_Obj = `duplicate $Selected_Obj`; float $Obj_Center[] = `objectCenter -gl`;//location of crack if ($Crop_Fracture == 1) { //adjust Center of cutting plane // float $Adjusted_X = ($Obj_Bounds[0] + ($X_Bounds * (.01 * $X_percent))); float $Adjusted_Y = ($Obj_Bounds[2] + ($Y_Bounds * (.01 * $Y_percent))); float $Adjusted_Z = ($Obj_Bounds[4] + ($Z_Bounds * (.01 * $Z_percent))); $Obj_Center = {$Adjusted_X , $Adjusted_Y, $Adjusted_Z}; } $Crack_Plane = Create_Fracture_Object($Obj_Center, $Extent);//create fracture plane //Set Random Rotation on Plane // $Rand_RotX = `rand ($Rand_Rot * -1) $Rand_Rot`; $Rand_RotY = `rand ($Rand_Rot * -1) $Rand_Rot`; $Rand_RotZ = `rand ($Rand_Rot * -1) $Rand_Rot`; if ($Crop_Fracture == "1" && $X_percent < 50 )//-x { $Rand_RotX = 0; $Rand_RotZ = 0; $Rand_RotY = -90; //$Rand_RotY = `rand -90 -90`; } if ($Crop_Fracture == "1" && $X_percent > 50 )//+x { $Rand_RotX = 0; $Rand_RotZ = 0; $Rand_RotY = 90; //$Rand_RotY = `rand 90 90`; } if ($Crop_Fracture == "1" && $Y_percent < 50 )//-y { $Rand_RotY = 0; $Rand_RotZ = 0; $Rand_RotX = 90; //$Rand_RotX = `rand 90 90`; } if ($Crop_Fracture == "1" && $Y_percent > 50 )//-y { $Rand_RotY = 0; $Rand_RotZ = 0; $Rand_RotX = -90; //$Rand_RotX = `rand -90 -90`; } if ($Crop_Fracture == "1" && $Z_percent != 50 )//Z { $Rand_RotY = 0; $Rand_RotZ = 0; $Rand_RotX = 0; //$Rand_RotX = `rand -90 -90`; } rotate -ws $Rand_RotX $Rand_RotY $Rand_RotZ $Crack_Plane; //Duplicate Cutting Plane // $Dup_Plane = `duplicate $Crack_Plane`; polyNormal -normalMode 3 -ch 0 $Dup_Plane[0]; //Boolean the Object // $Bool_A = `polyBoolOp -op 2 -ch 0 $Selected_Obj $Crack_Plane`;//this is the Top $Bool_B = `polyBoolOp -op 2 -ch 0 $Dup_Obj $Dup_Plane`;//this is the Bottom //add chunks to array to find area // if ($Crop_Fracture == "0") //fracture center { stringArrayInsertAtIndex(0, $Chunks, $Bool_A[0]); stringArrayInsertAtIndex(0, $Chunks, $Bool_B[0]); $Crop_Fracture = 0; } if ($Crop_Fracture == "1" && $Z_percent >= 50 ) //fracture top { stringArrayInsertAtIndex(0, $Chunks, $Bool_A[0]); $Crop_Fracture = 0; } if ($Crop_Fracture == "1" && $Z_percent < 50 ) //fracture bottom { stringArrayInsertAtIndex(0, $Chunks, $Bool_B[0]); $Crop_Fracture = 0; } //find the biggest chunk // float $Chunk_Area[]= {0}; for ($c = 0; $c < `size $Chunks`; $c++) { if (`objExists $Chunks[$c]`)//check to see if object still exists { select $Chunks[$c]; $Chunk_Area = `polyEvaluate -a `;//get the area if ($Chunk_Area[0] > $Chunk_Area[0]) { $Chunk_Area = $Chunk_Area; select -r $Chunks[$c]; }//end if }//end if exists }//end for c progressBar -edit -step 1 Fracture_progress; }//end for b //Seperate Chunks // if ($Seperate_Chunks == 1) { for ($s = 0; $s < `size $Chunks`; $s++) { if (`objExists $Chunks[$s]`)//check to see if object still exists { select $Chunks[$s]; string $New_Chunks[] = BK_Seperate_Chunks(); appendStringArray ($Chunks,$New_Chunks, `size $New_Chunks`); }//end if }//end for $s }//end if //Delete Slivers // if ($Delete_Slivers == 1) { for ($d = 0; $d < `size $Chunks`; $d++) { if (`objExists $Chunks[$d]`)//check to see if object still exists { float $Chunk_Area[] = `polyEvaluate -a $Chunks[$d]`; if ($Chunk_Area[0] < ($Object_Area[0] * ($Sliver_Size *.01) ) ) { delete $Chunks[$d]; } }//end if }//end for $s }//end if //Rename Chunks and center pivots and set normal angle // for ($r = 0; $r < `size $Chunks`; $r++) { if (`objExists $Chunks[$r]`)//check to see if object still exists { $Chunk = `rename $Chunks[$r] $Chunk_Name`; stringArrayInsertAtIndex(0, $Chunk_Array, $Chunk); xform -cp $Chunk;//Centers pivot polySoftEdge -angle 30 -ch 0 $Chunk; }//end if objExists }//end for r //Group Chunks // if ($Create_Group == 1) { group -name $Fracture_Group $Chunk_Array; } }//end for o select $Chunk; }//end proc ///////////////////////////////////////////////////////////////////////////////////////////////////BK_RE_Break global proc BK_RE_Fracture() { $Undo_Search = `undoInfo -q -un`;//check last undo call if ($Undo_Search == "BK_Fracture()") { undo; BK_Fracture(); }//end if if ($Undo_Search == "BK_RE_Fracture()") { undo; BK_Fracture(); }//end if else { print "no fracture to undo"; }//end else }//end proc //////////////////////////////////////////////////////////////////////////////////////// Chip Off /////////////////////////////////////////////////////////////////////////////////////////// // // // // // // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////Create Chip global proc string[] Create_Chip() { $Chip_Size =((`floatSliderGrp -q -value fF_Chip_Size`) / 2); float $Chip_Noise = `floatSliderGrp -q -value fF_Chip_Noise`; $Chip_Mesh = `polyCube -ch on -o on -ax 0 0 1 -w $Chip_Size -h $Chip_Size -d $Chip_Size -cuv 4` ; polySmooth -mth 1 -dv 1 -c 0.5 -kb 1 -ksb 1 -khe 1 -kt 0 -kmb 0 -suv 1 -sl 1 -dpe 1 -ps 1 -ro 0 -ch 1 $Chip_Mesh; ConvertSelectionToVertices; $Selected_Verts = `ls -sl -fl`; for ($v = 0; $v < `size $Selected_Verts`; $v++) { $Displace = `rand 0 $Chip_Noise`; move -r $Displace $Displace $Displace $Selected_Verts[$v]; }//end for $v //polySmooth -mth 1 -dv 1 -c 0.5 -kb 1 -ksb 1 -khe 1 -kt 0 -kmb 0 -suv 1 -sl 1 -dpe 1 -ps 1 -ro 2 -ch 1 $Chip_Mesh; return $Chip_Mesh; }//end proc Create_Chip() ///////////////////////////////////////////////////////////////////////////////////////////////////Chip Off Selected global proc BK_Chip_Off_Sel() { $Keep_Chips = `checkBox -q -v cb_Keep_Chips`; progressBar -edit -pr 0 Chip_progress;//reset progress bar to 0 $Selected_Obj = `ls -hl`; $Selected_Component =`ls -sl -fl`; progressBar -edit -maxValue `size $Selected_Component` Chip_progress; $Chip_Mesh = Create_Chip(); string $Chip_Array[] = {}; //Move chip mesh to vert locations for ($c = 0; $c < `size $Selected_Component`; $c++) { //get vertex location $Chipper = `duplicate $Chip_Mesh[0]`; //add random rotation to chip // $Random_rotation = `rand -90 90`; rotate $Random_rotation $Random_rotation $Random_rotation $Chipper; //Move Chips to Location // stringArrayInsertAtIndex(0, $Chip_Array, $Chipper[0]); //add chips to an array $Component_Location = `xform -q -ws -bb $Selected_Component[$c]`; float $Mid_X =(($Component_Location[3] - $Component_Location [0]) / 2); float $Mid_Y =(($Component_Location[4] - $Component_Location [1]) / 2); float $Mid_Z =(($Component_Location[5] - $Component_Location [2]) / 2); move -r ($Component_Location [0] + $Mid_X) ($Component_Location [1] + $Mid_Y) ($Component_Location [2] + $Mid_Z) $Chipper; }//end for for ($b = 0; $b < `size $Chip_Array`; $b++) { if ($Keep_Chips == 1) { $Chipper = `duplicate $Chip_Array[$b]`; $Chip_Master = `duplicate $Selected_Obj[0]`; $Chip_Object =`polyBoolOp -op 3 -ch 0 $Chip_Master $Chipper`; xform -cp $Chip_Object;//Centers pivot rename $Chip_Object "Fracture_Chip" ; } $Selected_Obj = `polyBoolOp -op 2 -ch 0 $Selected_Obj[0] $Chip_Array[$b]`; progressBar -edit -step 1 Chip_progress; }//end for delete $Chip_Mesh; }//end proc BK_Chip_Off_Sel() ///////////////////////////////////////////////////////////////////////////////////////////////////Chip Off Random global proc string[] BK_Chip_Off_Random() { $Keep_Chips = `checkBox -q -v cb_Keep_Chips`; $Number_Chips =`intSliderGrp -q -value fF_Number_Chips` ; $Component_Type =`radioButtonGrp -q -select rbg_Component`; progressBar -edit -maxValue $Number_Chips Chip_progress; progressBar -edit -pr 0 Chip_progress;//reset progress bar to 0 string $Selected_Obj[]; string $Chip_Array[] = {}; string $New_Chip_Array[] = {}; string $Selected_Objects[] = `selectedNodes`; for ($i = 0; $i < `size $Selected_Objects`; $i++) { print $i; select -r $Selected_Objects[$i]; $Selected_Obj = `selectedNodes`; $Original_Name = `selectedNodes`; //set component selection // if ($Component_Type == 1) { ConvertSelectionToVertices; } if ($Component_Type == 2) { ConvertSelectionToEdges; } if ($Component_Type == 3) { ConvertSelectionToFaces; } $Selected_Component =`ls -sl -fl`; $Total_Verts = `size $Selected_Component`; $Chip_Mesh = Create_Chip(); string $Chip_Array[] = {}; string $Random_Verts_Array[] ={}; if ($Number_Chips > $Total_Verts) { $Number_Chips = $Total_Verts; } //get random verts // while (`size $Random_Verts_Array` < $Number_Chips) { int $Random_Vert = `rand 0 $Total_Verts`; if (stringArrayContains ($Selected_Component[$Random_Vert] , $Random_Verts_Array) != 1) { stringArrayInsertAtIndex(0, $Random_Verts_Array, $Selected_Component[$Random_Vert]); //add chips to an array }//end if }//end while //Move chip mesh to vert locations // for ($c = 0; $c < `size $Random_Verts_Array`; $c++) { $Chipper = `duplicate $Chip_Mesh[0]`; //add random rotation to chip // $Random_rotation = `rand -90 90`; rotate $Random_rotation $Random_rotation $Random_rotation $Chipper; stringArrayInsertAtIndex(0, $Chip_Array, $Chipper[0]); //add chips to an array $Vert_Location = `xform -q -ws -bb $Random_Verts_Array[$c]`; float $Mid_X =(($Vert_Location[3] - $Vert_Location [0]) / 2); float $Mid_Y =(($Vert_Location[4] - $Vert_Location [1]) / 2); float $Mid_Z =(($Vert_Location[5] - $Vert_Location [2]) / 2); move -r ($Vert_Location [0] + $Mid_X) ($Vert_Location [1] + $Mid_Y) ($Vert_Location [2] + $Mid_Z) $Chipper; }//end for //Start chipping away // for ($b = 0; $b < `size $Chip_Array`; $b++) { if ($Keep_Chips == 1) { $Chipper = `duplicate $Chip_Array[$b]`; $Chip_Master = `duplicate $Selected_Obj[0]`; $Chip_Object =`polyBoolOp -op 3 -ch 0 $Chip_Master $Chipper`; xform -cp $Chip_Object;//Centers pivot $Chip_Name = `rename $Chip_Object "Fracture_Chip"`; stringArrayInsertAtIndex(0, $New_Chip_Array, $Chip_Name); } $Selected_Obj = `polyBoolOp -op 2 -ch 0 $Selected_Obj[0] $Chip_Array[$b]`; progressBar -edit -step 1 Chip_progress; }//end for //rename to original name // rename $Selected_Obj $Original_Name ; //center pivot // xform -cp ;//Centers pivot delete $Chip_Mesh; }//end for i return $New_Chip_Array; }//end proc BK_Chip_Off_Random() ///////////////////////////////////////////////////////////////////////////////////////////////////BK_RE_Chip global proc BK_RE_Chip_Off() { $Undo_Search = `undoInfo -q -un`;//check last undo call if ($Undo_Search == "BK_Chip_Off_Random()") { undo; BK_Chip_Off_Random(); }//end if if ($Undo_Search == "BK_RE_Chip_Off()") { undo; BK_Chip_Off_Random(); }//end if else { print "no chip to undo"; }//end else }//end proc BK_RE_Chip_Off() ///////////////////////////////////////////////////////////////////////////////////////////////////Fracture Seperate global proc Fracture_Seperate() { int $Distance = `floatSliderGrp -q -v FF_Fracture_Seperate`; //get Center of broken objects $Selected_Objects = `ls -sl`; $Selected_Extents = `polyEvaluate -b $Selected_Objects`; float $CenterX = (($Selected_Extents[1] + $Selected_Extents[0]) /2); float $CenterY = (($Selected_Extents[3] + $Selected_Extents[2]) /2); float $CenterZ = (($Selected_Extents[5] + $Selected_Extents[4]) /2); float $Size_X = ($Selected_Extents[1] - $Selected_Extents[0]); float $Size_Y = ($Selected_Extents[1] - $Selected_Extents[0]); float $Size_Z = ($Selected_Extents[1] - $Selected_Extents[0]); $average_size = ( ($Size_X + $Size_Y + $Size_Z) /3); //Create Particle Emitter $Fracture_emitter = `emitter -pos $CenterX $CenterY $CenterZ -type omni -r ($average_size * 100) -sro 0 -nuv 0 -cye none -cyi 1 -spd ($average_size /2) -srn 0 -nsp 1 -tsp 0 -mxd 0 -mnd 0 -dx 1 -dy 0 -dz 0 -sp 0 `; $Fractrue_particle = `particle`; setAttr ($Fractrue_particle[0] + ".maxCount") (`size $Selected_Objects`); connectDynamic -em $Fracture_emitter[0] $Fractrue_particle[0]; for ($s = 0; $s < 5; $s++ ) { currentTime $s; } currentTime $Distance; //Explode the chunks outward from center if ($Distance > 0) { for ($s = 0; $s < `size $Selected_Objects`; $s++) { select -r ($Fractrue_particle[0] + ".pt[" + $s + "]") ; float $Particle_Location[] = `xform -q -ws -t`; //select $Selected_Objects[$s]; $Chunk_Location = `xform -q -ws -piv $Selected_Objects[$s]`; move -r ($Chunk_Location[0] * -1) ($Chunk_Location[1] * -1) ($Chunk_Location[2] * -1) $Selected_Objects[$s]; makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 -jointOrient $Selected_Objects[$s]; move -r $Particle_Location[0] $Particle_Location[1] $Particle_Location[2] $Selected_Objects[$s]; } } //Move Z Back to min Z start select $Selected_Objects; $Seperated_Extents = `polyEvaluate -b $Selected_Objects`; move -r 0 0 ($Seperated_Extents[4] * - 1); delete $Fracture_emitter; delete $Fractrue_particle; } global proc Fracture_RE_Seperate() { $Undo_Search = `undoInfo -q -un`;//check last undo call if ($Undo_Search == "Fracture_Seperate()") { undo; Fracture_Seperate(); } if ($Undo_Search == "Fracture_RE_Seperate()") { undo; Fracture_Seperate(); } } ///////////////////////////////////////////////////////////////////////////////////////////////////Fracture Crumble global proc Fracture_Crumble() { //Setup Simulation to collide with floor currentTime 0; $Time = (`floatSliderGrp -q -v FF_Crumble` * 100); $PhysChunks = `ls -sl`; $Explode_Extents = `polyEvaluate -b $PhysChunks`; $Explode_Extents_SizeX = ($Explode_Extents[1] - $Explode_Extents[0]); $Explode_Extents_SizeY = ($Explode_Extents[3] - $Explode_Extents[2]); $Explode_Extents_SizeZ = ($Explode_Extents[5] - $Explode_Extents[4]); string $RigidBoday_Array = `rigidBody -active -cl true -m 10 -dp 0 -sf 0.2 -df 0.2 -b 0 -l 0 -tf 200 -iv 0 0 0 -iav 0 0 0 -c 0 -pc 0 -i 0 0 0 -imp 0 0 0 -si 0 0 0 -sio sphere`; $Fracture_Gravity = `gravity -name "Fracture_Gravity" -pos 0 0 0 -m 980 -att 0 -dx 0 -dy 0 -dz -1 -mxd -1 -vsh none -vex 0 -vof 0 0 0 -vsw 360 -tsr 0.5` ; connectDynamic -f $Fracture_Gravity $PhysChunks; //Create Collision Ground $Adjusted_Extents = `polyEvaluate -b $PhysChunks`; polyPlane -name "Fracture_Collision_Ground" -ch on -o on -ax 0 0 1 -w ($Explode_Extents_SizeZ * 8) -h ($Explode_Extents_SizeZ * 8) -sw 1 -sh 1 -cuv 2 ; move -a 0 0 ($Adjusted_Extents[4] - 100); rigidBody -passive -m 1 -dp 0 -sf 0.2 -df 0.2 -b 0 -l 0 -tf 200 -iv 0 0 0 -iav 0 0 0 -c 0 -pc 0 -i 0 0 0 -imp 0 0 0 -si 0 0 0 -sio cube ; playbackOptions -max 600; currentTime 0; currentTime 100; currentTime $Time; //select $PhysChunks; //Move Z Back to min Z start select $PhysChunks; $Seperated_Extents = `polyEvaluate -b $PhysChunks`; for ($s = 0; $s < `size $PhysChunks`; $s++) { $Chunk_Location = `xform -q -ws -piv $PhysChunks[$s]`; move -r 0 0 ($Chunk_Location[2] * - 1) $PhysChunks[$s]; } //Clean up deleteSelectRigidBodies; delete "Fracture_Gravity"; delete "Fracture_Collision_Ground"; //Fracture_Settle(); } global proc Fracture_RE_Crumble() { $Undo_Search = `undoInfo -q -un`;//check last undo call if ($Undo_Search == "Fracture_Crumble()") { undo; Fracture_Crumble(); } if ($Undo_Search == "Fracture_RE_Crumble()") { undo; Fracture_Crumble(); } } ///////////////////////////////////////////////////////////////////////////////////////////////////Fracture Settle global proc Fracture_Settle() { //Setup Simulation to collide with floor currentTime 0; //$Time = (`floatSliderGrp -q -v FF_Crumble` * 100); $PhysChunks = `ls -sl`; $Explode_Extents = `polyEvaluate -b $PhysChunks`; $Explode_Extents_SizeX = ($Explode_Extents[1] - $Explode_Extents[0]); $Explode_Extents_SizeY = ($Explode_Extents[3] - $Explode_Extents[2]); $Explode_Extents_SizeZ = ($Explode_Extents[5] - $Explode_Extents[4]); string $RigidBoday_Array = `rigidBody -active -cl true -m 1 -dp 0 -sf 0.2 -df 0.2 -b 0 -l 0 -tf 200 -iv 0 0 0 -iav 0 0 0 -c 0 -pc 0 -i 0 0 0 -imp 0 0 0 -si 0 0 0 -sio none`; $Fracture_Gravity = `gravity -name "Fracture_Gravity" -pos 0 0 0 -m 980 -att 0 -dx 0 -dy 0 -dz -1 -mxd -1 -vsh none -vex 0 -vof 0 0 0 -vsw 360 -tsr 0.5` ; connectDynamic -f $Fracture_Gravity $PhysChunks; //Create Collision Ground polyPlane -name "Fracture_Collision_Ground" -ch on -o on -ax 0 0 1 -w ($Explode_Extents_SizeX * 100) -h ($Explode_Extents_SizeY * 100) -sw 1 -sh 1 -cuv 2 ; move -a 0 0 ($Explode_Extents[4] - 100); rigidBody -passive -m 1 -dp 0 -sf 0.2 -df 0.2 -b 0 -l 0 -tf 200 -iv 0 0 0 -iav 0 0 0 -c 0 -pc 0 -i 0 0 0 -imp 0 0 0 -si 0 0 0 -sio cube ; playbackOptions -max 600; //currentTime 0; currentTime 300; //Move Z Back to min Z start select $PhysChunks; //$Seperated_Extents = `polyEvaluate -b`; //move -r 0 0 ($Seperated_Extents[4] * - 1); //Clean up deleteSelectRigidBodies; delete "Fracture_Gravity"; delete "Fracture_Collision_Ground"; } global proc Fracture_Explode() { Fracture_Seperate(); Fracture_Crumble(); Fracture_Settle(); } ////////////////////////////////////////////////////////////////////////////////////////////////////Open Help global proc Open_Fracture_Help() { system ("load http://www.bk3d.com/Scripts/Mel/Fracture/Fracture.htm") ; }//end proc ////////////////////////////////////////////////////////////////////////////////////////////////////Enable_Group checkbox global proc Fracture_Enable_Group() { textField -e -en true TF_Fracture_Group_Name; } ////////////////////////////////////////////////////////////////////////////////////////////////////Disable_Group checkbox global proc Fracture_Disable_Group() { textField -e -en false TF_Fracture_Group_Name; } global proc Fracture_Set_Meters() { intSliderGrp -e -v 2 FF_Cuts; floatSliderGrp -e -v .4 FF_Face_Size; floatSliderGrp -e -v .2 FF_Noise; intSliderGrp -e -v 45 FF_Rot; intSliderGrp -e -v 50 X_percent; intSliderGrp -e -v 50 Y_percent; intSliderGrp -e -v 50 Z_percent; intSliderGrp -e -v 1 fF_Number_Chips; floatSliderGrp -e -v .2 fF_Chip_Noise; floatSliderGrp -e -v 1 fF_Chip_Size; } global proc Fracture_Set_Centimeters() { intSliderGrp -e -v 2 FF_Cuts; floatSliderGrp -e -v 40 FF_Face_Size; floatSliderGrp -e -v 20 FF_Noise; intSliderGrp -e -v 45 FF_Rot; intSliderGrp -e -v 50 X_percent; intSliderGrp -e -v 50 Y_percent; intSliderGrp -e -v 50 Z_percent; intSliderGrp -e -v 1 fF_Number_Chips; floatSliderGrp -e -v 20 fF_Chip_Noise; floatSliderGrp -e -v 100 fF_Chip_Size; } global proc Fracture_Set_Presets() { int $M = (`currentUnit -q -l` == "m");//check if meters int $CM = (`currentUnit -q -l` == "cm");//check if Centimeters if ($M == 1) { Fracture_Set_Meters(); } if ($CM == 1) { Fracture_Set_Centimeters(); } }//end proc global proc Fracture_Enable_Bias() { intSliderGrp -e -en true X_percent; intSliderGrp -e -en true Y_percent; intSliderGrp -e -en true Z_percent; } global proc Fracture_Disable_Bias() { intSliderGrp -e -en false X_percent; intSliderGrp -e -en false Y_percent; intSliderGrp -e -en false Z_percent; } //////////////////////////////////////////////////////////////////////////////////////// UI //////////////////////////////////////////////////////////////////////////////////////////////// // // // // // // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// global proc Build_Fracture_UI() { $UI_Width = 250; //Fracture Menu // menuBarLayout; menu -label "Help" -helpMenu true; menuItem -label "Open Help Page" -c ("Open_Fracture_Help()"); menu -label "Presets"; menuItem -label "Meters" -c ("Fracture_Set_Meters()"); menuItem -label "Centimeters" -c ("Fracture_Set_Centimeters()"); setParent.. ; string $Fracture_tabs = `tabLayout -bgc 1.0 1.0 1.0 -innerMarginWidth 0 -innerMarginHeight 0`; //Fracture UI // string $Tab_Fracture = `columnLayout`; frameLayout -label "Fracture" -borderStyle "in" -cl false -cll true FL_Fracture; columnLayout; separator -height 10 -width $UI_Width; progressBar -height 10 -width $UI_Width -bgc 1 0 0 Fracture_progress; progressBar -height 10 -width $UI_Width -bgc 1 0 0 Noise_progress; separator -height 10 -width $UI_Width; intSliderGrp -cal 1 "left" -cw3 100 50 100 -l "# Chunks" -minValue 2 -maxValue 100 -value 2 -fieldMinValue 2 -fieldMaxValue 10000 -field true -adjustableColumn3 3 -cc ("BK_RE_Fracture()") FF_Cuts; floatSliderGrp -cal 1 "left" -cw3 100 50 100 -l "Face Size" -pre 2 -minValue .01 -maxValue 1000.00 -value 40 -fieldMinValue .01 -fieldMaxValue 10000 -ss 1 -field true -adjustableColumn3 3 -cc ("BK_RE_Fracture()") FF_Face_Size; floatSliderGrp -cal 1 "left" -cw3 100 50 100 -l "Random Noise" -pre 2 -minValue 0 -maxValue 1000 -value 20 -fieldMinValue .01 -fieldMaxValue 10000 -ss 1 -field true -adjustableColumn3 3 -cc ("BK_RE_Fracture()") FF_Noise; intSliderGrp -cal 1 "left" -cw3 100 50 100 -l "Random Rotation" -minValue 0 -maxValue 90 -value 45 -fieldMinValue 0 -fieldMaxValue 180 -field true -adjustableColumn3 3 -cc ("BK_RE_Fracture()") FF_Rot; separator -height 10 -width $UI_Width; checkBox -l "Fracture Area Bias" -onc ("Fracture_Enable_Bias()") -ofc ("Fracture_Disable_Bias()") cb_Crop_Fracture; intSliderGrp -en false -cal 1 "left" -cw3 40 40 170 -l " X%" -minValue 0 -maxValue 100 -v 50 -field true -adjustableColumn3 3 -cc ("BK_RE_Fracture()") X_percent ; intSliderGrp -en false -cal 1 "left" -cw3 40 40 170 -l " Y%" -minValue 0 -maxValue 100 -v 50 -field true -adjustableColumn3 3 -cc ("BK_RE_Fracture()") Y_percent; intSliderGrp -en false -cal 1 "left" -cw3 40 40 170 -l " Z%" -minValue 0 -maxValue 100 -v 50 -field true -adjustableColumn3 3 -cc ("BK_RE_Fracture()") Z_percent; separator -height 10 -width $UI_Width; text -l "Chunks Name"; textField -w $UI_Width -tx "Fracture_Chunk_01" TF_Fracture_Chunk_Name; separator -height 10 -width $UI_Width; checkBox -l "Create in New Group" -onc ("Fracture_Enable_Group()") -ofc ("Fracture_Disable_Group()") CB_Group_Chunks; text -l "Group Name"; textField -en false -w $UI_Width -tx "Fracture_Group_01" TF_Fracture_Group_Name; separator -height 10 -width $UI_Width; //textField -w $UI_Width TF_Fracture_Shader; //button -label "Set Shading Group" -bgc .75 .75 .75 -h 30 -w $UI_Width -c ("Fracture_Shader()"); checkBox -l "Auto Fill Holes" -v 1 cb_Fill_Holes; checkBox -l "Seperate unseperated Chunks" -v 1 cb_Seperate_Chunks; rowColumnLayout -nc 3 -cw 1 150 -cw 2 30 -cw 3 100; checkBox -l "Delete chunks smaller than" -v 0 cb_Delete_Slivers; intField -v 5 sliver_size; text -l "% of object"; setParent..; separator -height 10 -width $UI_Width; button -label "Fracture" -bgc .75 .75 .75 -h 30 -w $UI_Width -c ("BK_Fracture()"); button -label "Try Again" -bgc .75 .75 .75 -h 30 -w $UI_Width -c ("BK_RE_Fracture()"); separator -height 10 -width $UI_Width; setParent.. ;//parent columnLayout setParent.. ;//parent framelayout setParent.. ;//parent Tab_Fracture //Chip Off UI // string $Tab_Chip = `columnLayout`; frameLayout -label "Chip Off" -borderStyle "in" -cl false -cll true FL_Chip; columnLayout; separator -height 10 -width $UI_Width; progressBar -height 10 -width $UI_Width -bgc 1 0 0 Chip_progress; intSliderGrp -cal 1 "left" -cw3 100 50 100 -l "# chips" -minValue 1 -maxValue 100 -value 1 -fieldMinValue 1 -fieldMaxValue 10000 -field true -adjustableColumn3 3 -cc ("BK_RE_Chip_Off()") fF_Number_Chips; floatSliderGrp -cal 1 "left" -cw3 100 50 100 -l "Chip Noise" -pre 2 -minValue .01 -maxValue 1000.00 -value 20 -fieldMinValue .01 -fieldMaxValue 10000 -field true -adjustableColumn3 3 -cc ("BK_RE_Chip_Off()")fF_Chip_Noise; floatSliderGrp -cal 1 "left" -cw3 100 50 100 -l "Chip size(radius)" -pre 2 -minValue .01 -maxValue 1000.00 -value 100 -fieldMinValue .01 -fieldMaxValue 10000 -field true -adjustableColumn3 3 -cc ("BK_RE_Chip_Off()")fF_Chip_Size; radioButtonGrp -columnWidth4 50 50 50 50 -numberOfRadioButtons 3 -label "center" -labelArray3 "verts" "edges" "faces" -select 1 rbg_Component; separator -height 10 -width $UI_Width; checkBox -l "Keep Chips" -v 1 cb_Keep_Chips; button -label "Remove random Chips" -bgc .75 .75 .75 -h 30 -w $UI_Width -c ("BK_Chip_Off_Random()"); button -label "Try Again" -bgc .75 .75 .75 -h 30 -w $UI_Width -c ("BK_RE_Chip_Off()"); separator -height 10 -width $UI_Width; button -label "Remove Chips at selected component" -bgc .75 .75 .75 -h 30 -w $UI_Width -c ("BK_Chip_Off_Sel()"); separator -height 10 -width $UI_Width; setParent.. ;//parent columnLayout setParent.. ;//parent framelayout setParent.. ;//parent Chip Tab //Explode UI // string $Tab_Explode = `columnLayout`; frameLayout -label "Explode" -borderStyle "in" -cl false -cll true FL_Explode; columnLayout; separator -height 10 -width $UI_Width; button -label "Seperate Chunks" -bgc .75 .75 .75 -h 30 -w $UI_Width -c ("Fracture_Seperate()"); floatSliderGrp -cal 1 "left" -cw3 100 50 100 -l "Seperate Amount" -pre 2 -minValue 0 -maxValue 500 -value 100 -fieldMinValue 0 -fieldMaxValue 10000 -ss 1 -field true -adjustableColumn3 3 -cc ("Fracture_RE_Seperate()") FF_Fracture_Seperate; separator -height 10 -width $UI_Width; button -label "Crumble" -bgc .75 .75 .75 -h 30 -w $UI_Width -c ("Fracture_Crumble()"); floatSliderGrp -cal 1 "left" -cw3 100 50 100 -l "Crumble Amount" -pre 2 -minValue 0 -maxValue 1 -value .5 -fieldMinValue 0 -fieldMaxValue 100 -ss 1 -field true -adjustableColumn3 3 -cc ("Fracture_RE_Crumble()") FF_Crumble; separator -height 10 -width $UI_Width; button -label "Settle" -bgc .75 .75 .75 -h 30 -w $UI_Width -c ("Fracture_Settle()"); //button -label "Explode" -bgc .75 .75 .75 -h 30 -w $UI_Width -c ("Fracture_Explode()"); setParent.. ;//parent columnLayout setParent.. ;//parent framelayout setParent.. ;//parent Explode Tab //Helpers UI // string $Tab_Helpers = `columnLayout`; frameLayout -label "Helpers" -borderStyle "in" -cl false -cll true FL_Help; columnLayout; separator -height 10 -width $UI_Width; button -label "Seperate Unsperated Chunks" -bgc .75 .75 .75 -h 30 -w $UI_Width -c ("BK_Seperate_Chunks()"); button -label "Cap Holes" -bgc .75 .75 .75 -h 30 -w $UI_Width -c ("Fracture_Cap_Holes()"); button -label "Union Selected" -bgc .75 .75 .75 -h 30 -w $UI_Width -c ("Fracture_Union()"); setParent.. ;//parent columnLayout setParent.. ;//parent framelayout setParent.. ;//parent Tab_Helpers setParent..; tabLayout -edit -tabLabel $Tab_Fracture "Fracture" -tabLabel $Tab_Chip "Chip Off" -tabLabel $Tab_Explode "Explode" -tabLabel $Tab_Helpers "Helpers" $Fracture_tabs; }//end proc global proc Fracture() { $UI_Width = 250; if ((`window -ex Fracture_UI`) == true) deleteUI Fracture_UI; $Fracture_Window = `window -title "Fracture Demo" -w $UI_Width Fracture_UI`; Build_Fracture_UI(); Fracture_Set_Presets(); showWindow Fracture_UI; }