mirror of
https://github.com/bulletphysics/bullet3
synced 2025-01-11 01:40:10 +00:00
e459145b91
Constraints reworked - all of them could now work with one or two bodies Modification of constraint frames and initial positions of rigid bodies now allowed at start frame only Plugin version is set to 2.76
975 lines
37 KiB
Plaintext
975 lines
37 KiB
Plaintext
/*
|
|
Bullet Continuous Collision Detection and Physics Library Maya Plugin
|
|
Copyright (c) 2008 Walt Disney Studios
|
|
|
|
This software is provided 'as-is', without any express or implied warranty.
|
|
In no event will the authors be held liable for any damages arising
|
|
from the use of this software.
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
including commercial applications, and to alter it and redistribute it freely,
|
|
subject to the following restrictions:
|
|
|
|
1. The origin of this software must not be misrepresented; you must
|
|
not claim that you wrote the original software. If you use this
|
|
software in a product, an acknowledgment in the product documentation
|
|
would be appreciated but is not required.
|
|
2. Altered source versions must be plainly marked as such, and must
|
|
not be misrepresented as being the original software.
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
Written by: Nicola Candussi <nicola@fluidinteractive.com>
|
|
|
|
Modified by Roman Ponomarev <rponom@gmail.com>
|
|
01/22/2010 : Constraints reworked
|
|
*/
|
|
|
|
//dynamicaUI.mel
|
|
|
|
//
|
|
global string $dynamicaUIWindow = "dynamicaUIWindow";
|
|
|
|
|
|
global proc dynamicaUI_initialize()
|
|
{
|
|
dynamicaUI_createShelfButton();
|
|
|
|
//add script jobs
|
|
// scriptJob -e "SceneOpened" gpufxGUI_updateSettings;
|
|
// scriptJob -e "timeChanged" "dynamicaUI_timeChangedCallback";
|
|
// scriptJob -cc "playingBack" "dynamicaUI_playingBackCallback";
|
|
// expression -string "dynamicaUI_timeChangedCallback";
|
|
|
|
}
|
|
|
|
//main window
|
|
global proc dynamicaUI_createWindow()
|
|
{
|
|
global string $dynamicaUIWindow;
|
|
|
|
//check if the window exists
|
|
if ( `window -ex $dynamicaUIWindow` )
|
|
{
|
|
showWindow $dynamicaUIWindow;
|
|
return;
|
|
}
|
|
|
|
//create dSolver node if necessary
|
|
dSolver;
|
|
|
|
$dynamicaUIWindow = `window -t "dynamica"`;
|
|
|
|
string $mainForm = `formLayout`;
|
|
string $tabs = `tabLayout -innerMarginWidth 5 -innerMarginHeight 5`;
|
|
|
|
formLayout -e
|
|
-attachForm $tabs "top" 0
|
|
-attachForm $tabs "left" 0
|
|
-attachForm $tabs "bottom" 0
|
|
-attachForm $tabs "right" 0
|
|
$mainForm;
|
|
|
|
|
|
string $mainLayt = dynamicaUI_createMainTab();
|
|
string $solverLayt = dynamicaUI_createSolverTab();
|
|
|
|
tabLayout -e -tabLabel $mainLayt "Create" -tabLabel $solverLayt "Solver" $tabs;
|
|
|
|
showWindow $dynamicaUIWindow;
|
|
// window -e -wh 479 664 $dynamicaUIWindow;
|
|
|
|
}
|
|
|
|
global proc dynamicaUI_createShelfButton()
|
|
{
|
|
// The shelf we want to add the button to.
|
|
string $shelf = "EfxToolsLumiere";
|
|
|
|
// The icon we want to use on the button.
|
|
string $iconImage = "dynamica.xpm";
|
|
|
|
// Tle button label.
|
|
string $iconBtnLabel = "dynamica";
|
|
|
|
// Specify the shelf as the parent for our tool button. If there
|
|
// is no such shelf, we create it.
|
|
//
|
|
string $btnParent;
|
|
if ( `shelfLayout -ex $shelf` )
|
|
{
|
|
$btnParent = $shelf;
|
|
|
|
// Check to see if the shelf already has the gpufx button. If so,
|
|
// we want to delete it before we remake it so we don't end up with
|
|
// duplicate buttons on the shelf.
|
|
|
|
string $existingShelfButtons[] = `shelfLayout -q -ca $shelf`;
|
|
for ( $btn in $existingShelfButtons )
|
|
if ( `shelfButton -q -l $btn` == $iconBtnLabel )
|
|
deleteUI $btn;
|
|
} else {
|
|
// Create the shelf under the global shelf parent.
|
|
global string $gShelfTopLevel;
|
|
$btnParent = `shelfLayout -p $gShelfTopLevel $shelf`;
|
|
}
|
|
|
|
// Make (or remake) the tool button.
|
|
shelfButton -label $iconBtnLabel -image1 $iconImage
|
|
-command "dynamicaUI_createWindow" -p $btnParent;
|
|
|
|
}
|
|
|
|
global proc string dynamicaUI_createSolverTab()
|
|
{
|
|
global string $dynamicaUI_STsolverType;
|
|
global string $dynamicaUI_STgravityX;
|
|
global string $dynamicaUI_STgravityY;
|
|
global string $dynamicaUI_STgravityZ;
|
|
global string $dynamicaUI_STenabled;
|
|
global string $dynamicaUI_STsplitImpulse;
|
|
global string $dynamicaUI_STsubsteps;
|
|
|
|
string $mainForm = `columnLayout -adj 1`;
|
|
{
|
|
string $solverTypeFrame = `frameLayout -collapsable false -label "Solver Type" -borderStyle "etchedIn"`;
|
|
{
|
|
rowLayout -nc 1 -adj 1 -cat 1 "left" 30;
|
|
{
|
|
int $solverType = `getAttr dSolver1.ssSolverType` + 1; // 1-based
|
|
$dynamicaUI_STsolverType = `textScrollList -append "Bullet Physics" -append "Ageia PhysX" -append "Stanford PhysBAM"
|
|
-selectIndexedItem $solverType
|
|
-numberOfRows 1
|
|
-sc dynamicaUI_STSolverTypeChanged`;
|
|
setParent ..;
|
|
}
|
|
setParent ..;
|
|
}
|
|
string $gravityFrame = `frameLayout -collapsable false -label "Gravity" -borderStyle "etchedIn"`;
|
|
{
|
|
rowLayout -nc 3 -cat 1 "both" 0 -cat 2 "both" 0 -cat 3 "both" 0 -cw3 50 50 50;
|
|
{
|
|
float $gravity[] = `getAttr dSolver1.gravity`;
|
|
$dynamicaUI_STgravityX = `floatField -precision 3 -value $gravity[0] -changeCommand dynamicaUI_STgravityChanged`;
|
|
$dynamicaUI_STgravityY = `floatField -precision 3 -value $gravity[1] -changeCommand dynamicaUI_STgravityChanged`;
|
|
$dynamicaUI_STgravityZ = `floatField -precision 3 -value $gravity[2] -changeCommand dynamicaUI_STgravityChanged`;
|
|
|
|
setParent ..;
|
|
}
|
|
setParent ..;
|
|
}
|
|
string $substepsFrame = `frameLayout -collapsable false -label "Substeps" -borderStyle "etchedIn"`;
|
|
{
|
|
rowLayout -nc 1 -cat 1 "both" 0 -cw1 50;
|
|
{
|
|
int $substeps = `getAttr dSolver1.substeps`;
|
|
$dynamicaUI_STsubsteps = `intField -value $substeps -changeCommand dynamicaUI_STsubstepsChanged`;
|
|
|
|
setParent ..;
|
|
}
|
|
setParent ..;
|
|
}
|
|
string $enabledFrame = `frameLayout -collapsable false -label "Solver State" -borderStyle "etchedIn"`;
|
|
{
|
|
rowLayout -nc 1 -adj 1 -cat 1 "left" 30;
|
|
{
|
|
int $enabled = `getAttr dSolver1.enabled`;
|
|
$dynamicaUI_STenabled = `checkBox -label "Enabled" -value $enabled
|
|
-cc dynamicaUI_STenabledChanged`;
|
|
setParent ..;
|
|
}
|
|
setParent ..;
|
|
}
|
|
string $splitImpulseFrame = `frameLayout -collapsable false -label "SplitImpulse" -borderStyle "etchedIn"`;
|
|
{
|
|
rowLayout -nc 1 -adj 1 -cat 1 "left" 30;
|
|
{
|
|
int $enabled = `getAttr dSolver1.splitImpulse`;
|
|
$dynamicaUI_STsplitImpulse = `checkBox -label "Enabled" -value $enabled
|
|
-cc dynamicaUI_STsplitImpulseChanged`;
|
|
setParent ..;
|
|
}
|
|
setParent ..;
|
|
}
|
|
setParent ..;
|
|
}
|
|
|
|
return $mainForm;
|
|
}
|
|
|
|
global proc string dynamicaUI_createMainTab()
|
|
{
|
|
string $mainForm = `columnLayout -adj 1`;
|
|
{
|
|
frameLayout -collapsable true -label "Active Rigid Bodies" -borderStyle "in";
|
|
{
|
|
rowLayout -nc 5;
|
|
{
|
|
string $createActiveSphereRBBtn = `iconTextButton -style "iconAndTextVertical" -label "Sphere"
|
|
-width 100 -image1 "dynamicaCreateActiveSphereRB.xpm" -c ("dynamicaUI_createActiveSphereRB")
|
|
-ann "Create an active sphere rigid body"`;
|
|
|
|
string $createActiveBoxRBBtn = `iconTextButton -style "iconAndTextVertical" -label "Box"
|
|
-width 100 -image1 "dynamicaCreateActiveBoxRB.xpm" -c ("dynamicaUI_createActiveBoxRB")
|
|
-ann "Create an active box rigid body"`;
|
|
|
|
string $createActivePlaneRBBtn = `iconTextButton -style "iconAndTextVertical" -label "Plane"
|
|
-width 100 -image1 "dynamicaCreateActivePlaneRB.xpm" -c ("dynamicaUI_createActivePlaneRB")
|
|
-ann "Create an active plane rigid body"`;
|
|
|
|
string $createActiveHullRBBtn = `iconTextButton -style "iconAndTextVertical" -label "Hull"
|
|
-width 100 -image1 "dynamicaCreateActiveHullRB.xpm" -c ("dynamicaUI_createActiveHullRB")
|
|
-ann "Create an active hull rigid body"`;
|
|
|
|
string $createActiveMeshRBBtn = `iconTextButton -style "iconAndTextVertical" -label "Mesh"
|
|
-width 100 -image1 "dynamicaCreateActiveMeshRB.xpm" -c ("dynamicaUI_createActiveMeshRB")
|
|
-ann "Create an active mesh rigid body"`;
|
|
|
|
setParent ..;
|
|
}
|
|
setParent ..;
|
|
}
|
|
|
|
frameLayout -collapsable true -label "Passive Rigid Bodies" -borderStyle "in";
|
|
{
|
|
rowLayout -nc 5;
|
|
{
|
|
string $createPassiveSphereRBBtn = `iconTextButton -style "iconAndTextVertical" -label "Sphere"
|
|
-width 100 -image1 "dynamicaCreatePassiveSphereRB.xpm" -c ("dynamicaUI_createPassiveSphereRB")
|
|
-ann "Create an passive sphere rigid body"`;
|
|
|
|
string $createPassiveBoxRBBtn = `iconTextButton -style "iconAndTextVertical" -label "Box"
|
|
-width 100 -image1 "dynamicaCreatePassiveBoxRB.xpm" -c ("dynamicaUI_createPassiveBoxRB")
|
|
-ann "Create an passive box rigid body"`;
|
|
|
|
string $createPassivePlaneRBBtn = `iconTextButton -style "iconAndTextVertical" -label "Plane"
|
|
-width 100 -image1 "dynamicaCreatePassivePlaneRB.xpm" -c ("dynamicaUI_createPassivePlaneRB")
|
|
-ann "Create an passive plane rigid body"`;
|
|
|
|
string $createPassiveHullRBBtn = `iconTextButton -style "iconAndTextVertical" -label "Hull"
|
|
-width 100 -image1 "dynamicaCreatePassiveHullRB.xpm" -c ("dynamicaUI_createPassiveHullRB")
|
|
-ann "Create an passive hull rigid body"`;
|
|
|
|
string $createPassiveMeshRBBtn = `iconTextButton -style "iconAndTextVertical" -label "Mesh"
|
|
-width 100 -image1 "dynamicaCreatePassiveMeshRB.xpm" -c ("dynamicaUI_createPassiveMeshRB")
|
|
-ann "Create an passive mesh rigid body"`;
|
|
|
|
setParent ..;
|
|
}
|
|
setParent ..;
|
|
}
|
|
|
|
|
|
frameLayout -collapsable true -label "Active Rigid Body Arrays" -borderStyle "in";
|
|
{
|
|
rowLayout -nc 5;
|
|
{
|
|
string $createActiveSphereRBArrayBtn = `iconTextButton -style "iconAndTextVertical" -label "Sphere"
|
|
-width 100 -image1 "dynamicaCreateActiveSphereRBArray.xpm" -c ("dynamicaUI_createActiveSphereRBArray")
|
|
-ann "Create an active sphere rigid body array"`;
|
|
|
|
string $createActiveBoxRBArrayBtn = `iconTextButton -style "iconAndTextVertical" -label "Box"
|
|
-width 100 -image1 "dynamicaCreateActiveBoxRBArray.xpm" -c ("dynamicaUI_createActiveBoxRBArray")
|
|
-ann "Create an active box rigid body array"`;
|
|
|
|
string $createActivePlaneRBArrayBtn = `iconTextButton -style "iconAndTextVertical" -label "Plane"
|
|
-width 100 -image1 "dynamicaCreateActivePlaneRBArray.xpm" -c ("dynamicaUI_createActivePlaneRBArray")
|
|
-ann "Create an active plane rigid body array"`;
|
|
|
|
string $createActiveHullRBArrayBtn = `iconTextButton -style "iconAndTextVertical" -label "Hull"
|
|
-width 100 -image1 "dynamicaCreateActiveHullRBArray.xpm" -c ("dynamicaUI_createActiveHullRBArray")
|
|
-ann "Create an active hull rigid body array"`;
|
|
|
|
string $createActiveMeshRBArrayBtn = `iconTextButton -style "iconAndTextVertical" -label "Mesh"
|
|
-width 100 -image1 "dynamicaCreateActiveMeshRBArray.xpm" -c ("dynamicaUI_createActiveMeshRBArray")
|
|
-ann "Create an active mesh rigid body array"`;
|
|
|
|
setParent ..;
|
|
}
|
|
setParent ..;
|
|
}
|
|
|
|
frameLayout -collapsable true -label "Passive Rigid Body Arrays" -borderStyle "in";
|
|
{
|
|
rowLayout -nc 5;
|
|
{
|
|
string $createPassiveSphereRBArrayBtn = `iconTextButton -style "iconAndTextVertical" -label "Sphere"
|
|
-width 100 -image1 "dynamicaCreatePassiveSphereRBArray.xpm" -c ("dynamicaUI_createPassiveSphereRBArray")
|
|
-ann "Create an passive sphere rigid body array"`;
|
|
|
|
string $createPassiveBoxRBArrayBtn = `iconTextButton -style "iconAndTextVertical" -label "Box"
|
|
-width 100 -image1 "dynamicaCreatePassiveBoxRBArray.xpm" -c ("dynamicaUI_createPassiveBoxRBArray")
|
|
-ann "Create an passive box rigid body array"`;
|
|
|
|
string $createPassivePlaneRBArrayBtn = `iconTextButton -style "iconAndTextVertical" -label "Plane"
|
|
-width 100 -image1 "dynamicaCreatePassivePlaneRBArray.xpm" -c ("dynamicaUI_createPassivePlaneRBArray")
|
|
-ann "Create an passive plane rigid body array"`;
|
|
|
|
string $createPassiveHullRBArrayBtn = `iconTextButton -style "iconAndTextVertical" -label "Hull"
|
|
-width 100 -image1 "dynamicaCreatePassiveHullRBArray.xpm" -c ("dynamicaUI_createPassiveHullRBArray")
|
|
-ann "Create an passive hull rigid body array"`;
|
|
|
|
string $createPassiveMeshRBArrayBtn = `iconTextButton -style "iconAndTextVertical" -label "Mesh"
|
|
-width 100 -image1 "dynamicaCreatePassiveMeshRBArray.xpm" -c ("dynamicaUI_createPassiveMeshRBArray")
|
|
-ann "Create an passive mesh rigid body array"`;
|
|
|
|
setParent ..;
|
|
}
|
|
setParent ..;
|
|
}
|
|
|
|
frameLayout -collapsable true -label "Constraints" -borderStyle "in";
|
|
{
|
|
rowLayout -nc 5;
|
|
{
|
|
string $createNailConstraintBtn = `iconTextButton -style "iconAndTextVertical" -label "Nail"
|
|
-width 100 -image1 "dynamicaCreateNailConstraint.xpm" -c ("dynamicaUI_createNailConstraint")
|
|
-ann "Create a nail constraint"`;
|
|
string $createHingeConstraintBtn = `iconTextButton -style "iconAndTextVertical" -label "Hinge"
|
|
-width 100 -image1 "dynamicaCreateHingeConstraint.xpm" -c ("dynamicaUI_createHingeConstraint")
|
|
-ann "Create a hinge constraint"`;
|
|
string $createSliderConstraintBtn = `iconTextButton -style "iconAndTextVertical" -label "Slider"
|
|
-width 100 -image1 "dynamicaCreateSliderConstraint.xpm" -c ("dynamicaUI_createSliderConstraint")
|
|
-ann "Create a slider constraint"`;
|
|
/* string $createConeTwistConstraintBtn = `iconTextButton -style "iconAndTextVertical" -label "ConeTwist"
|
|
-width 100 -image1 "dynamicaCreateConeTwistConstraint.xpm" -c ("dynamicaUI_createConeTwistConstraint")
|
|
-ann "Create a conetwist constraint"`;
|
|
*/ string $create6DofConstraintBtn = `iconTextButton -style "iconAndTextVertical" -label "6Dof"
|
|
-width 100 -image1 "dynamicaCreate6DofConstraint.xpm" -c ("dynamicaUI_create6DofConstraint")
|
|
-ann "Create a 6dof constraint"`;
|
|
|
|
|
|
|
|
setParent ..;
|
|
}
|
|
setParent ..;
|
|
}
|
|
|
|
setParent ..;
|
|
}
|
|
return $mainForm;
|
|
}
|
|
|
|
global proc dynamicaUI_STSolverTypeChanged()
|
|
{
|
|
//create dSolver node if necessary
|
|
dSolver;
|
|
|
|
global string $dynamicaUI_STsolverType;
|
|
int $type[] = `textScrollList -q -selectIndexedItem $dynamicaUI_STsolverType`;
|
|
$type[0] = $type[0] -1; //1-based
|
|
setAttr dSolver1.ssSolverType $type[0];
|
|
}
|
|
|
|
global proc dynamicaUI_STgravityChanged()
|
|
{
|
|
//create dSolver node if necessary
|
|
dSolver;
|
|
|
|
global string $dynamicaUI_STgravityX;
|
|
global string $dynamicaUI_STgravityY;
|
|
global string $dynamicaUI_STgravityZ;
|
|
|
|
float $gx = `floatField -query -value $dynamicaUI_STgravityX`;
|
|
float $gy = `floatField -query -value $dynamicaUI_STgravityY`;
|
|
float $gz = `floatField -query -value $dynamicaUI_STgravityZ`;
|
|
|
|
setAttr dSolver1.gravity -type double3 $gx $gy $gz;
|
|
|
|
}
|
|
|
|
global proc dynamicaUI_STenabledChanged()
|
|
{
|
|
//create dSolver node if necessary
|
|
dSolver;
|
|
|
|
global string $dynamicaUI_STenabled;
|
|
|
|
int $enabled = `checkBox -query -value $dynamicaUI_STenabled`;
|
|
|
|
setAttr dSolver1.enabled $enabled;
|
|
|
|
}
|
|
|
|
global proc dynamicaUI_STsplitImpulseChanged()
|
|
{
|
|
//create dSolver node if necessary
|
|
dSolver;
|
|
|
|
global string $dynamicaUI_STsplitImpulse;
|
|
|
|
int $enabled = `checkBox -query -value $dynamicaUI_STsplitImpulse`;
|
|
|
|
setAttr dSolver1.splitImpulse $enabled;
|
|
|
|
}
|
|
|
|
global proc dynamicaUI_STsubstepsChanged()
|
|
{
|
|
//create dSolver node if necessary
|
|
dSolver;
|
|
|
|
global string $dynamicaUI_STsubsteps;
|
|
|
|
int $substeps = `intField -query -value $dynamicaUI_STsubsteps`;
|
|
|
|
setAttr dSolver1.substeps $substeps;
|
|
|
|
}
|
|
|
|
proc dynamicaUI_createRigidBody(int $activebody, int $collisionShapeType)
|
|
{
|
|
float $mass = 1;
|
|
|
|
if($activebody == false)
|
|
{
|
|
$mass = 0;
|
|
}
|
|
|
|
string $selection[] = `ls -selection -dag -leaf -showType -type "geometry"`;
|
|
|
|
//create dSolver node if necessary
|
|
dSolver;
|
|
|
|
string $newBodies[];
|
|
int $makeCollisionShape;
|
|
|
|
//pick the selected object's transform only if we are creating a hull or a mesh
|
|
if($collisionShapeType == 0 || $collisionShapeType == 1) {
|
|
|
|
for($i = 0; $i < size($selection) / 2; $i++)
|
|
{
|
|
$makeCollisionShape = 1;
|
|
string $connectedCollisionShapes[] = `listConnections -s true -t dCollisionShape $selection[$i * 2]`;
|
|
if(size($connectedCollisionShapes) > 0)
|
|
{
|
|
$makeCollisionShape = 0;
|
|
}
|
|
string $shapeTransforms[] = `listRelatives -parent $selection[$i * 2]`;
|
|
if($makeCollisionShape)
|
|
{
|
|
string $rigidBodyNode = `dRigidBody`;
|
|
string $collisionShapeNode = `createNode dCollisionShape`;
|
|
connectAttr ($collisionShapeNode + ".outCollisionShape") ($rigidBodyNode + ".inCollisionShape");
|
|
string $rigidBodyTransforms[] = `listRelatives -parent $rigidBodyNode`;
|
|
|
|
if($selection[$i * 2 + 1] == "mesh") {
|
|
connectAttr ($selection[$i * 2] + ".message") ($collisionShapeNode + ".inShape");
|
|
hide $shapeTransforms[0];
|
|
}
|
|
setAttr ($rigidBodyNode + ".mass" ) $mass;
|
|
setAttr ($collisionShapeNode + ".type" ) $collisionShapeType;
|
|
|
|
float $pos[]= `getAttr ($shapeTransforms[0] + ".translate")`;
|
|
float $rot[]= `getAttr ($shapeTransforms[0] + ".rotate")`;
|
|
|
|
setAttr ($rigidBodyTransforms[0] + ".translate") -type double3 $pos[0] $pos[1] $pos[2];
|
|
setAttr ($rigidBodyNode + ".initialPosition") -type double3 $pos[0] $pos[1] $pos[2];
|
|
|
|
setAttr ($rigidBodyTransforms[0] + ".rotate") -type double3 $rot[0] $rot[1] $rot[2];
|
|
setAttr ($rigidBodyNode + ".initialRotation") -type double3 $rot[0] $rot[1] $rot[2];
|
|
|
|
$newBodies[$i] = $rigidBodyTransforms[0];
|
|
}
|
|
else
|
|
{
|
|
print("Warning : Object " + $shapeTransforms[0] + " already is a rigid body\n");
|
|
$newBodies[$i] = $shapeTransforms[0];
|
|
}
|
|
}
|
|
} else {
|
|
string $rigidBodyNode = `dRigidBody`;
|
|
string $collisionShapeNode = `createNode dCollisionShape`;
|
|
connectAttr ($collisionShapeNode + ".outCollisionShape") ($rigidBodyNode + ".inCollisionShape");
|
|
string $rigidBodyTransforms[] = `listRelatives -parent $rigidBodyNode`;
|
|
|
|
setAttr ($rigidBodyNode + ".mass" ) $mass;
|
|
setAttr ($collisionShapeNode + ".type" ) $collisionShapeType;
|
|
$newBodies[0] = $rigidBodyTransforms[0];
|
|
}
|
|
|
|
select -r $newBodies;
|
|
}
|
|
|
|
global proc dynamicaUI_createArrayUIdismissCB(string $button)
|
|
{
|
|
global string $dynamicaUI_createArrayUI_sizeCT;
|
|
global string $dynamicaUI_createArrayUI_offsetCT;
|
|
|
|
global int $dynamicaUI_createArrayUI_size[];
|
|
global float $dynamicaUI_createArrayUI_offset[];
|
|
|
|
$dynamicaUI_createArrayUI_size = `intFieldGrp -query -value $dynamicaUI_createArrayUI_sizeCT`;
|
|
$dynamicaUI_createArrayUI_offset = `floatFieldGrp -query -value $dynamicaUI_createArrayUI_offsetCT`;
|
|
layoutDialog -dismiss $button;
|
|
}
|
|
|
|
global proc dynamicaUI_createArrayUI()
|
|
{
|
|
global string $dynamicaUI_createArrayUI_sizeCT;
|
|
global string $dynamicaUI_createArrayUI_offsetCT;
|
|
|
|
// Get the dialog's formLayout.
|
|
string $form = `setParent -q`;
|
|
|
|
// layoutDialog's are not resizable, so hard code a size here,
|
|
// to make sure all UI elements are visible.
|
|
formLayout -e -width 350 $form;
|
|
|
|
string $b1 = `button -l "OK" -c "dynamicaUI_createArrayUIdismissCB(\"OK\")"`;
|
|
string $b2 = `button -l "Cancel"-c "dynamicaUI_createArrayUIdismissCB(\"Cancel\")"`;
|
|
|
|
$dynamicaUI_createArrayUI_sizeCT = `intFieldGrp -columnAlign 1 "left" -adj 1 -numberOfFields 3 -label "Array Size" -v1 1 -v2 1 -v3 1`;
|
|
$dynamicaUI_createArrayUI_offsetCT = `floatFieldGrp -columnAlign 1 "left" -adj 1 -numberOfFields 3 -label "Array Offset" -v1 2.0 -v2 2.0 -v3 2.0`;
|
|
|
|
formLayout -edit
|
|
-attachForm $dynamicaUI_createArrayUI_sizeCT "top" 5
|
|
-attachForm $dynamicaUI_createArrayUI_sizeCT "left" 5
|
|
-attachNone $dynamicaUI_createArrayUI_sizeCT "bottom"
|
|
-attachForm $dynamicaUI_createArrayUI_sizeCT "right" 5
|
|
|
|
-attachControl $dynamicaUI_createArrayUI_offsetCT "top" 5 $dynamicaUI_createArrayUI_sizeCT
|
|
-attachForm $dynamicaUI_createArrayUI_offsetCT "left" 5
|
|
-attachNone $dynamicaUI_createArrayUI_offsetCT "bottom"
|
|
-attachForm $dynamicaUI_createArrayUI_offsetCT "right" 5
|
|
|
|
-attachControl $b1 "top" 5 $dynamicaUI_createArrayUI_offsetCT
|
|
-attachForm $b1 "left" 5
|
|
-attachNone $b1 "bottom"
|
|
-attachPosition $b1 "right" 5 33
|
|
|
|
-attachControl $b2 "top" 5 $dynamicaUI_createArrayUI_offsetCT
|
|
-attachPosition $b2 "left" 5 33
|
|
-attachNone $b2 "bottom"
|
|
-attachPosition $b2 "right" 5 66
|
|
|
|
$form;
|
|
}
|
|
|
|
global proc dynamicaUI_createActiveRigidBody()
|
|
{
|
|
dynamicaUI_createRigidBody(true, 0);
|
|
}
|
|
|
|
global proc dynamicaUI_createPassiveRigidBody()
|
|
{
|
|
dynamicaUI_createRigidBody(false, 0);
|
|
}
|
|
|
|
global proc dynamicaUI_createActiveSphereRB()
|
|
{
|
|
dynamicaUI_createRigidBody(true, 5);
|
|
}
|
|
|
|
global proc dynamicaUI_createActiveBoxRB()
|
|
{
|
|
dynamicaUI_createRigidBody(true, 4);
|
|
}
|
|
|
|
global proc dynamicaUI_createActivePlaneRB()
|
|
{
|
|
dynamicaUI_createRigidBody(true, 6);
|
|
}
|
|
|
|
global proc dynamicaUI_createActiveHullRB()
|
|
{
|
|
dynamicaUI_createRigidBody(true, 0);
|
|
}
|
|
|
|
global proc dynamicaUI_createActiveMeshRB()
|
|
{
|
|
dynamicaUI_createRigidBody(true, 1);
|
|
}
|
|
|
|
global proc dynamicaUI_createPassiveSphereRB()
|
|
{
|
|
dynamicaUI_createRigidBody(false, 5);
|
|
}
|
|
|
|
global proc dynamicaUI_createPassiveBoxRB()
|
|
{
|
|
dynamicaUI_createRigidBody(false, 4);
|
|
}
|
|
|
|
global proc dynamicaUI_createPassivePlaneRB()
|
|
{
|
|
dynamicaUI_createRigidBody(false, 6);
|
|
}
|
|
|
|
global proc dynamicaUI_createPassiveHullRB()
|
|
{
|
|
dynamicaUI_createRigidBody(false, 0);
|
|
}
|
|
|
|
global proc dynamicaUI_createPassiveMeshRB()
|
|
{
|
|
dynamicaUI_createRigidBody(false, 1);
|
|
}
|
|
|
|
proc dynamicaUI_createRigidBodyArray(int $activebody, int $collisionShapeType)
|
|
{
|
|
float $mass = 1;
|
|
|
|
if ($activebody == false)
|
|
{
|
|
$mass = 0;
|
|
}
|
|
|
|
global int $dynamicaUI_createArrayUI_size[];
|
|
global float $dynamicaUI_createArrayUI_offset[];
|
|
|
|
if(`layoutDialog -title "Create Rigid Body Array" -ui "dynamicaUI_createArrayUI"` == "OK") {
|
|
string $selection[] = `ls -selection -dag -leaf -showType -type "geometry"`;
|
|
|
|
//create dSolver node if necessary
|
|
dSolver;
|
|
|
|
string $rigidBodyArrayNode = `dRigidBodyArray`;
|
|
string $collisionShapeNode = `createNode dCollisionShape`;
|
|
connectAttr ($collisionShapeNode + ".outCollisionShape") ($rigidBodyArrayNode + ".inCollisionShape");
|
|
string $rigidBodyTransforms[] = `listRelatives -parent $rigidBodyArrayNode`;
|
|
|
|
if(size($selection) != 0) {
|
|
string $shapeTransforms[] = `listRelatives -parent $selection[0]`;
|
|
if($selection[1] == "mesh") {
|
|
connectAttr ($selection[0] + ".message") ($collisionShapeNode + ".inShape");
|
|
hide $shapeTransforms[0];
|
|
}
|
|
}
|
|
|
|
setAttr ($rigidBodyArrayNode + ".mass" ) $mass;
|
|
setAttr ($collisionShapeNode + ".type" ) $collisionShapeType;
|
|
|
|
select -r $rigidBodyTransforms[0];
|
|
|
|
int $size[]= $dynamicaUI_createArrayUI_size;
|
|
float $off[]= $dynamicaUI_createArrayUI_offset;
|
|
float $x0[];
|
|
$x0[0] = -0.5 * $size[0] * $off[0];
|
|
$x0[1] = -0.5 * $size[1] * $off[1];
|
|
$x0[2] = -0.5 * $size[2] * $off[2];
|
|
setAttr ($rigidBodyArrayNode + ".numBodies") ($size[0] * $size[1] * $size[2]);
|
|
for($i = 0; $i < $size[0]; $i++) {
|
|
for($j = 0; $j < $size[1]; $j++) {
|
|
for($k = 0; $k < $size[2]; $k++) {
|
|
setAttr ($rigidBodyArrayNode + ".initialPosition[" + string($i + $size[0] * $j + $size[0] * $size[1] * $k) + "]") ($x0[0] + $i * $off[0]) ($x0[1] + $j * $off[1]) ($x0[2] + $k * $off[2]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
global proc dynamicaUI_createActiveSphereRBArray()
|
|
{
|
|
dynamicaUI_createRigidBodyArray(true, 5);
|
|
}
|
|
|
|
global proc dynamicaUI_createActiveBoxRBArray()
|
|
{
|
|
dynamicaUI_createRigidBodyArray(true, 4);
|
|
}
|
|
|
|
global proc dynamicaUI_createActivePlaneRBArray()
|
|
{
|
|
dynamicaUI_createRigidBodyArray(true, 6);
|
|
}
|
|
|
|
global proc dynamicaUI_createActiveHullRBArray()
|
|
{
|
|
dynamicaUI_createRigidBodyArray(true, 0);
|
|
}
|
|
|
|
global proc dynamicaUI_createActiveMeshRBArray()
|
|
{
|
|
dynamicaUI_createRigidBodyArray(true, 1);
|
|
}
|
|
|
|
global proc dynamicaUI_createPassiveSphereRBArray()
|
|
{
|
|
dynamicaUI_createRigidBodyArray(false, 5);
|
|
}
|
|
|
|
global proc dynamicaUI_createPassiveBoxRBArray()
|
|
{
|
|
dynamicaUI_createRigidBodyArray(false, 4);
|
|
}
|
|
|
|
global proc dynamicaUI_createPassivePlaneRBArray()
|
|
{
|
|
dynamicaUI_createRigidBodyArray(false, 6);
|
|
}
|
|
|
|
global proc dynamicaUI_createPassiveHullRBArray()
|
|
{
|
|
dynamicaUI_createRigidBodyArray(false, 0);
|
|
}
|
|
|
|
global proc dynamicaUI_createPassiveMeshRBArray()
|
|
{
|
|
dynamicaUI_createRigidBodyArray(false, 1);
|
|
}
|
|
|
|
|
|
global proc float[] dynamicaUI_worldToObj(float $pointW[], float $objToWorldMatrix[])
|
|
{
|
|
float $result[];
|
|
$result[0] = 0.0;
|
|
$result[1] = 0.0;
|
|
$result[2] = 0.0;
|
|
float $offs[];
|
|
if ( size($pointW) != 3 || size($objToWorldMatrix) != 16 )
|
|
{
|
|
warning("Point must be an array of 3 doubles and matrix must be an array of 16 doubles.");
|
|
return $result;
|
|
}
|
|
for($i = 0; $i < 3; $i++)
|
|
{
|
|
$offs[$i] = $pointW[$i] - $objToWorldMatrix[12 + $i];
|
|
}
|
|
for($i = 0; $i < 3; $i++)
|
|
{
|
|
for($j = 0; $j < 3; $j++)
|
|
{
|
|
$result[$i] += $objToWorldMatrix[$i * 4 + $j] * $offs[$j];
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
global proc dynamicaUI_createNailConstraint()
|
|
{
|
|
string $selection[] = `ls -selection -dag -leaf -showType -type "geometry"`;
|
|
//create dSolver node if necessary
|
|
dSolver;
|
|
// check selection in scene : one or two rigidBodies should be selected
|
|
int $selSize = size($selection);
|
|
int $selOK = (($selSize == 2) || ($selSize == 4));
|
|
for($i = 0; $i < $selSize/2; $i++)
|
|
{
|
|
if($selection[$i * 2 + 1] != "dRigidBody")
|
|
{
|
|
$selOK = 0;
|
|
}
|
|
}
|
|
if(!$selOK)
|
|
{
|
|
error("Select one or two bodies to create a nail constraint");
|
|
return;
|
|
}
|
|
// create nail constraint node
|
|
string $constraintNode = `dNailConstraint`;
|
|
string $constraintTransforms[] = `listRelatives -parent $constraintNode`;
|
|
string $newConstraintTransf = $constraintTransforms[0];
|
|
// connect to bodies
|
|
if($selSize == 2)
|
|
{
|
|
connectAttr ($selection[0] + ".message") ($constraintNode + ".inRigidBodyA");
|
|
string $rbTransform[] = `listRelatives -parent $selection[0]`;
|
|
float $posA[3] = `getAttr ($rbTransform[0] + ".translate")`;
|
|
float $iWorldA[16] = `getAttr ($rbTransform[0] + ".worldMatrix")`;
|
|
float $pivA[] = dynamicaUI_worldToObj($posA, $iWorldA);
|
|
setAttr ($constraintNode + ".pivotInA") -type float3 $pivA[0] $pivA[1] $pivA[2];
|
|
setAttr ($newConstraintTransf + ".translate") -type float3 $posA[0] $posA[1] $posA[2];
|
|
}
|
|
else
|
|
{
|
|
connectAttr ($selection[0] + ".message") ($constraintNode + ".inRigidBodyA");
|
|
connectAttr ($selection[2] + ".message") ($constraintNode + ".inRigidBodyB");
|
|
string $rbTransformA[] = `listRelatives -parent $selection[0]`;
|
|
string $rbTransformB[] = `listRelatives -parent $selection[2]`;
|
|
float $posA[] = `getAttr ($rbTransformA[0] + ".translate")`;
|
|
float $posB[] = `getAttr ($rbTransformB[2] + ".translate")`;
|
|
float $pivW[3];
|
|
for($k=0; $k < 3; $k++) $pivW[$k] = $posA[$k];
|
|
float $iWorldA[16] = `getAttr ($rbTransformA[0] + ".worldMatrix")`;
|
|
float $iWorldB[16] = `getAttr ($rbTransformB[0] + ".worldMatrix")`;
|
|
float $pivA[] = dynamicaUI_worldToObj($pivW, $iWorldA);
|
|
float $pivB[] = dynamicaUI_worldToObj($pivW, $iWorldB);
|
|
setAttr ($constraintNode + ".pivotInA") -type float3 $pivA[0] $pivA[1] $pivA[2];
|
|
setAttr ($constraintNode + ".pivotInB") -type float3 $pivB[0] $pivB[1] $pivB[2];
|
|
setAttr ($newConstraintTransf + ".translate") -type float3 $pivW[0] $pivW[1] $pivW[2];
|
|
}
|
|
select -r $newConstraintTransf;
|
|
}
|
|
|
|
global proc dynamicaUI_createHingeConstraint()
|
|
{
|
|
string $selection[] = `ls -selection -dag -leaf -showType -type "geometry"`;
|
|
//create dSolver node if necessary
|
|
dSolver;
|
|
// check selection in scene : one or two rigidBodies should be selected
|
|
int $selSize = size($selection);
|
|
int $selOK = (($selSize == 2) || ($selSize == 4));
|
|
for($i = 0; $i < $selSize/2; $i++)
|
|
{
|
|
if($selection[$i * 2 + 1] != "dRigidBody")
|
|
{
|
|
$selOK = 0;
|
|
}
|
|
}
|
|
if(!$selOK)
|
|
{
|
|
error("Select one or two bodies to create a hinge constraint");
|
|
return;
|
|
}
|
|
// create hinge constraint node
|
|
string $constraintNode = `dHingeConstraint`;
|
|
string $constraintTransforms[] = `listRelatives -parent $constraintNode`;
|
|
string $newConstraintTransf = $constraintTransforms[0];
|
|
// connect to bodies
|
|
if($selSize == 2)
|
|
{
|
|
connectAttr ($selection[0] + ".message") ($constraintNode + ".inRigidBodyA");
|
|
string $rbTransform[] = `listRelatives -parent $selection[0]`;
|
|
float $posA[3] = `getAttr ($rbTransform[0] + ".translate")`;
|
|
float $iWorldA[16] = `getAttr ($rbTransform[0] + ".worldMatrix")`;
|
|
float $pivA[] = dynamicaUI_worldToObj($posA, $iWorldA);
|
|
setAttr ($constraintNode + ".pivotInA") -type float3 $pivA[0] $pivA[1] $pivA[2];
|
|
setAttr ($newConstraintTransf + ".translate") -type float3 $posA[0] $posA[1] $posA[2];
|
|
}
|
|
else
|
|
{
|
|
connectAttr ($selection[0] + ".message") ($constraintNode + ".inRigidBodyA");
|
|
connectAttr ($selection[2] + ".message") ($constraintNode + ".inRigidBodyB");
|
|
string $rbTransformA[] = `listRelatives -parent $selection[0]`;
|
|
string $rbTransformB[] = `listRelatives -parent $selection[2]`;
|
|
float $posA[] = `getAttr ($rbTransformA[0] + ".translate")`;
|
|
float $posB[] = `getAttr ($rbTransformB[2] + ".translate")`;
|
|
float $pivW[3];
|
|
for($k=0; $k < 3; $k++) $pivW[$k] = $posA[$k];
|
|
float $iWorldA[16] = `getAttr ($rbTransformA[0] + ".worldMatrix")`;
|
|
float $iWorldB[16] = `getAttr ($rbTransformB[0] + ".worldMatrix")`;
|
|
float $pivA[] = dynamicaUI_worldToObj($pivW, $iWorldA);
|
|
float $pivB[] = dynamicaUI_worldToObj($pivW, $iWorldB);
|
|
setAttr ($constraintNode + ".pivotInA") -type float3 $pivA[0] $pivA[1] $pivA[2];
|
|
setAttr ($constraintNode + ".pivotInB") -type float3 $pivB[0] $pivB[1] $pivB[2];
|
|
setAttr ($newConstraintTransf + ".translate") -type float3 $pivW[0] $pivW[1] $pivW[2];
|
|
}
|
|
select -r $newConstraintTransf;
|
|
}
|
|
|
|
global proc dynamicaUI_createSliderConstraint()
|
|
{
|
|
string $selection[] = `ls -selection -dag -leaf -showType -type "geometry"`;
|
|
//create dSolver node if necessary
|
|
dSolver;
|
|
// check selection in scene : one or two rigidBodies should be selected
|
|
int $selSize = size($selection);
|
|
int $selOK = (($selSize == 2) || ($selSize == 4));
|
|
for($i = 0; $i < $selSize/2; $i++)
|
|
{
|
|
if($selection[$i * 2 + 1] != "dRigidBody")
|
|
{
|
|
$selOK = 0;
|
|
}
|
|
}
|
|
if(!$selOK)
|
|
{
|
|
error("Select one or two bodies to create a slider constraint");
|
|
return;
|
|
}
|
|
// create slider constraint node
|
|
string $constraintNode = `dSliderConstraint`;
|
|
string $constraintTransforms[] = `listRelatives -parent $constraintNode`;
|
|
string $newConstraintTransf = $constraintTransforms[0];
|
|
// connect to bodies
|
|
if($selSize == 2)
|
|
{
|
|
connectAttr ($selection[0] + ".message") ($constraintNode + ".inRigidBodyA");
|
|
string $rbTransform[] = `listRelatives -parent $selection[0]`;
|
|
float $posA[3] = `getAttr ($rbTransform[0] + ".translate")`;
|
|
float $iWorldA[16] = `getAttr ($rbTransform[0] + ".worldMatrix")`;
|
|
float $pivA[] = dynamicaUI_worldToObj($posA, $iWorldA);
|
|
setAttr ($constraintNode + ".pivotInA") -type float3 $pivA[0] $pivA[1] $pivA[2];
|
|
setAttr ($newConstraintTransf + ".translate") -type float3 $posA[0] $posA[1] $posA[2];
|
|
}
|
|
else
|
|
{
|
|
connectAttr ($selection[0] + ".message") ($constraintNode + ".inRigidBodyA");
|
|
connectAttr ($selection[2] + ".message") ($constraintNode + ".inRigidBodyB");
|
|
string $rbTransformA[] = `listRelatives -parent $selection[0]`;
|
|
string $rbTransformB[] = `listRelatives -parent $selection[2]`;
|
|
float $posA[] = `getAttr ($rbTransformA[0] + ".translate")`;
|
|
float $posB[] = `getAttr ($rbTransformB[2] + ".translate")`;
|
|
float $pivW[3];
|
|
for($k=0; $k < 3; $k++) $pivW[$k] = $posA[$k];
|
|
float $iWorldA[16] = `getAttr ($rbTransformA[0] + ".worldMatrix")`;
|
|
float $iWorldB[16] = `getAttr ($rbTransformB[0] + ".worldMatrix")`;
|
|
float $pivA[] = dynamicaUI_worldToObj($pivW, $iWorldA);
|
|
float $pivB[] = dynamicaUI_worldToObj($pivW, $iWorldB);
|
|
setAttr ($constraintNode + ".pivotInA") -type float3 $pivA[0] $pivA[1] $pivA[2];
|
|
setAttr ($constraintNode + ".pivotInB") -type float3 $pivB[0] $pivB[1] $pivB[2];
|
|
setAttr ($newConstraintTransf + ".translate") -type float3 $pivW[0] $pivW[1] $pivW[2];
|
|
}
|
|
select -r $newConstraintTransf;
|
|
}
|
|
|
|
global proc dynamicaUI_create6DofConstraint()
|
|
{
|
|
string $selection[] = `ls -selection -dag -leaf -showType -type "geometry"`;
|
|
//create dSolver node if necessary
|
|
dSolver;
|
|
// check selection in scene : one or two rigidBodies should be selected
|
|
int $selSize = size($selection);
|
|
int $selOK = (($selSize == 2) || ($selSize == 4));
|
|
for($i = 0; $i < $selSize/2; $i++)
|
|
{
|
|
if($selection[$i * 2 + 1] != "dRigidBody")
|
|
{
|
|
$selOK = 0;
|
|
}
|
|
}
|
|
if(!$selOK)
|
|
{
|
|
error("Select one or two bodies to create a slider constraint");
|
|
return;
|
|
}
|
|
// create slider constraint node
|
|
string $constraintNode = `dSixdofConstraint`;
|
|
string $constraintTransforms[] = `listRelatives -parent $constraintNode`;
|
|
string $newConstraintTransf = $constraintTransforms[0];
|
|
// connect to bodies
|
|
if($selSize == 2)
|
|
{
|
|
connectAttr ($selection[0] + ".message") ($constraintNode + ".inRigidBodyA");
|
|
string $rbTransform[] = `listRelatives -parent $selection[0]`;
|
|
float $posA[3] = `getAttr ($rbTransform[0] + ".translate")`;
|
|
float $iWorldA[16] = `getAttr ($rbTransform[0] + ".worldMatrix")`;
|
|
float $pivA[] = dynamicaUI_worldToObj($posA, $iWorldA);
|
|
setAttr ($constraintNode + ".pivotInA") -type float3 $pivA[0] $pivA[1] $pivA[2];
|
|
setAttr ($newConstraintTransf + ".translate") -type float3 $posA[0] $posA[1] $posA[2];
|
|
}
|
|
else
|
|
{
|
|
connectAttr ($selection[0] + ".message") ($constraintNode + ".inRigidBodyA");
|
|
connectAttr ($selection[2] + ".message") ($constraintNode + ".inRigidBodyB");
|
|
string $rbTransformA[] = `listRelatives -parent $selection[0]`;
|
|
string $rbTransformB[] = `listRelatives -parent $selection[2]`;
|
|
float $posA[] = `getAttr ($rbTransformA[0] + ".translate")`;
|
|
float $posB[] = `getAttr ($rbTransformB[2] + ".translate")`;
|
|
float $pivW[3];
|
|
for($k=0; $k < 3; $k++) $pivW[$k] = $posA[$k];
|
|
float $iWorldA[16] = `getAttr ($rbTransformA[0] + ".worldMatrix")`;
|
|
float $iWorldB[16] = `getAttr ($rbTransformB[0] + ".worldMatrix")`;
|
|
float $pivA[] = dynamicaUI_worldToObj($pivW, $iWorldA);
|
|
float $pivB[] = dynamicaUI_worldToObj($pivW, $iWorldB);
|
|
setAttr ($constraintNode + ".pivotInA") -type float3 $pivA[0] $pivA[1] $pivA[2];
|
|
setAttr ($constraintNode + ".pivotInB") -type float3 $pivB[0] $pivB[1] $pivB[2];
|
|
setAttr ($newConstraintTransf + ".translate") -type float3 $pivW[0] $pivW[1] $pivW[2];
|
|
}
|
|
select -r $newConstraintTransf;
|
|
}
|
|
|
|
|
|
global proc dyn_demo1()
|
|
{
|
|
dynamicaUI_createActiveSphereRBArray();
|
|
string $children[] = `listRelatives -shapes`;
|
|
setAttr ($children[0] + ".numBodies") 1000;
|
|
for($i = 0; $i < 10; $i++) {
|
|
for($j = 0; $j < 10; $j++) {
|
|
for($k = 0; $k < 10; $k++) {
|
|
setAttr ($children[0] + ".initialPosition[" + string($i + 10 * $j + 100 * $k) + "]") ($i * 2) (10 + $k * 2) ($j * 2);
|
|
}
|
|
}
|
|
}
|
|
}
|