From af754373b2231652a7df69ec4b4d98467a8c7569 Mon Sep 17 00:00:00 2001 From: rponom Date: Wed, 3 Mar 2010 20:50:38 +0000 Subject: [PATCH] Dynamica Maya plugin changes to take into account scale and pivot point offset when converting existing objects to convex hull or mesh One more method added to set spring equilibrium point directly for btGeneric6DofSpringConstraint --- Extras/MayaPlugin/scripts/dynamicaUI.mel | 16 +++++++++++++++- .../btGeneric6DofSpringConstraint.cpp | 5 +++++ .../btGeneric6DofSpringConstraint.h | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Extras/MayaPlugin/scripts/dynamicaUI.mel b/Extras/MayaPlugin/scripts/dynamicaUI.mel index 59024b58b..71ea447fa 100644 --- a/Extras/MayaPlugin/scripts/dynamicaUI.mel +++ b/Extras/MayaPlugin/scripts/dynamicaUI.mel @@ -458,8 +458,19 @@ proc dynamicaUI_createRigidBody(int $activebody, int $collisionShapeType) setAttr ($rigidBodyNode + ".mass" ) $mass; setAttr ($collisionShapeNode + ".type" ) $collisionShapeType; - float $pos[]= `getAttr ($shapeTransforms[0] + ".translate")`; float $rot[]= `getAttr ($shapeTransforms[0] + ".rotate")`; + float $wmatr[]= `getAttr ($shapeTransforms[0] + ".worldMatrix")`; + // float $pos[]= `getAttr ($shapeTransforms[0] + ".translate")`; + // We need to take into account offset of the pivot point + // so get the final translation directly from world matrix + // also get existing scale + // note that this may not work if scaling coordinate system differs from object's coordinate system + // Bullet does not support that yet + float $pos[]; + $pos[0] = $wmatr[12]; + $pos[1] = $wmatr[13]; + $pos[2] = $wmatr[14]; + float $scale[] = `getAttr ($shapeTransforms[0] + ".scale")`; setAttr ($rigidBodyTransforms[0] + ".translate") -type double3 $pos[0] $pos[1] $pos[2]; setAttr ($rigidBodyNode + ".initialPosition") -type double3 $pos[0] $pos[1] $pos[2]; @@ -467,6 +478,9 @@ proc dynamicaUI_createRigidBody(int $activebody, int $collisionShapeType) setAttr ($rigidBodyTransforms[0] + ".rotate") -type double3 $rot[0] $rot[1] $rot[2]; setAttr ($rigidBodyNode + ".initialRotation") -type double3 $rot[0] $rot[1] $rot[2]; + setAttr ($rigidBodyTransforms[0] + ".scale") -type double3 $scale[0] $scale[1] $scale[2]; + setAttr ($collisionShapeNode + ".scale" ) -type double3 $scale[0] $scale[1] $scale[2]; + $newBodies[$i] = $rigidBodyTransforms[0]; } else diff --git a/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.cpp b/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.cpp index bacd19d80..af74db4c1 100644 --- a/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.cpp +++ b/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.cpp @@ -92,6 +92,11 @@ void btGeneric6DofSpringConstraint::setEquilibriumPoint(int index) } } +void btGeneric6DofSpringConstraint::setEquilibriumPoint(int index, btScalar val) +{ + btAssert((index >= 0) && (index < 6)); + m_equilibriumPoint[index] = val; +} void btGeneric6DofSpringConstraint::internalUpdateSprings(btConstraintInfo2* info) diff --git a/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.h b/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.h index b084c7e8d..4e723179c 100644 --- a/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.h +++ b/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.h @@ -47,6 +47,7 @@ public: void setDamping(int index, btScalar damping); void setEquilibriumPoint(); // set the current constraint position/orientation as an equilibrium point for all DOF void setEquilibriumPoint(int index); // set the current constraint position/orientation as an equilibrium point for given DOF + void setEquilibriumPoint(int index, btScalar val); virtual void getInfo2 (btConstraintInfo2* info); };