mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
Cloth meshes (descriptor, mesh, cooking, pool).
This commit is contained in:
parent
e3fdfaf312
commit
195a8d93ad
@ -30,6 +30,8 @@
|
||||
physxCapsuleForceFieldShapeDesc.I physxCapsuleForceFieldShapeDesc.h \
|
||||
physxCapsuleShape.I physxCapsuleShape.h \
|
||||
physxCapsuleShapeDesc.I physxCapsuleShapeDesc.h \
|
||||
physxClothMesh.I physxClothMesh.h \
|
||||
physxClothMeshDesc.I physxClothMeshDesc.h \
|
||||
physxConstraintDominance.I physxConstraintDominance.h \
|
||||
physxContactPair.I physxContactPair.h \
|
||||
physxContactPoint.I physxContactPoint.h \
|
||||
@ -146,6 +148,8 @@
|
||||
physxCapsuleForceFieldShapeDesc.cxx \
|
||||
physxCapsuleShape.cxx \
|
||||
physxCapsuleShapeDesc.cxx \
|
||||
physxClothMesh.cxx \
|
||||
physxClothMeshDesc.cxx \
|
||||
physxConstraintDominance.cxx \
|
||||
physxContactPair.cxx \
|
||||
physxContactPoint.cxx \
|
||||
@ -262,6 +266,8 @@
|
||||
physxCapsuleForceFieldShapeDesc.I physxCapsuleForceFieldShapeDesc.h \
|
||||
physxCapsuleShape.I physxCapsuleShape.h \
|
||||
physxCapsuleShapeDesc.I physxCapsuleShapeDesc.h \
|
||||
physxClothMesh.I physxClothMesh.h \
|
||||
physxClothMeshDesc.I physxClothMeshDesc.h \
|
||||
physxConstraintDominance.I physxConstraintDominance.h \
|
||||
physxContactPair.I physxContactPair.h \
|
||||
physxContactPoint.I physxContactPoint.h \
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "physxCapsuleController.h"
|
||||
#include "physxCapsuleForceFieldShape.h"
|
||||
#include "physxCapsuleShape.h"
|
||||
#include "physxClothMesh.h"
|
||||
#include "physxContactPair.h"
|
||||
#include "physxContactPoint.h"
|
||||
#include "physxController.h"
|
||||
@ -117,6 +118,7 @@ init_libphysx() {
|
||||
PhysxCapsuleController::init_type();
|
||||
PhysxCapsuleForceFieldShape::init_type();
|
||||
PhysxCapsuleShape::init_type();
|
||||
PhysxClothMesh::init_type();
|
||||
PhysxContactPair::init_type();
|
||||
PhysxContactPoint::init_type();
|
||||
PhysxController::init_type();
|
||||
|
59
panda/src/physx/physxClothMesh.I
Normal file
59
panda/src/physx/physxClothMesh.I
Normal file
@ -0,0 +1,59 @@
|
||||
// Filename: physxClothMesh.I
|
||||
// Created by: enn0x (28Mar10)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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: PhysxClothMesh::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PhysxClothMesh::
|
||||
PhysxClothMesh() : PhysxObject() {
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxClothMesh::Destructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PhysxClothMesh::
|
||||
~PhysxClothMesh() {
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxClothMesh::ls
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void PhysxClothMesh::
|
||||
ls() const {
|
||||
|
||||
ls(nout);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxClothMesh::ls
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void PhysxClothMesh::
|
||||
ls(ostream &out, int indent_level) const {
|
||||
|
||||
indent(out, indent_level) << get_type().get_name()
|
||||
<< " (at 0x" << this << ")\n";
|
||||
}
|
||||
|
76
panda/src/physx/physxClothMesh.cxx
Normal file
76
panda/src/physx/physxClothMesh.cxx
Normal file
@ -0,0 +1,76 @@
|
||||
// Filename: physxClothMesh.cxx
|
||||
// Created by: enn0x (28Mar10)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "physxClothMesh.h"
|
||||
#include "physxMeshPool.h"
|
||||
|
||||
TypeHandle PhysxClothMesh::_type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxClothMesh::link
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PhysxClothMesh::
|
||||
link(NxClothMesh *meshPtr) {
|
||||
|
||||
// Link self
|
||||
PhysxManager::get_global_ptr()->_cloth_meshes.add(this);
|
||||
_ptr = meshPtr;
|
||||
_error_type = ET_ok;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxClothMesh::unlink
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PhysxClothMesh::
|
||||
unlink() {
|
||||
|
||||
// Unlink self
|
||||
_error_type = ET_released;
|
||||
PhysxManager::get_global_ptr()->_cloth_meshes.remove(this);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxClothMesh::release
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PhysxClothMesh::
|
||||
release() {
|
||||
|
||||
nassertv(_error_type == ET_ok);
|
||||
|
||||
unlink();
|
||||
NxGetPhysicsSDK()->releaseClothMesh(*_ptr);
|
||||
_ptr = NULL;
|
||||
|
||||
PhysxMeshPool::release_cloth_mesh(this);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxClothMesh::get_reference_count
|
||||
// Access: Published
|
||||
// Description: Returns the reference count for shared meshes.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
unsigned int PhysxClothMesh::
|
||||
get_reference_count() const {
|
||||
|
||||
nassertr(_error_type == ET_ok, 0);
|
||||
|
||||
return _ptr->getReferenceCount();
|
||||
}
|
||||
|
75
panda/src/physx/physxClothMesh.h
Normal file
75
panda/src/physx/physxClothMesh.h
Normal file
@ -0,0 +1,75 @@
|
||||
// Filename: physxClothMesh.h
|
||||
// Created by: enn0x (28Mar10)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 PHYSXCLOTHMESH_H
|
||||
#define PHYSXCLOTHMESH_H
|
||||
|
||||
#include "pandabase.h"
|
||||
|
||||
#include "physxObject.h"
|
||||
#include "physx_includes.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : PhysxClothMesh
|
||||
// Description :
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDAPHYSX PhysxClothMesh : 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 PhysxClothMesh();
|
||||
INLINE ~PhysxClothMesh();
|
||||
|
||||
INLINE NxClothMesh *ptr() const { return _ptr; };
|
||||
|
||||
void link(NxClothMesh *meshPtr);
|
||||
void unlink();
|
||||
|
||||
private:
|
||||
NxClothMesh *_ptr;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
PhysxObject::init_type();
|
||||
register_type(_type_handle, "PhysxClothMesh",
|
||||
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 "physxClothMesh.I"
|
||||
|
||||
#endif // PHYSXCLOTHMESH_H
|
61
panda/src/physx/physxClothMeshDesc.I
Normal file
61
panda/src/physx/physxClothMeshDesc.I
Normal file
@ -0,0 +1,61 @@
|
||||
// Filename: physxClothMeshDesc.I
|
||||
// Created by: enn0x (28Mar10)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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: PhysxClothMeshDesc::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PhysxClothMeshDesc::
|
||||
PhysxClothMeshDesc() {
|
||||
|
||||
_desc.flags = 0;
|
||||
_desc.pointStrideBytes = 5*sizeof(NxReal);
|
||||
_desc.triangleStrideBytes = 3*sizeof(NxU32);
|
||||
_desc.points = NULL;
|
||||
_desc.triangles = NULL;
|
||||
|
||||
_points = NULL;
|
||||
_triangles = NULL;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxClothMeshDesc::Destructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PhysxClothMeshDesc::
|
||||
~PhysxClothMeshDesc() {
|
||||
|
||||
if (_points) {
|
||||
delete [] _points;
|
||||
}
|
||||
|
||||
if (_triangles) {
|
||||
delete [] _triangles;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxClothMeshDesc::is_valid
|
||||
// Access: Published
|
||||
// Description: Returns true if the descriptor is valid.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool PhysxClothMeshDesc::
|
||||
is_valid() const {
|
||||
|
||||
return _desc.isValid();
|
||||
}
|
||||
|
223
panda/src/physx/physxClothMeshDesc.cxx
Normal file
223
panda/src/physx/physxClothMeshDesc.cxx
Normal file
@ -0,0 +1,223 @@
|
||||
// Filename: physxClothMeshDesc.cxx
|
||||
// Created by: enn0x (28Mar10)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "physxClothMeshDesc.h"
|
||||
#include "physxManager.h"
|
||||
|
||||
#include "nodePathCollection.h"
|
||||
#include "geomNode.h"
|
||||
#include "geomVertexReader.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxClothMeshDesc::set_num_vertices
|
||||
// Access: Published
|
||||
// Description: Sets the number of vertices to be stored within
|
||||
// this triangle mesh. The function allocates memory
|
||||
// for the vertices, but it does not set any vertices.
|
||||
//
|
||||
// This method must be called before any calls to
|
||||
// set_vertex are done!
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PhysxClothMeshDesc::
|
||||
set_num_vertices(unsigned int numVertices) {
|
||||
|
||||
if (_desc.points) {
|
||||
delete [] _points;
|
||||
}
|
||||
|
||||
_points = new NxReal[5 * numVertices];
|
||||
|
||||
_desc.numVertices = numVertices;
|
||||
_desc.points = _points;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxClothMeshDesc::set_vertex
|
||||
// Access: Published
|
||||
// Description: Sets a single vertex. You have to call the function
|
||||
// set_num_vertices before you can call this function.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PhysxClothMeshDesc::
|
||||
set_vertex(unsigned int idx, const LPoint3f &vert, const LPoint2f &texcoord) {
|
||||
|
||||
nassertv(_desc.numVertices > idx);
|
||||
|
||||
idx = 5 * idx;
|
||||
_points[idx] = vert.get_x();
|
||||
_points[idx + 1] = vert.get_y();
|
||||
_points[idx + 2] = vert.get_z();
|
||||
_points[idx + 3] = texcoord.get_x();
|
||||
_points[idx + 4] = texcoord.get_y();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxClothMeshDesc::set_num_triangles
|
||||
// Access: Published
|
||||
// Description: Sets the number of triangles to be stored in this
|
||||
// triangle mesh.
|
||||
//
|
||||
// This method must be called before any calls to
|
||||
// set_triangle are done!
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PhysxClothMeshDesc::
|
||||
set_num_triangles(unsigned int numTriangles) {
|
||||
|
||||
if (_desc.triangles) {
|
||||
delete [] _triangles;
|
||||
}
|
||||
|
||||
_triangles = new NxU32[3 * numTriangles];
|
||||
|
||||
_desc.numTriangles = numTriangles;
|
||||
_desc.triangles = _triangles;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxClothMeshDesc::set_triangles
|
||||
// Access: Published
|
||||
// Description: Sets a single triangle, by providing the three
|
||||
// indices i1, i2, i3.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PhysxClothMeshDesc::
|
||||
set_triangle(unsigned int idx,
|
||||
unsigned int i1, unsigned int i2, unsigned int i3) {
|
||||
|
||||
nassertv(_desc.numTriangles > idx);
|
||||
|
||||
idx = 3 * idx;
|
||||
_triangles[idx] = i1;
|
||||
_triangles[idx + 1] = i2;
|
||||
_triangles[idx + 2] = i3;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxClothMeshDesc::get_desc
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
const NxClothMeshDesc &PhysxClothMeshDesc::
|
||||
get_desc() const {
|
||||
|
||||
return _desc;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxClothMeshDesc::set_from_node_path
|
||||
// Access: Published
|
||||
// Description: A convenience method to set the mesh data from
|
||||
// a NodePath in a single call. The method iterates
|
||||
// over the NodePath geoms and collects data for
|
||||
// the triangle mesh.
|
||||
//
|
||||
// Do not use the following function when using this
|
||||
// one:
|
||||
// - set_num_vertices
|
||||
// - set_vertex
|
||||
// - set_num_triangles
|
||||
// - set_triangle
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PhysxClothMeshDesc::
|
||||
set_from_node_path(const NodePath &np) {
|
||||
|
||||
pvector<LPoint3f> dataVertices;
|
||||
pvector<LPoint2f> dataTexcoords;
|
||||
pvector<int> dataIndices;
|
||||
|
||||
// Collect data from NodePath
|
||||
NodePathCollection npc = np.find_all_matches( "**/+GeomNode" );
|
||||
for (int i=0; i<npc.get_num_paths(); i++) {
|
||||
NodePath gnp = npc.get_path(i);
|
||||
GeomNode *gnode = DCAST(GeomNode, gnp.node());
|
||||
|
||||
for (int j=0; j<gnode->get_num_geoms(); j++) {
|
||||
CPT(Geom) geom = gnode->get_geom(j);
|
||||
CPT(GeomVertexData) vdata = geom->get_vertex_data();
|
||||
GeomVertexReader reader;
|
||||
|
||||
// Vertices
|
||||
reader = GeomVertexReader(vdata, InternalName::get_vertex());
|
||||
while (!reader.is_at_end()) {
|
||||
dataVertices.push_back(reader.get_data3f());
|
||||
}
|
||||
|
||||
// Texcoords
|
||||
reader = GeomVertexReader(vdata, InternalName::get_texcoord());
|
||||
while (!reader.is_at_end()) {
|
||||
dataTexcoords.push_back(reader.get_data2f());
|
||||
}
|
||||
|
||||
// Indices
|
||||
for (int k=0; k<geom->get_num_primitives(); k++) {
|
||||
|
||||
CPT(GeomPrimitive) prim = geom->get_primitive(k);
|
||||
prim = prim->decompose();
|
||||
|
||||
for (int l=0; l<prim->get_num_primitives(); l++) {
|
||||
|
||||
int s = prim->get_primitive_start(l);
|
||||
int e = prim->get_primitive_end(l);
|
||||
|
||||
for (int l=s; l<e; l++) {
|
||||
dataIndices.push_back(prim->get_vertex(l));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set descriptor members
|
||||
int i;
|
||||
|
||||
NxU32 numVertices = dataVertices.size();
|
||||
NxU32 numTriangles = dataIndices.size() / 3;
|
||||
|
||||
_points = new NxReal[5 * numVertices];
|
||||
_triangles = new NxU32[3 * numTriangles];
|
||||
|
||||
i = 0;
|
||||
pvector<LPoint3f>::const_iterator vit;
|
||||
for (vit=dataVertices.begin(); vit!=dataVertices.end(); vit++) {
|
||||
LPoint3f v = *vit;
|
||||
|
||||
_points[5*i] = v.get_x();
|
||||
_points[5*i+1] = v.get_y();
|
||||
_points[5*i+2] = v.get_z();
|
||||
i++;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
pvector<LPoint2f>::const_iterator tcit;
|
||||
for (tcit=dataTexcoords.begin(); tcit!=dataTexcoords.end(); tcit++) {
|
||||
LPoint2f tc = *tcit;
|
||||
|
||||
_points[5*i+3] = tc.get_x();
|
||||
_points[5*i+4] = tc.get_y();
|
||||
i++;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
pvector<int>::const_iterator iit;
|
||||
for(iit=dataIndices.begin(); iit!=dataIndices.end(); iit++) {
|
||||
NxU32 idx = *iit;
|
||||
|
||||
_triangles[i] = idx;
|
||||
i++;
|
||||
}
|
||||
|
||||
_desc.numVertices = numVertices;
|
||||
_desc.points = _points;
|
||||
_desc.numTriangles = numTriangles;
|
||||
_desc.triangles = _triangles;
|
||||
}
|
||||
|
57
panda/src/physx/physxClothMeshDesc.h
Normal file
57
panda/src/physx/physxClothMeshDesc.h
Normal file
@ -0,0 +1,57 @@
|
||||
// Filename: physxClothMeshDesc.h
|
||||
// Created by: enn0x (28Mar10)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 PHYSXCLOTHMESHDESC_H
|
||||
#define PHYSXCLOTHMESHDESC_H
|
||||
|
||||
#include "pandabase.h"
|
||||
#include "lpoint3.h"
|
||||
#include "lpoint2.h"
|
||||
#include "nodePath.h"
|
||||
|
||||
#include "physx_includes.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : PhysxClothMeshDesc
|
||||
// Description :
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDAPHYSX PhysxClothMeshDesc {
|
||||
|
||||
PUBLISHED:
|
||||
INLINE PhysxClothMeshDesc();
|
||||
INLINE ~PhysxClothMeshDesc();
|
||||
|
||||
INLINE bool is_valid() const;
|
||||
|
||||
void set_num_vertices(unsigned int n);
|
||||
void set_vertex(unsigned int idx, const LPoint3f &vert, const LPoint2f &texcoord);
|
||||
|
||||
void set_num_triangles(unsigned int n);
|
||||
void set_triangle(unsigned int idx,
|
||||
unsigned int i1, unsigned int i2, unsigned int i3);
|
||||
|
||||
void set_from_node_path(const NodePath &np);
|
||||
|
||||
public:
|
||||
const NxClothMeshDesc &get_desc() const;
|
||||
|
||||
private:
|
||||
NxReal *_points;
|
||||
NxU32 *_triangles;
|
||||
NxClothMeshDesc _desc;
|
||||
};
|
||||
|
||||
#include "physxClothMeshDesc.I"
|
||||
|
||||
#endif // PHYSXCLOTHMESHDESC_H
|
@ -17,6 +17,8 @@
|
||||
#include "physxConvexMeshDesc.h"
|
||||
#include "physxTriangleMesh.h"
|
||||
#include "physxTriangleMeshDesc.h"
|
||||
#include "physxClothMesh.h"
|
||||
#include "physxClothMeshDesc.h"
|
||||
#include "physxFileStream.h"
|
||||
#include "physxMemoryReadBuffer.h"
|
||||
#include "physxMemoryWriteBuffer.h"
|
||||
@ -83,6 +85,22 @@ cook_triangle_mesh(const PhysxTriangleMeshDesc &meshDesc, const Filename &filena
|
||||
return _cooking->NxCookTriangleMesh(meshDesc.get_desc(), stream);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxKitchen::cook_cloth_mesh
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool PhysxKitchen::
|
||||
cook_cloth_mesh(const PhysxClothMeshDesc &meshDesc, const Filename &filename) {
|
||||
|
||||
nassertr_always(!filename.empty(), false);
|
||||
nassertr_always(filename.touch(), false);
|
||||
nassertr_always(meshDesc.is_valid(), false);
|
||||
|
||||
PhysxFileStream stream = PhysxFileStream(filename, false);
|
||||
return _cooking->NxCookClothMesh(meshDesc.get_desc(), stream);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxKitchen::cook_convex_mesh
|
||||
// Access: Published
|
||||
@ -139,3 +157,31 @@ cook_triangle_mesh(const PhysxTriangleMeshDesc &meshDesc) {
|
||||
return mesh;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxKitchen::cook_cloth_mesh
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PhysxClothMesh *PhysxKitchen::
|
||||
cook_cloth_mesh(const PhysxClothMeshDesc &meshDesc) {
|
||||
|
||||
nassertr_always(meshDesc.is_valid(), false);
|
||||
|
||||
PhysxMemoryWriteBuffer buffer;
|
||||
bool status = _cooking->NxCookClothMesh(meshDesc.get_desc(), buffer);
|
||||
nassertr(status, NULL);
|
||||
|
||||
NxPhysicsSDK *sdk = NxGetPhysicsSDK();
|
||||
nassertr(sdk, NULL);
|
||||
|
||||
PhysxClothMesh *mesh = new PhysxClothMesh();
|
||||
nassertr(mesh, NULL);
|
||||
|
||||
NxClothMesh *meshPtr = sdk->createClothMesh(PhysxMemoryReadBuffer(buffer.data));
|
||||
nassertr(meshPtr, NULL);
|
||||
|
||||
mesh->link(meshPtr);
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,8 @@ class PhysxConvexMesh;
|
||||
class PhysxConvexMeshDesc;
|
||||
class PhysxTriangleMesh;
|
||||
class PhysxTriangleMeshDesc;
|
||||
class PhysxClothMesh;
|
||||
class PhysxClothMeshDesc;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : PhysxKitchen
|
||||
@ -39,9 +41,11 @@ PUBLISHED:
|
||||
|
||||
bool cook_convex_mesh(const PhysxConvexMeshDesc &meshDesc, const Filename &filename);
|
||||
bool cook_triangle_mesh(const PhysxTriangleMeshDesc &meshDesc, const Filename &filename);
|
||||
bool cook_cloth_mesh(const PhysxClothMeshDesc &meshDesc, const Filename &filename);
|
||||
|
||||
PhysxConvexMesh *cook_convex_mesh(const PhysxConvexMeshDesc &meshDesc);
|
||||
PhysxTriangleMesh *cook_triangle_mesh(const PhysxTriangleMeshDesc &meshDesc);
|
||||
PhysxClothMesh *cook_cloth_mesh(const PhysxClothMeshDesc &meshDesc);
|
||||
|
||||
private:
|
||||
NxCookingInterface *_cooking;
|
||||
|
@ -271,6 +271,30 @@ get_triangle_mesh(unsigned int idx) {
|
||||
return (PhysxTriangleMesh *)_triangle_meshes[idx];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxManager::get_num_cloth_meshes
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
unsigned int PhysxManager::
|
||||
get_num_cloth_meshes() {
|
||||
|
||||
return _sdk->getNbClothMeshes();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxManager::get_cloth_mesh
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PhysxClothMesh *PhysxManager::
|
||||
get_cloth_mesh(unsigned int idx) {
|
||||
|
||||
nassertr_always(idx < _sdk->getNbClothMeshes(), NULL);
|
||||
|
||||
return (PhysxClothMesh *)_cloth_meshes[idx];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxManager::is_hardware_available
|
||||
// Access: Published
|
||||
|
@ -71,6 +71,10 @@ PUBLISHED:
|
||||
PhysxTriangleMesh *get_triangle_mesh(unsigned int idx);
|
||||
MAKE_SEQ(get_triangle_meshes, get_num_triangle_meshes, get_triangle_mesh);
|
||||
|
||||
unsigned int get_num_cloth_meshes();
|
||||
PhysxClothMesh *get_cloth_mesh(unsigned int idx);
|
||||
MAKE_SEQ(get_cloth_meshes, get_num_cloth_meshes, get_cloth_mesh);
|
||||
|
||||
INLINE void ls() const;
|
||||
INLINE void ls(ostream &out, int indent_level=0) const;
|
||||
|
||||
@ -81,6 +85,7 @@ public:
|
||||
PhysxObjectCollection<PhysxHeightField> _heightfields;
|
||||
PhysxObjectCollection<PhysxConvexMesh> _convex_meshes;
|
||||
PhysxObjectCollection<PhysxTriangleMesh> _triangle_meshes;
|
||||
PhysxObjectCollection<PhysxClothMesh> _cloth_meshes;
|
||||
|
||||
INLINE static NxVec3 vec3_to_nxVec3(const LVector3f &v);
|
||||
INLINE static LVector3f nxVec3_to_vec3(const NxVec3 &v);
|
||||
|
@ -15,12 +15,13 @@
|
||||
#include "physxMeshPool.h"
|
||||
#include "physxConvexMesh.h"
|
||||
#include "physxTriangleMesh.h"
|
||||
#include "physxClothMesh.h"
|
||||
#include "physxFileStream.h"
|
||||
#include "virtualFileSystem.h"
|
||||
|
||||
PhysxMeshPool::ConvexMeshes PhysxMeshPool::_convex_meshes;
|
||||
PhysxMeshPool::TriangleMeshes PhysxMeshPool::_triangle_meshes;
|
||||
//PhysxMeshPool::ClothMeshes PhysxMeshPool::_cloth_meshes;
|
||||
PhysxMeshPool::ClothMeshes PhysxMeshPool::_cloth_meshes;
|
||||
//PhysxMeshPool::SoftbodyMeshes PhysxMeshPool::_softbody_meshes;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -122,6 +123,45 @@ load_triangle_mesh(const Filename &fn) {
|
||||
return mesh;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxMeshPool::load_cloth_mesh
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PhysxClothMesh *PhysxMeshPool::
|
||||
load_cloth_mesh(const Filename &fn) {
|
||||
|
||||
if (!check_filename(fn)) return NULL;
|
||||
|
||||
PhysxClothMesh *mesh;
|
||||
|
||||
ClothMeshes::iterator it = _cloth_meshes.find(fn);
|
||||
if (it == _cloth_meshes.end()) {
|
||||
// Not found; load mesh.
|
||||
NxClothMesh *meshPtr;
|
||||
PhysxFileStream stream = PhysxFileStream(fn, true);
|
||||
|
||||
mesh = new PhysxClothMesh();
|
||||
nassertr_always(mesh, NULL);
|
||||
|
||||
NxPhysicsSDK *sdk = NxGetPhysicsSDK();
|
||||
nassertr_always(sdk, NULL);
|
||||
|
||||
meshPtr = sdk->createClothMesh(stream);
|
||||
nassertr_always(meshPtr, NULL);
|
||||
|
||||
mesh->link(meshPtr);
|
||||
|
||||
_cloth_meshes.insert(ClothMeshes::value_type(fn, mesh));
|
||||
}
|
||||
else {
|
||||
// Found; return previously loaded mesh.
|
||||
mesh = (*it).second;
|
||||
}
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxMeshPool::release_convex_mesh
|
||||
// Access: Published
|
||||
@ -161,13 +201,22 @@ release_triangle_mesh(PhysxTriangleMesh *mesh) {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxMeshPool::list_content
|
||||
// Function: PhysxMeshPool::release_cloth_mesh
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PhysxMeshPool::
|
||||
list_contents() {
|
||||
list_contents( nout );
|
||||
bool PhysxMeshPool::
|
||||
release_cloth_mesh(PhysxClothMesh *mesh) {
|
||||
|
||||
ClothMeshes::iterator it;
|
||||
for (it=_cloth_meshes.begin(); it != _cloth_meshes.end(); ++it) {
|
||||
if (mesh == (*it).second) {
|
||||
_cloth_meshes.erase(it);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -176,7 +225,17 @@ list_contents() {
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PhysxMeshPool::
|
||||
list_contents( ostream &out ) {
|
||||
list_contents() {
|
||||
list_contents(nout);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PhysxMeshPool::list_content
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PhysxMeshPool::
|
||||
list_contents(ostream &out) {
|
||||
|
||||
out << "PhysX mesh pool contents:\n";
|
||||
|
||||
@ -206,6 +265,19 @@ list_contents( ostream &out ) {
|
||||
}
|
||||
}
|
||||
|
||||
// Cloth meshes
|
||||
{
|
||||
ClothMeshes::const_iterator it;
|
||||
for (it=_cloth_meshes.begin(); it != _cloth_meshes.end(); ++it) {
|
||||
Filename fn = (*it).first;
|
||||
PhysxClothMesh *mesh = (*it).second;
|
||||
|
||||
out << " " << fn.get_fullpath()
|
||||
<< " (cloth mesh, " << mesh->ptr()->getReferenceCount()
|
||||
<< " references)\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Summary
|
||||
NxPhysicsSDK *sdk = NxGetPhysicsSDK();
|
||||
|
||||
@ -214,5 +286,8 @@ list_contents( ostream &out ) {
|
||||
|
||||
out << " Total number of triangle meshes: " << sdk->getNbTriangleMeshes()
|
||||
<< " created, " << _triangle_meshes.size() << " registred\n";
|
||||
|
||||
out << " Total number of cloth meshes: " << sdk->getNbClothMeshes()
|
||||
<< " created, " << _cloth_meshes.size() << " registred\n";
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
class PhysxConvexMesh;
|
||||
class PhysxTriangleMesh;
|
||||
class PhysxClothMesh;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : PhysxMeshPool
|
||||
@ -42,9 +43,13 @@ PUBLISHED:
|
||||
|
||||
static PhysxConvexMesh *load_convex_mesh(const Filename &filename);
|
||||
static PhysxTriangleMesh *load_triangle_mesh(const Filename &filename);
|
||||
static PhysxClothMesh *load_cloth_mesh(const Filename &filename);
|
||||
//static PhysxSoftBodyMesh *load_softbody_mesh(const Filename &filename);
|
||||
|
||||
static bool release_convex_mesh(PhysxConvexMesh *mesh);
|
||||
static bool release_triangle_mesh(PhysxTriangleMesh *mesh);
|
||||
static bool release_cloth_mesh(PhysxClothMesh *mesh);
|
||||
//static bool release_softbody_mesh(PhysxSoftBodyMesh *mesh);
|
||||
|
||||
static void list_contents();
|
||||
static void list_contents(ostream &out);
|
||||
@ -54,12 +59,12 @@ private:
|
||||
|
||||
typedef pmap<Filename, PT(PhysxConvexMesh)> ConvexMeshes;
|
||||
typedef pmap<Filename, PT(PhysxTriangleMesh)> TriangleMeshes;
|
||||
//typedef pmap<Filename, PT(PhysxClothMesh)> ClothMeshes;
|
||||
typedef pmap<Filename, PT(PhysxClothMesh)> ClothMeshes;
|
||||
//typedef pmap<Filename, PT(PhysxSoftBodyMesh)> SoftbodyMeshes;
|
||||
|
||||
static ConvexMeshes _convex_meshes;
|
||||
static TriangleMeshes _triangle_meshes;
|
||||
//static ClothMeshes _cloth_meshes;
|
||||
static ClothMeshes _cloth_meshes;
|
||||
//static SoftbodyMeshes _softbody_meshes;
|
||||
};
|
||||
|
||||
|
@ -108,11 +108,10 @@
|
||||
#include "physxUtilLib.cxx"
|
||||
#include "physxVehicle.cxx"
|
||||
#include "physxVehicleDesc.cxx"
|
||||
//#include "physxVehicleGears.cxx"
|
||||
//#include "physxVehicleGearsDesc.cxx"
|
||||
//#include "physxVehicleMotor.cxx"
|
||||
//#include "physxVehicleMotorDesc.cxx"
|
||||
#include "physxWheel.cxx"
|
||||
#include "physxWheelDesc.cxx"
|
||||
#include "physxWheelShape.cxx"
|
||||
#include "physxWheelShapeDesc.cxx"
|
||||
|
||||
#include "physxClothMesh.cxx"
|
||||
#include "physxClothMeshDesc.cxx"
|
||||
|
Loading…
x
Reference in New Issue
Block a user