00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "physxKitchen.h"
00016 #include "physxConvexMesh.h"
00017 #include "physxConvexMeshDesc.h"
00018 #include "physxTriangleMesh.h"
00019 #include "physxTriangleMeshDesc.h"
00020 #include "physxFileStream.h"
00021 #include "physxMemoryReadBuffer.h"
00022 #include "physxMemoryWriteBuffer.h"
00023 #include "physxClothMesh.h"
00024 #include "physxClothMeshDesc.h"
00025 #include "physxSoftBodyMesh.h"
00026 #include "physxSoftBodyMeshDesc.h"
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 void PhysxKitchen::
00047 set_cooking_params(float skinWidth, bool hintCollisionSpeed) {
00048
00049 NxCookingParams params;
00050
00051 params.targetPlatform = PLATFORM_PC;
00052 params.skinWidth = skinWidth;
00053 params.hintCollisionSpeed = hintCollisionSpeed;
00054
00055 _cooking->NxSetCookingParams(params);
00056 }
00057
00058
00059
00060
00061
00062
00063 bool PhysxKitchen::
00064 cook_convex_mesh(const PhysxConvexMeshDesc &meshDesc, const Filename &filename) {
00065
00066 nassertr_always(!filename.empty(), false);
00067 nassertr_always(filename.touch(), false);
00068 nassertr_always(meshDesc.is_valid(), false);
00069
00070 PhysxFileStream fs = PhysxFileStream(filename, false);
00071 return _cooking->NxCookConvexMesh(meshDesc.get_desc(), fs);
00072 }
00073
00074
00075
00076
00077
00078
00079 bool PhysxKitchen::
00080 cook_triangle_mesh(const PhysxTriangleMeshDesc &meshDesc, const Filename &filename) {
00081
00082 nassertr_always(!filename.empty(), false);
00083 nassertr_always(filename.touch(), false);
00084 nassertr_always(meshDesc.is_valid(), false);
00085
00086 PhysxFileStream fs = PhysxFileStream(filename, false);
00087 return _cooking->NxCookTriangleMesh(meshDesc.get_desc(), fs);
00088 }
00089
00090
00091
00092
00093
00094
00095 bool PhysxKitchen::
00096 cook_cloth_mesh(const PhysxClothMeshDesc &meshDesc, const Filename &filename) {
00097
00098 nassertr_always(!filename.empty(), false);
00099 nassertr_always(filename.touch(), false);
00100 nassertr_always(meshDesc.is_valid(), false);
00101
00102 PhysxFileStream fs = PhysxFileStream(filename, false);
00103 return _cooking->NxCookClothMesh(meshDesc.get_desc(), fs);
00104 }
00105
00106
00107
00108
00109
00110
00111 bool PhysxKitchen::
00112 cook_soft_body_mesh(const PhysxSoftBodyMeshDesc &meshDesc, const Filename &filename) {
00113
00114 nassertr_always(!filename.empty(), false);
00115 nassertr_always(filename.touch(), false);
00116 nassertr_always(meshDesc.is_valid(), false);
00117
00118 PhysxFileStream fs = PhysxFileStream(filename, false);
00119 return _cooking->NxCookSoftBodyMesh(meshDesc.get_desc(), fs);
00120 }
00121
00122
00123
00124
00125
00126
00127 bool PhysxKitchen::
00128 cook_texcoords(const PhysxClothMeshDesc &meshDesc, const Filename &filename) {
00129
00130 nassertr_always(!filename.empty(), false);
00131 nassertr_always(filename.touch(), false);
00132 nassertr_always(meshDesc.is_valid(), false);
00133
00134 const plist<LPoint2f> texcoords = meshDesc.get_texcoords();
00135
00136
00137 PhysxFileStream fs = PhysxFileStream(filename.c_str(), false);
00138
00139
00140 fs.storeByte('N');
00141 fs.storeByte('X');
00142 fs.storeByte('S');
00143 fs.storeByte(1);
00144 fs.storeByte('T');
00145 fs.storeByte('E');
00146 fs.storeByte('X');
00147 fs.storeByte('C');
00148 fs.storeByte(1);
00149
00150
00151 fs.storeDword(texcoords.size());
00152
00153
00154 plist<LPoint2f>::const_iterator it;
00155 for(it=texcoords.begin(); it!=texcoords.end(); it++) {
00156 LPoint2f v = *it;
00157
00158 fs.storeFloat(v.get_x());
00159 fs.storeFloat(v.get_y());
00160 }
00161
00162 return true;
00163 }
00164
00165
00166
00167
00168
00169
00170 PhysxConvexMesh *PhysxKitchen::
00171 cook_convex_mesh(const PhysxConvexMeshDesc &meshDesc) {
00172
00173 nassertr_always(meshDesc.is_valid(), false);
00174
00175 PhysxMemoryWriteBuffer buffer;
00176 bool status = _cooking->NxCookConvexMesh(meshDesc.get_desc(), buffer);
00177 nassertr(status, NULL);
00178
00179 NxPhysicsSDK *sdk = NxGetPhysicsSDK();
00180 nassertr(sdk, NULL);
00181
00182 PhysxConvexMesh *mesh = new PhysxConvexMesh();
00183 nassertr(mesh, NULL);
00184
00185 NxConvexMesh *meshPtr = sdk->createConvexMesh(PhysxMemoryReadBuffer(buffer.data));
00186 nassertr(meshPtr, NULL);
00187
00188 mesh->link(meshPtr);
00189
00190 return mesh;
00191 }
00192
00193
00194
00195
00196
00197
00198 PhysxTriangleMesh *PhysxKitchen::
00199 cook_triangle_mesh(const PhysxTriangleMeshDesc &meshDesc) {
00200
00201 nassertr_always(meshDesc.is_valid(), false);
00202
00203 PhysxMemoryWriteBuffer buffer;
00204 bool status = _cooking->NxCookTriangleMesh(meshDesc.get_desc(), buffer);
00205 nassertr(status, NULL);
00206
00207 NxPhysicsSDK *sdk = NxGetPhysicsSDK();
00208 nassertr(sdk, NULL);
00209
00210 PhysxTriangleMesh *mesh = new PhysxTriangleMesh();
00211 nassertr(mesh, NULL);
00212
00213 NxTriangleMesh *meshPtr = sdk->createTriangleMesh(PhysxMemoryReadBuffer(buffer.data));
00214 nassertr(meshPtr, NULL);
00215
00216 mesh->link(meshPtr);
00217
00218 return mesh;
00219 }
00220
00221
00222
00223
00224
00225
00226 PhysxClothMesh *PhysxKitchen::
00227 cook_cloth_mesh(const PhysxClothMeshDesc &meshDesc) {
00228
00229 nassertr_always(meshDesc.is_valid(), false);
00230
00231 PhysxMemoryWriteBuffer wbuffer;
00232 bool status = _cooking->NxCookClothMesh(meshDesc.get_desc(), wbuffer);
00233 nassertr(status, NULL);
00234
00235 NxPhysicsSDK *sdk = NxGetPhysicsSDK();
00236 nassertr(sdk, NULL);
00237
00238 PhysxClothMesh *mesh = new PhysxClothMesh();
00239 nassertr(mesh, NULL);
00240
00241 PhysxMemoryReadBuffer rbuffer(wbuffer.data);
00242 NxClothMesh *meshPtr = sdk->createClothMesh(rbuffer);
00243 nassertr(meshPtr, NULL);
00244
00245 mesh->link(meshPtr);
00246
00247 return mesh;
00248 }
00249
00250
00251
00252
00253
00254
00255 PhysxSoftBodyMesh *PhysxKitchen::
00256 cook_soft_body_mesh(const PhysxSoftBodyMeshDesc &meshDesc) {
00257
00258 nassertr_always(meshDesc.is_valid(), false);
00259
00260 PhysxMemoryWriteBuffer wbuffer;
00261 bool status = _cooking->NxCookSoftBodyMesh(meshDesc.get_desc(), wbuffer);
00262 nassertr(status, NULL);
00263
00264 NxPhysicsSDK *sdk = NxGetPhysicsSDK();
00265 nassertr(sdk, NULL);
00266
00267 PhysxSoftBodyMesh *mesh = new PhysxSoftBodyMesh();
00268 nassertr(mesh, NULL);
00269
00270 PhysxMemoryReadBuffer rbuffer(wbuffer.data);
00271 NxSoftBodyMesh *meshPtr = sdk->createSoftBodyMesh(rbuffer);
00272 nassertr(meshPtr, NULL);
00273
00274 mesh->link(meshPtr);
00275
00276 return mesh;
00277 }
00278