diff --git a/dtool/src/parser-inc/NxPhysics.h b/dtool/src/parser-inc/NxPhysics.h index 711e92b4b8..e424507953 100644 --- a/dtool/src/parser-inc/NxPhysics.h +++ b/dtool/src/parser-inc/NxPhysics.h @@ -31,6 +31,7 @@ class NxCapsuleForceFieldShape; class NxCapsuleForceFieldShapeDesc; class NxCapsuleShape; class NxCapsuleShapeDesc; +class NxCCDSkeleton; class NxConvexMesh; class NxConvexMeshDesc; class NxConvexForceFieldShape; @@ -113,6 +114,7 @@ class NxConstraintDominance; class NxRemoteDebugger; class NxGroupsMask; class NxSceneStats2; +class NxSimpleTriangleMesh; class NxSoftBody; class NxSoftBodyDesc; diff --git a/dtool/src/parser-inc/btBulletDynamicsCommon.h b/dtool/src/parser-inc/btBulletDynamicsCommon.h index 4303a2777c..2251bb607f 100644 --- a/dtool/src/parser-inc/btBulletDynamicsCommon.h +++ b/dtool/src/parser-inc/btBulletDynamicsCommon.h @@ -46,6 +46,7 @@ class btHingeConstraint; class btHinge2Constraint; class btIDebugDraw; class btKinematicCharacterController; +class btManifoldArray; class btManifoldPoint; class btMatrix3x3; class btMotionState; diff --git a/panda/src/physx/p3physx_composite.cxx b/panda/src/physx/p3physx_composite.cxx index 8eb94d9972..c3ed5ec577 100644 --- a/panda/src/physx/p3physx_composite.cxx +++ b/panda/src/physx/p3physx_composite.cxx @@ -17,6 +17,7 @@ #include "physxCapsuleForceFieldShapeDesc.cxx" #include "physxCapsuleShape.cxx" #include "physxCapsuleShapeDesc.cxx" +#include "physxCcdSkeleton.cxx" #include "physxCloth.cxx" #include "physxClothDesc.cxx" #include "physxClothMesh.cxx" diff --git a/panda/src/physx/physxCcdSkeleton.I b/panda/src/physx/physxCcdSkeleton.I new file mode 100644 index 0000000000..5101729ee7 --- /dev/null +++ b/panda/src/physx/physxCcdSkeleton.I @@ -0,0 +1,59 @@ +// Filename: physxCcdSkeleton.I +// Created by: enn0x (13Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCcdSkeleton::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxCcdSkeleton:: +PhysxCcdSkeleton() : PhysxObject() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCcdSkeleton::Destructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PhysxCcdSkeleton:: +~PhysxCcdSkeleton() { + +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCcdSkeleton::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxCcdSkeleton:: +ls() const { + + ls(nout); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCcdSkeleton::ls +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void PhysxCcdSkeleton:: +ls(ostream &out, int indent_level) const { + + indent(out, indent_level) << get_type().get_name() + << " (at 0x" << this << ")\n"; +} + diff --git a/panda/src/physx/physxCcdSkeleton.cxx b/panda/src/physx/physxCcdSkeleton.cxx new file mode 100644 index 0000000000..fe33a8a2f7 --- /dev/null +++ b/panda/src/physx/physxCcdSkeleton.cxx @@ -0,0 +1,76 @@ +// Filename: physxCcdSkeleton.cxx +// Created by: enn0x (13Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "physxCcdSkeleton.h" +#include "physxMeshPool.h" + +TypeHandle PhysxCcdSkeleton::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCcdSkeleton::link +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxCcdSkeleton:: +link(NxCCDSkeleton *skeletonPtr) { + + // Link self + PhysxManager::get_global_ptr()->_ccd_skeletons.add(this); + _ptr = skeletonPtr; + _error_type = ET_ok; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCcdSkeleton::unlink +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxCcdSkeleton:: +unlink() { + + // Unlink self + _error_type = ET_released; + PhysxManager::get_global_ptr()->_ccd_skeletons.remove(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCcdSkeleton::release +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxCcdSkeleton:: +release() { + + nassertv(_error_type == ET_ok); + + unlink(); + NxGetPhysicsSDK()->releaseCCDSkeleton(*_ptr); + _ptr = NULL; + + //TODO PhysxMeshPool::release_ccd_skeleton(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxCcdSkeleton::get_reference_count +// Access: Published +// Description: Returns the reference count for shared meshes. +//////////////////////////////////////////////////////////////////// +unsigned int PhysxCcdSkeleton:: +get_reference_count() const { + + nassertr(_error_type == ET_ok, 0); + + return _ptr->getReferenceCount(); +} + diff --git a/panda/src/physx/physxCcdSkeleton.h b/panda/src/physx/physxCcdSkeleton.h new file mode 100644 index 0000000000..702610e413 --- /dev/null +++ b/panda/src/physx/physxCcdSkeleton.h @@ -0,0 +1,77 @@ +// Filename: physxCcdSkeleton.h +// Created by: enn0x (13Oct09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PHYSXCCDSKELETON_H +#define PHYSXCCDSKELETON_H + +#include "pandabase.h" + +#include "physxObject.h" +#include "physx_includes.h" + +//////////////////////////////////////////////////////////////////// +// Class : PhysxCcdSkeleton +// Description : A Convex Mesh. Internally represented as a list of +// convex polygons. The number of polygons is +// limited to 256. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAPHYSX PhysxCcdSkeleton : public PhysxObject { + +PUBLISHED: + unsigned int get_reference_count() const; + +//////////////////////////////////////////////////////////////////// +PUBLISHED: + void release(); + + INLINE void ls() const; + INLINE void ls(ostream &out, int indent_level=0) const; + +public: + INLINE PhysxCcdSkeleton(); + INLINE ~PhysxCcdSkeleton(); + + INLINE NxCCDSkeleton *ptr() const { return _ptr; }; + + void link(NxCCDSkeleton *meshPtr); + void unlink(); + +private: + NxCCDSkeleton *_ptr; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + PhysxObject::init_type(); + register_type(_type_handle, "PhysxCcdSkeleton", + PhysxObject::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "physxCcdSkeleton.I" + +#endif // PHYSXCCDSKELETON_H diff --git a/panda/src/physx/physxManager.cxx b/panda/src/physx/physxManager.cxx index 93d67f9cfb..002c685d3f 100644 --- a/panda/src/physx/physxManager.cxx +++ b/panda/src/physx/physxManager.cxx @@ -319,6 +319,52 @@ get_soft_body_mesh(unsigned int idx) { return (PhysxSoftBodyMesh *)_softbody_meshes[idx]; } +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::get_num_ccd_skeletons +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +unsigned int PhysxManager:: +get_num_ccd_skeletons() { + + return _sdk->getNbCCDSkeletons(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::create_ccd_skeleton +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxCcdSkeleton *PhysxManager:: +create_ccd_skeleton(PhysxTriangleMeshDesc &desc) { + + nassertr(desc.is_valid(), NULL); + nassertr(desc.get_desc().numVertices < 64, NULL); + + PhysxCcdSkeleton *skel = new PhysxCcdSkeleton(); + nassertr(skel, NULL); + + NxCCDSkeleton *skelPtr = _sdk->createCCDSkeleton(desc.get_desc()); + nassertr(skelPtr, NULL); + + skel->link(skelPtr); + + return skel; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxManager::get_ccd_skeleton +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +PhysxCcdSkeleton *PhysxManager:: +get_ccd_skeleton(unsigned int idx) { + + nassertr_always(idx < _sdk->getNbCCDSkeletons(), NULL); + + return (PhysxCcdSkeleton *)_ccd_skeletons[idx]; +} + //////////////////////////////////////////////////////////////////// // Function: PhysxManager::is_hardware_available // Access: Published diff --git a/panda/src/physx/physxManager.h b/panda/src/physx/physxManager.h index 31fb06f932..ca0cb2f289 100644 --- a/panda/src/physx/physxManager.h +++ b/panda/src/physx/physxManager.h @@ -32,6 +32,8 @@ class PhysxConvexMesh; class PhysxClothMesh; class PhysxSoftBodyMesh; class PhysxOutputStream; +class PhysxCcdSkeleton; +class PhysxTriangleMeshDesc; //////////////////////////////////////////////////////////////////// // Class : PhysxManager @@ -84,6 +86,11 @@ PUBLISHED: PhysxSoftBodyMesh *get_soft_body_mesh(unsigned int idx); MAKE_SEQ(get_soft_body_meshes, get_num_soft_body_meshes, get_soft_body_mesh); + unsigned int get_num_ccd_skeletons(); + PhysxCcdSkeleton *create_ccd_skeleton(PhysxTriangleMeshDesc &desc); + PhysxCcdSkeleton *get_ccd_skeleton(unsigned int idx); + MAKE_SEQ(get_ccd_skeletons, get_num_ccd_skeletons, get_ccd_skeleton); + INLINE void ls() const; INLINE void ls(ostream &out, int indent_level=0) const; @@ -96,6 +103,7 @@ public: PhysxObjectCollection _triangle_meshes; PhysxObjectCollection _cloth_meshes; PhysxObjectCollection _softbody_meshes; + PhysxObjectCollection _ccd_skeletons; INLINE static NxVec3 vec3_to_nxVec3(const LVector3f &v); INLINE static LVector3f nxVec3_to_vec3(const NxVec3 &v); diff --git a/panda/src/physx/physxShape.cxx b/panda/src/physx/physxShape.cxx index 4e60387a82..76d7bd1bf9 100644 --- a/panda/src/physx/physxShape.cxx +++ b/panda/src/physx/physxShape.cxx @@ -30,6 +30,7 @@ #include "physxCapsule.h" #include "physxRay.h" #include "physxRaycastHit.h" +#include "physxCcdSkeleton.h" TypeHandle PhysxShape::_type_handle; @@ -461,3 +462,30 @@ raycast(const PhysxRay &worldRay, bool firstHit, bool smoothNormal) const { return PhysxRaycastHit(hit); } +//////////////////////////////////////////////////////////////////// +// Function: PhysxShape::set_ccd_skeleton +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void PhysxShape:: +set_ccd_skeleton(PhysxCcdSkeleton *skel) { + + nassertv(_error_type == ET_ok); + + ptr()->setCCDSkeleton(skel->ptr()); + _skel = skel; +} + +//////////////////////////////////////////////////////////////////// +// Function: PhysxShape::get_ccd_skeleton +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +PhysxCcdSkeleton *PhysxShape:: +get_ccd_skeleton() const { + + nassertr(_error_type == ET_ok, NULL); + + return _skel; +} + diff --git a/panda/src/physx/physxShape.h b/panda/src/physx/physxShape.h index 1ca893ed58..222aaca193 100644 --- a/panda/src/physx/physxShape.h +++ b/panda/src/physx/physxShape.h @@ -32,6 +32,7 @@ class PhysxBox; class PhysxCapsule; class PhysxRay; class PhysxRaycastHit; +class PhysxCcdSkeleton; //////////////////////////////////////////////////////////////////// // Class : PhysxShape @@ -53,6 +54,7 @@ PUBLISHED: void set_material(const PhysxMaterial &material); void set_material_index(unsigned short idx); void set_groups_mask(const PhysxGroupsMask &mask); + void set_ccd_skeleton(PhysxCcdSkeleton *skel); const char *get_name() const; bool get_flag(const PhysxShapeFlag flag) const; @@ -63,6 +65,7 @@ PUBLISHED: unsigned short get_material_index() const; PhysxGroupsMask get_groups_mask() const; PhysxBounds3 get_world_bounds() const; + PhysxCcdSkeleton *get_ccd_skeleton() const; bool check_overlap_aabb(const PhysxBounds3 &world_bounds) const; bool check_overlap_capsule(const PhysxCapsule &world_capsule) const; @@ -86,6 +89,7 @@ protected: private: string _name; + PT(PhysxCcdSkeleton) _skel; //////////////////////////////////////////////////////////////////// public: