Panda3D
Loading...
Searching...
No Matches
physxKitchen.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file physxKitchen.cxx
10 * @author enn0x
11 * @date 2009-10-12
12 */
13
14#include "physxKitchen.h"
15#include "physxConvexMesh.h"
16#include "physxConvexMeshDesc.h"
17#include "physxTriangleMesh.h"
19#include "physxFileStream.h"
22#include "physxClothMesh.h"
23#include "physxClothMeshDesc.h"
24#include "physxSoftBodyMesh.h"
26
27/**
28 * Sets two parameters which affect mesh cooking:
29 *
30 * Skin width for convex meshes: Specifies the amount to inflate the convex
31 * mesh by when the new convex hull generator is used. Inflating the mesh
32 * allows the user to hide interpenetration errors by increasing the size of
33 * the collision mesh with respect to the size of the rendered geometry.
34 * Default value: 0.025f
35 *
36 * Hint to choose speed or less memory for collision structures. Default
37 * value: false
38 */
40set_cooking_params(float skinWidth, bool hintCollisionSpeed) {
41
42 NxCookingParams params;
43
44 params.targetPlatform = PLATFORM_PC;
45 params.skinWidth = skinWidth;
46 params.hintCollisionSpeed = hintCollisionSpeed;
47
48 _cooking->NxSetCookingParams(params);
49}
50
51/**
52 *
53 */
54bool PhysxKitchen::
55cook_convex_mesh(const PhysxConvexMeshDesc &meshDesc, const Filename &filename) {
56
57 nassertr_always(!filename.empty(), false);
58 nassertr_always(filename.touch(), false);
59 nassertr_always(meshDesc.is_valid(), false);
60
61 PhysxFileStream fs = PhysxFileStream(filename, false);
62 return _cooking->NxCookConvexMesh(meshDesc.get_desc(), fs);
63}
64
65/**
66 *
67 */
68bool PhysxKitchen::
69cook_triangle_mesh(const PhysxTriangleMeshDesc &meshDesc, const Filename &filename) {
70
71 nassertr_always(!filename.empty(), false);
72 nassertr_always(filename.touch(), false);
73 nassertr_always(meshDesc.is_valid(), false);
74
75 PhysxFileStream fs = PhysxFileStream(filename, false);
76 return _cooking->NxCookTriangleMesh(meshDesc.get_desc(), fs);
77}
78
79/**
80 *
81 */
82bool PhysxKitchen::
83cook_cloth_mesh(const PhysxClothMeshDesc &meshDesc, const Filename &filename) {
84
85 nassertr_always(!filename.empty(), false);
86 nassertr_always(filename.touch(), false);
87 nassertr_always(meshDesc.is_valid(), false);
88
89 PhysxFileStream fs = PhysxFileStream(filename, false);
90 return _cooking->NxCookClothMesh(meshDesc.get_desc(), fs);
91}
92
93/**
94 *
95 */
96bool PhysxKitchen::
97cook_soft_body_mesh(const PhysxSoftBodyMeshDesc &meshDesc, const Filename &filename) {
98
99 nassertr_always(!filename.empty(), false);
100 nassertr_always(filename.touch(), false);
101 nassertr_always(meshDesc.is_valid(), false);
102
103 PhysxFileStream fs = PhysxFileStream(filename, false);
104 return _cooking->NxCookSoftBodyMesh(meshDesc.get_desc(), fs);
105}
106
107/**
108 *
109 */
110bool PhysxKitchen::
111cook_texcoords(const PhysxClothMeshDesc &meshDesc, const Filename &filename) {
112
113 nassertr_always(!filename.empty(), false);
114 nassertr_always(filename.touch(), false);
115 nassertr_always(meshDesc.is_valid(), false);
116
117 const plist<LPoint2f> texcoords = meshDesc.get_texcoords();
118
119 // Write texcoords to binary file
120 PhysxFileStream fs = PhysxFileStream(filename.c_str(), false);
121
122 // Header
123 fs.storeByte('N');
124 fs.storeByte('X');
125 fs.storeByte('S');
126 fs.storeByte(1);
127 fs.storeByte('T');
128 fs.storeByte('E');
129 fs.storeByte('X');
130 fs.storeByte('C');
131 fs.storeByte(1);
132
133 // Size
134 fs.storeDword(texcoords.size());
135
136 // Texcoords
137 plist<LPoint2f>::const_iterator it;
138 for(it=texcoords.begin(); it!=texcoords.end(); it++) {
139 LPoint2f v = *it;
140
141 fs.storeFloat(v.get_x());
142 fs.storeFloat(v.get_y());
143 }
144
145 return true;
146}
147
148/**
149 *
150 */
151PhysxConvexMesh *PhysxKitchen::
152cook_convex_mesh(const PhysxConvexMeshDesc &meshDesc) {
153
154 nassertr_always(meshDesc.is_valid(), nullptr);
155
157 bool status = _cooking->NxCookConvexMesh(meshDesc.get_desc(), buffer);
158 nassertr(status, nullptr);
159
160 NxPhysicsSDK *sdk = NxGetPhysicsSDK();
161 nassertr(sdk, nullptr);
162
163 PhysxConvexMesh *mesh = new PhysxConvexMesh();
164 nassertr(mesh, nullptr);
165
166 NxConvexMesh *meshPtr = sdk->createConvexMesh(PhysxMemoryReadBuffer(buffer.data));
167 nassertr(meshPtr, nullptr);
168
169 mesh->link(meshPtr);
170
171 return mesh;
172}
173
174/**
175 *
176 */
177PhysxTriangleMesh *PhysxKitchen::
178cook_triangle_mesh(const PhysxTriangleMeshDesc &meshDesc) {
179
180 nassertr_always(meshDesc.is_valid(), nullptr);
181
183 bool status = _cooking->NxCookTriangleMesh(meshDesc.get_desc(), buffer);
184 nassertr(status, nullptr);
185
186 NxPhysicsSDK *sdk = NxGetPhysicsSDK();
187 nassertr(sdk, nullptr);
188
190 nassertr(mesh, nullptr);
191
192 NxTriangleMesh *meshPtr = sdk->createTriangleMesh(PhysxMemoryReadBuffer(buffer.data));
193 nassertr(meshPtr, nullptr);
194
195 mesh->link(meshPtr);
196
197 return mesh;
198}
199
200/**
201 *
202 */
203PhysxClothMesh *PhysxKitchen::
204cook_cloth_mesh(const PhysxClothMeshDesc &meshDesc) {
205
206 nassertr_always(meshDesc.is_valid(), nullptr);
207
209 bool status = _cooking->NxCookClothMesh(meshDesc.get_desc(), wbuffer);
210 nassertr(status, nullptr);
211
212 NxPhysicsSDK *sdk = NxGetPhysicsSDK();
213 nassertr(sdk, nullptr);
214
215 PhysxClothMesh *mesh = new PhysxClothMesh();
216 nassertr(mesh, nullptr);
217
218 PhysxMemoryReadBuffer rbuffer(wbuffer.data);
219 NxClothMesh *meshPtr = sdk->createClothMesh(rbuffer);
220 nassertr(meshPtr, nullptr);
221
222 mesh->link(meshPtr);
223
224 return mesh;
225}
226
227/**
228 *
229 */
230PhysxSoftBodyMesh *PhysxKitchen::
231cook_soft_body_mesh(const PhysxSoftBodyMeshDesc &meshDesc) {
232
233 nassertr_always(meshDesc.is_valid(), nullptr);
234
236 bool status = _cooking->NxCookSoftBodyMesh(meshDesc.get_desc(), wbuffer);
237 nassertr(status, nullptr);
238
239 NxPhysicsSDK *sdk = NxGetPhysicsSDK();
240 nassertr(sdk, nullptr);
241
243 nassertr(mesh, nullptr);
244
245 PhysxMemoryReadBuffer rbuffer(wbuffer.data);
246 NxSoftBodyMesh *meshPtr = sdk->createSoftBodyMesh(rbuffer);
247 nassertr(meshPtr, nullptr);
248
249 mesh->link(meshPtr);
250
251 return mesh;
252}
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
bool touch() const
Updates the modification time of the file to the current time.
bool is_valid() const
Returns true if the descriptor is valid.
bool is_valid() const
Returns true if the descriptor is valid.
A Convex Mesh.
void set_cooking_params(float skinWidth, bool hintCollisionSpeed)
Sets two parameters which affect mesh cooking:
bool is_valid() const
Returns true if the descriptor is valid.
bool is_valid() const
Returns true if the descriptor is valid.
This is our own Panda specialization on the default STL list.
Definition plist.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.