//THIS SCRIPT IS DESIGNED FOR USE WITH THE 'LFA SCENE MANAGER' TO EXPORT //COLLISIONS THAT ARE BOXES (AABB collision). //OBJECTS PARENTED TO WORLD THAT ARE IN A LAYER CALLED 'COL' WILL EXPORT ITS BOUNDING BOX AS COLLISION. //CHILD OBJECTS WILL EXPORT AS CHILD BOXES, THEY MUST ALL BE IN THE 'COL' LAYER TO EXPORT. //boxes can be given NODE user data. global int $lfa_collisionSectionSize = 100; global proc string lfa_exportCollisionBox(string $box, string $depth) { string $output; float $bbox[6]; $bbox = `exactWorldBoundingBox $box`; $output += ($depth + "\n"); $output += $userData; for ($aBox in $childBoxes) { if (`objectLayer $aBox` == "COL") $output += `lfa_exportCollisionBox $aBox ($depth+" ")`; } $output += $depth + "\n"; } else $output += "/>\n"; return $output; } global proc lfa_exportCollisions() { string $nameOfScene = basenameEx(`file -q -sn`); if ($nameOfScene == "") $nameOfScene = "Untitled"; string $dir = (`lfa_parseDirectoryField`+"/"+$nameOfScene+".col"); $dir = `toNativePath($dir)`; int $fileID=`fopen ($dir) "w"`; if ($fileID == 0) { error "Invalid directory or write protected file."; } else { string $output = "\n"; string $allNodes[] = `ls -tr`; string $colObjects[]; for ($currentNode in $allNodes) { if (`objectLayer $currentNode` == "COL") { if (! size(`listRelatives -p $currentNode`)) //if parented to world $colObjects[`size $colObjects`] = $currentNode; } } for ($aBox in $colObjects) { //export the parent box using it's pivot at origin vector $xyz = `getAttr ($aBox +".rotatePivot")`; float $tx = `getAttr ($aBox +".tx")`; float $ty = `getAttr ($aBox +".ty")`; float $tz = `getAttr ($aBox +".tz")`; move -r (-$tx) (-$ty) (-$tz) $aBox; move -r (-$xyz.x) (-$xyz.y) (-$xyz.z) $aBox; $output += lfa_exportCollisionBox($aBox, " "); //export //move it back move -r $tx $ty $tz $aBox; move -r ($xyz.x) ($xyz.y) ($xyz.z) $aBox; } $output += "\n"; fprint $fileID $output; fclose $fileID; print ("Output collision data to: "+$dir); } }