diff --git a/Extras/MayaPlugin/Makefile b/Extras/MayaPlugin/Makefile index 46c80501c..13b2ebb74 100644 --- a/Extras/MayaPlugin/Makefile +++ b/Extras/MayaPlugin/Makefile @@ -5,7 +5,7 @@ MAYA=$(MAYA_LOCATION) ## Change this if you want to change the installation directory -MAYA_PLUG_IN_PATH=/tmp +MAYA_PLUG_IN_PATH=/usr/maya-plugins ## Change this if you want to change the name of the final plugin LIBRARY=mayaplugin.so @@ -31,14 +31,14 @@ BULLET_LIB=-L$(BULLET)/out/linux/optimize/libs -L$(BULLET)/src \ -lGIMPACT -lGIMPACTUtils -lbulletdynamics \ -lbulletmath -lbulletcollision -lbulletopenglsupport -GL_LIB=-lGL -lGLU -lglut -lGLEW +GL_LIB=-lGL -lGLU MAYA_INCLUDE=-I$(MAYA)/include MAYA_LIB=-L$(MAYA)/lib -lOpenMaya -lFoundation -lOpenMayaUI -lOpenMayaFX SOURCES = pluginMain.cpp rigidBodyNode.cpp rigidBodyArrayNode.cpp collisionShapeNode.cpp \ solver.cpp bt_solver.cpp dSolverNode.cpp dSolverCmd.cpp dRigidBodyCmd.cpp dRigidBodyArrayCmd.cpp \ - pdbIO.cpp + pdbIO.cpp drawUtils.cpp HEADERS = box_shape.h bt_sphere_shape.h dSolverNode.h rigid_body_impl.h \ box_shape_impl.h collision_shape.h mathUtils.h rigidBodyNode.h \ @@ -49,7 +49,7 @@ HEADERS = box_shape.h bt_sphere_shape.h dSolverNode.h bt_plane_shape.h dRigidBodyArrayCmd.h plane_shape_impl.h \ bt_rigid_body.h dRigidBodyCmd.h rigidBodyArrayNode.h \ bt_solver.h dSolverCmd.h rigid_body.h pdbIO.h \ - shared_ptr.h + shared_ptr.h drawUtils.h INCLUDE_FLAGS= $(GL_INCLUDE) $(BULLET_INCLUDE) $(MAYA_INCLUDE) diff --git a/Extras/MayaPlugin/bt_box_shape.h b/Extras/MayaPlugin/bt_box_shape.h index 661555528..8bd9f6088 100644 --- a/Extras/MayaPlugin/bt_box_shape.h +++ b/Extras/MayaPlugin/bt_box_shape.h @@ -26,6 +26,7 @@ Written by: Nicola Candussi #define DYN_BT_BOX_SHAPE_H #include "box_shape_impl.h" +#include "drawUtils.h" class bt_box_shape_t: public bt_collision_shape_t, public box_shape_impl_t { @@ -37,9 +38,9 @@ public: glScalef(2 * e.x(), 2 * e.y(), 2 * e.z()); if(draw_style & collision_shape_t::kDSSolid) { - glutSolidCube(1.0); + solid_cube(); } else { - glutWireCube(1.0); + wire_cube(); } glPopMatrix(); } diff --git a/Extras/MayaPlugin/bt_plane_shape.h b/Extras/MayaPlugin/bt_plane_shape.h index d198e21df..bc3aa58e6 100644 --- a/Extras/MayaPlugin/bt_plane_shape.h +++ b/Extras/MayaPlugin/bt_plane_shape.h @@ -26,6 +26,7 @@ Written by: Nicola Candussi #define DYN_BT_PLANE_SHAPE_H #include "plane_shape_impl.h" +#include "drawUtils.h" class bt_plane_shape_t: public bt_collision_shape_t, public plane_shape_impl_t { @@ -35,9 +36,9 @@ public: glPushMatrix(); glScalef(100.0, 0.001, 100.0); if(draw_style & collision_shape_t::kDSSolid) { - glutSolidCube(1.0); + solid_cube(); } else { - glutWireCube(1.0); + wire_cube(); } glPopMatrix(); } diff --git a/Extras/MayaPlugin/bt_sphere_shape.h b/Extras/MayaPlugin/bt_sphere_shape.h index 632713518..398c20ed3 100644 --- a/Extras/MayaPlugin/bt_sphere_shape.h +++ b/Extras/MayaPlugin/bt_sphere_shape.h @@ -25,22 +25,26 @@ Written by: Nicola Candussi #ifndef DYN_BT_SPHERE_SHAPE_H #define DYN_BT_SPHERE_SHAPE_H -#include +#include #include "sphere_shape_impl.h" #include "bt_collision_shape.h" #include "collision_shape.h" +#include "drawUtils.h" class bt_sphere_shape_t: public bt_collision_shape_t, public sphere_shape_impl_t { public: virtual void gl_draw(size_t draw_style) { btSphereShape *sphere_shape = static_cast(shape()); + glPushMatrix(); + glScalef(sphere_shape->getRadius(), sphere_shape->getRadius(), sphere_shape->getRadius()); if(draw_style & collision_shape_t::kDSSolid) { - glutSolidSphere(sphere_shape->getRadius(), 10, 10); + solid_sphere(); } else { - glutWireSphere(sphere_shape->getRadius(), 10, 10); + wire_sphere(); } + glPopMatrix(); } virtual void set_scale(vec3f const& s) { diff --git a/Extras/MayaPlugin/collisionShapeNode.cpp b/Extras/MayaPlugin/collisionShapeNode.cpp index bfd4ad7e7..6338f9e45 100644 --- a/Extras/MayaPlugin/collisionShapeNode.cpp +++ b/Extras/MayaPlugin/collisionShapeNode.cpp @@ -22,8 +22,6 @@ Written by: Nicola Candussi //collisionShapeNode.cpp -#include - #include #include #include diff --git a/Extras/MayaPlugin/dRigidBodyCmd.cpp b/Extras/MayaPlugin/dRigidBodyCmd.cpp index 8f9fd24b2..ac76d84bc 100644 --- a/Extras/MayaPlugin/dRigidBodyCmd.cpp +++ b/Extras/MayaPlugin/dRigidBodyCmd.cpp @@ -139,7 +139,7 @@ dRigidBodyCmd::redoIt() m_dagModifier->doIt(); } - MGlobal::select(parentObj, MGlobal::kReplaceList); + // MGlobal::select(parentObj, MGlobal::kReplaceList); setResult(MFnDependencyNode(dRigidBodyObj).name()); diff --git a/Extras/MayaPlugin/drawUtils.cpp b/Extras/MayaPlugin/drawUtils.cpp new file mode 100644 index 000000000..1b3f6c66d --- /dev/null +++ b/Extras/MayaPlugin/drawUtils.cpp @@ -0,0 +1,159 @@ +/* +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 +*/ + +//drawUtils.cpp + +#include +#include + +void wire_cube() +{ + static GLuint dlist = 0; + if(glIsList(dlist)) { + glCallList(dlist); + } else { + dlist = glGenLists(1); + glNewList(dlist, GL_COMPILE_AND_EXECUTE); + + glBegin(GL_LINE_STRIP); + glVertex3f(-0.5f, -0.5, 0.5); + glVertex3f(0.5f, -0.5, 0.5); + glVertex3f(0.5f, 0.5, 0.5); + glVertex3f(-0.5f, 0.5, 0.5); + glVertex3f(-0.5f, -0.5, 0.5); + glEnd(); + + glBegin(GL_LINE_STRIP); + glVertex3f(-0.5f, -0.5, -0.5); + glVertex3f(0.5f, -0.5, -0.5); + glVertex3f(0.5f, 0.5, -0.5); + glVertex3f(-0.5f, 0.5, -0.5); + glVertex3f(-0.5f, -0.5, -0.5); + glEnd(); + + glBegin(GL_LINES); + glVertex3f(-0.5f, -0.5f, 0.5f); + glVertex3f(-0.5f, -0.5f, -0.5f); + glVertex3f(0.5f, -0.5f, 0.5f); + glVertex3f(0.5f, -0.5f, -0.5f); + glVertex3f(0.5f, 0.5f, 0.5f); + glVertex3f(0.5f, 0.5f, -0.5f); + glVertex3f(-0.5f, 0.5f, 0.5f); + glVertex3f(-0.5f, 0.5f, -0.5f); + glEnd(); + + glEndList(); + } +} + +void solid_cube() +{ + static GLuint dlist = 0; + if(glIsList(dlist)) { + glCallList(dlist); + } else { + dlist = glGenLists(1); + glNewList(dlist, GL_COMPILE_AND_EXECUTE); + + glBegin(GL_QUADS); + glNormal3f(-1.0f, 0.0f, 0.0f); + glVertex3f(-0.5f, -0.5f, -0.5f); + glVertex3f(-0.5f, -0.5f, 0.5f); + glVertex3f(-0.5f, 0.5f, 0.5f); + glVertex3f(-0.5f, 0.5f, -0.5f); + + glNormal3f(0.0f, 1.0f, 0.0f); + glVertex3f(-0.5f, 0.5f, -0.5f); + glVertex3f(-0.5f, 0.5f, 0.5f); + glVertex3f(0.5f, 0.5f, 0.5f); + glVertex3f(0.5f, 0.5f, -0.5f); + + glNormal3f(1.0f, 0.0f, 0.0f); + glVertex3f(0.5f, 0.5f, -0.5f); + glVertex3f(0.5f, 0.5f, 0.5f); + glVertex3f(0.5f, -0.5f, 0.5f); + glVertex3f(0.5f, -0.5f, -0.5f); + + glNormal3f(0.0f, -1.0f, 0.0f); + glVertex3f(0.5f, -0.5f, -0.5f); + glVertex3f(0.5f, -0.5f, 0.5f); + glVertex3f(-0.5f, -0.5f, 0.5f); + glVertex3f(-0.5f, -0.5f, -0.5f); + + glNormal3f(1.0f, 0.0f, 0.0f); + glVertex3f(0.5f, 0.5f, -0.5f); + glVertex3f(0.5f, 0.5f, 0.5f); + glVertex3f(0.5f, -0.5f, 0.5f); + glVertex3f(0.5f, -0.5f, -0.5f); + + glNormal3f(0.0f, 0.0f, 1.0f); + glVertex3f(-0.5f, -0.5f, 0.5f); + glVertex3f(0.5f, -0.5f, 0.5f); + glVertex3f(0.5f, 0.5f, 0.5f); + glVertex3f(-0.5f, 0.5f, 0.5f); + + glNormal3f(0.0f, 0.0f, -1.0f); + glVertex3f(0.5f, -0.5f, -0.5f); + glVertex3f(-0.5f, -0.5f, -0.5f); + glVertex3f(-0.5f, 0.5f, -0.5f); + glVertex3f(0.5f, 0.5f, -0.5f); + glEnd(); + + glEndList(); + } +} + +void wire_sphere() +{ + static GLuint dlist = 0; + if(glIsList(dlist)) { + glCallList(dlist); + } else { + GLUquadricObj* quadric = gluNewQuadric(); + gluQuadricDrawStyle(quadric, GLU_LINE); + + dlist = glGenLists(1); + glNewList(dlist, GL_COMPILE_AND_EXECUTE); + gluSphere(quadric, 1.0, 10, 10); + glEndList(); + + gluDeleteQuadric(quadric); + } +} + +void solid_sphere() +{ + static GLuint dlist = 0; + if(glIsList(dlist)) { + glCallList(dlist); + } else { + GLUquadricObj* quadric = gluNewQuadric(); + gluQuadricDrawStyle(quadric, GLU_FILL); + + dlist = glGenLists(1); + glNewList(dlist, GL_COMPILE_AND_EXECUTE); + gluSphere(quadric, 1.0, 10, 10); + glEndList(); + + gluDeleteQuadric(quadric); + } +} diff --git a/Extras/MayaPlugin/drawUtils.h b/Extras/MayaPlugin/drawUtils.h new file mode 100644 index 000000000..5657019fc --- /dev/null +++ b/Extras/MayaPlugin/drawUtils.h @@ -0,0 +1,33 @@ +/* +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 +*/ + +//drawUtils.h + +#ifndef DYN_DRAW_UTILS_H +#define DYN_DRAW_UTILS_H + +void wire_cube(); +void solid_cube(); +void wire_sphere(); +void solid_sphere(); + +#endif diff --git a/Extras/MayaPlugin/pluginMain.cpp b/Extras/MayaPlugin/pluginMain.cpp index f56d44dea..659893554 100644 --- a/Extras/MayaPlugin/pluginMain.cpp +++ b/Extras/MayaPlugin/pluginMain.cpp @@ -21,8 +21,6 @@ Written by: Nicola Candussi */ //pluginMain.cpp - - #include #include #include diff --git a/Extras/MayaPlugin/rigidBodyArrayNode.cpp b/Extras/MayaPlugin/rigidBodyArrayNode.cpp index 9216945f5..20f935704 100644 --- a/Extras/MayaPlugin/rigidBodyArrayNode.cpp +++ b/Extras/MayaPlugin/rigidBodyArrayNode.cpp @@ -22,8 +22,6 @@ Written by: Nicola Candussi //rigidBodyArrayNode.cpp -//#include - #include #include #include diff --git a/Extras/MayaPlugin/rigidBodyNode.cpp b/Extras/MayaPlugin/rigidBodyNode.cpp index c16e77ba4..9104e5523 100644 --- a/Extras/MayaPlugin/rigidBodyNode.cpp +++ b/Extras/MayaPlugin/rigidBodyNode.cpp @@ -22,8 +22,6 @@ Written by: Nicola Candussi //rigidBodyNode.cpp -//#include - #include #include #include diff --git a/Extras/MayaPlugin/scripts/dynamicaUI.mel b/Extras/MayaPlugin/scripts/dynamicaUI.mel index 7aa07f350..0452f08d8 100644 --- a/Extras/MayaPlugin/scripts/dynamicaUI.mel +++ b/Extras/MayaPlugin/scripts/dynamicaUI.mel @@ -386,20 +386,24 @@ proc dynamicaUI_createRigidBody(int $active, int $collisionShapeType) //create dSolver node if necessary dSolver; - - string $rigidBodyNode = `dRigidBody`; - string $collisionShapeNode = `createNode dCollisionShape`; - connectAttr ($collisionShapeNode + ".outCollisionShape") ($rigidBodyNode + ".inCollisionShape"); - string $rigidBodyTransforms[] = `listRelatives -parent $rigidBodyNode`; - if(size($selection) != 0) { - string $shapeTransforms[] = `listRelatives -parent $selection[0]`; - if($selection[1] == "mesh") { - connectAttr ($selection[0] + ".message") ($collisionShapeNode + ".inShape"); - hide $shapeTransforms[0]; - } - //pick the selected object's transform only if we are creating a hull or a mesh - if($collisionShapeType == 0 || $collisionShapeType == 1) { + string $newBodies[]; + + //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++) { + + string $rigidBodyNode = `dRigidBody`; + string $collisionShapeNode = `createNode dCollisionShape`; + connectAttr ($collisionShapeNode + ".outCollisionShape") ($rigidBodyNode + ".inCollisionShape"); + string $rigidBodyTransforms[] = `listRelatives -parent $rigidBodyNode`; + + string $shapeTransforms[] = `listRelatives -parent $selection[$i * 2]`; + if($selection[$i * 2 + 1] == "mesh") { + connectAttr ($selection[$i * 2] + ".message") ($collisionShapeNode + ".inShape"); + hide $shapeTransforms[0]; + } float $pos[]= `getAttr ($shapeTransforms[0] + ".translate")`; float $rot[]= `getAttr ($shapeTransforms[0] + ".rotate")`; @@ -408,13 +412,25 @@ proc dynamicaUI_createRigidBody(int $active, 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 ($rigidBodyNode + ".active" ) $active; + setAttr ($collisionShapeNode + ".type" ) $collisionShapeType; + + $newBodies[$i] = $rigidBodyTransforms[0]; } + } else { + string $rigidBodyNode = `dRigidBody`; + string $collisionShapeNode = `createNode dCollisionShape`; + connectAttr ($collisionShapeNode + ".outCollisionShape") ($rigidBodyNode + ".inCollisionShape"); + string $rigidBodyTransforms[] = `listRelatives -parent $rigidBodyNode`; + + setAttr ($rigidBodyNode + ".active" ) $active; + setAttr ($collisionShapeNode + ".type" ) $collisionShapeType; + + $newBodies[0] = $rigidBodyTransforms[0]; } - setAttr ($rigidBodyNode + ".active" ) $active; - setAttr ($collisionShapeNode + ".type" ) $collisionShapeType; - - select -r $rigidBodyTransforms[0]; + select -r $newBodies; } global proc dynamicaUI_createArrayUIdismissCB(string $button)