aboutsummaryrefslogtreecommitdiff
path: root/PhysX_3.4/Samples/PxToolkit/src
diff options
context:
space:
mode:
authorgit perforce import user <a@b>2016-10-25 12:29:14 -0600
committerSheikh Dawood Abdul Ajees <Sheikh Dawood Abdul Ajees>2016-10-25 18:56:37 -0500
commit3dfe2108cfab31ba3ee5527e217d0d8e99a51162 (patch)
treefa6485c169e50d7415a651bf838f5bcd0fd3bfbd /PhysX_3.4/Samples/PxToolkit/src
downloadphysx-3.4-3dfe2108cfab31ba3ee5527e217d0d8e99a51162.tar.xz
physx-3.4-3dfe2108cfab31ba3ee5527e217d0d8e99a51162.zip
Initial commit:
PhysX 3.4.0 Update @ 21294896 APEX 1.4.0 Update @ 21275617 [CL 21300167]
Diffstat (limited to 'PhysX_3.4/Samples/PxToolkit/src')
-rw-r--r--PhysX_3.4/Samples/PxToolkit/src/PxTkBmpLoader.cpp195
-rw-r--r--PhysX_3.4/Samples/PxToolkit/src/PxTkFPS.cpp69
-rw-r--r--PhysX_3.4/Samples/PxToolkit/src/PxTkMatrixUtils.cpp89
-rw-r--r--PhysX_3.4/Samples/PxToolkit/src/PxTkRandom.cpp141
-rw-r--r--PhysX_3.4/Samples/PxToolkit/src/PxTkStream.cpp155
5 files changed, 649 insertions, 0 deletions
diff --git a/PhysX_3.4/Samples/PxToolkit/src/PxTkBmpLoader.cpp b/PhysX_3.4/Samples/PxToolkit/src/PxTkBmpLoader.cpp
new file mode 100644
index 00000000..458c68d1
--- /dev/null
+++ b/PhysX_3.4/Samples/PxToolkit/src/PxTkBmpLoader.cpp
@@ -0,0 +1,195 @@
+// This code contains NVIDIA Confidential Information and is disclosed to you
+// under a form of NVIDIA software license agreement provided separately to you.
+//
+// Notice
+// NVIDIA Corporation and its licensors retain all intellectual property and
+// proprietary rights in and to this software and related documentation and
+// any modifications thereto. Any use, reproduction, disclosure, or
+// distribution of this software and related documentation without an express
+// license agreement from NVIDIA Corporation is strictly prohibited.
+//
+// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
+// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
+// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
+// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// Information and code furnished is believed to be accurate and reliable.
+// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
+// information or for any infringement of patents or other rights of third parties that may
+// result from its use. No license is granted by implication or otherwise under any patent
+// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
+// This code supersedes and replaces all information previously supplied.
+// NVIDIA Corporation products are not authorized for use as critical
+// components in life support devices or systems without express written approval of
+// NVIDIA Corporation.
+//
+// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved.
+// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
+// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "PxTkBmpLoader.h"
+#include "PxTkFile.h"
+
+
+using namespace PxToolkit;
+
+#define MAKETWOCC(a,b) ( (static_cast<char>(a)) | ((static_cast<char>(b))<< 8) )
+
+static bool isBigEndian() { int i = 1; return *(reinterpret_cast<char*>(&i))==0; }
+
+static unsigned short endianSwap(unsigned short nValue)
+{
+ return (((nValue>> 8)) | (nValue << 8));
+
+}
+
+static unsigned int endianSwap(unsigned int i)
+{
+ unsigned char b1, b2, b3, b4;
+
+ b1 = i & 255;
+ b2 = ( i >> 8 ) & 255;
+ b3 = ( i>>16 ) & 255;
+ b4 = ( i>>24 ) & 255;
+
+ return (static_cast<unsigned int>(b1) << 24) + (static_cast<unsigned int>(b2) << 16) + (static_cast<unsigned int>(b3) << 8) + b4;
+}
+
+// -------------------------------------------------------------------
+
+#pragma pack(1)
+
+struct BMPHEADER {
+ unsigned short Type;
+ unsigned int Size;
+ unsigned short Reserved1;
+ unsigned short Reserved2;
+ unsigned int OffBits;
+};
+
+// Only Win3.0 BMPINFO (see later for OS/2)
+struct BMPINFO {
+ unsigned int Size;
+ unsigned int Width;
+ unsigned int Height;
+ unsigned short Planes;
+ unsigned short BitCount;
+ unsigned int Compression;
+ unsigned int SizeImage;
+ unsigned int XPelsPerMeter;
+ unsigned int YPelsPerMeter;
+ unsigned int ClrUsed;
+ unsigned int ClrImportant;
+};
+
+#pragma pack()
+
+// Compression Type
+#define BI_RGB 0L
+#define BI_RLE8 1L
+#define BI_RLE4 2L
+
+// -------------------------------------------------------------------
+BmpLoader::BmpLoader() :
+ mWidth (0),
+ mHeight (0),
+ mRGB (NULL),
+ mHasAlpha (false)
+{
+}
+
+// -------------------------------------------------------------------
+BmpLoader::~BmpLoader()
+{
+ if (mRGB) free(mRGB);
+}
+
+// -------------------------------------------------------------------
+bool BmpLoader::loadBmp(PxFileHandle f)
+{
+ if (!f) return false;
+
+ if (mRGB) {
+ free(mRGB);
+ mRGB = NULL;
+ }
+ mWidth = 0;
+ mHeight = 0;
+
+ size_t num;
+ BMPHEADER header;
+ num = fread(&header, 1, sizeof(BMPHEADER), f);
+ if(isBigEndian()) header.Type = endianSwap(header.Type);
+ if (num != sizeof(BMPHEADER)) { fclose(f); return false; }
+ if (header.Type != MAKETWOCC('B','M')) { fclose(f); return false; }
+
+ BMPINFO info;
+ num = fread(&info, 1, sizeof(BMPINFO), f);
+ if (num != sizeof(BMPINFO)) { fclose(f); return false; }
+ if(isBigEndian()) info.Size = endianSwap(info.Size);
+ if(isBigEndian()) info.BitCount = endianSwap(info.BitCount);
+ if(isBigEndian()) info.Compression = endianSwap(info.Compression);
+ if(isBigEndian()) info.Width = endianSwap(info.Width);
+ if(isBigEndian()) info.Height = endianSwap(info.Height);
+
+ if (info.Size != sizeof(BMPINFO)) { fclose(f); return false; }
+ if (info.BitCount != 24 && info.BitCount != 32) { fclose(f); return false; }
+ if (info.Compression != BI_RGB) { fclose(f); return false; }
+
+ mWidth = info.Width;
+ mHeight = info.Height;
+
+ int bytesPerPixel = 0;
+ if(info.BitCount == 24)
+ {
+ mHasAlpha = false;
+ bytesPerPixel = 3;
+ }
+ else if(info.BitCount == 32)
+ {
+ mHasAlpha = true;
+ bytesPerPixel = 4;
+ }
+ else assert(0);
+
+ mRGB = static_cast<unsigned char*>(malloc(mWidth * mHeight * bytesPerPixel));
+
+ int lineLen = (((info.Width * (info.BitCount>>3)) + 3)>>2)<<2;
+ unsigned char* line = static_cast<unsigned char*>(malloc(lineLen));
+
+ for(int i = info.Height-1; i >= 0; i--)
+ {
+ num = fread(line, 1, static_cast<size_t>(lineLen), f);
+ if (num != static_cast<size_t>(lineLen)) { fclose(f); return false; }
+ unsigned char* src = line;
+ unsigned char* dest = mRGB + i*info.Width*bytesPerPixel;
+ for(unsigned int j = 0; j < info.Width; j++)
+ {
+ unsigned char b = *src++;
+ unsigned char g = *src++;
+ unsigned char r = *src++;
+ unsigned char a = mHasAlpha ? *src++ : 0;
+ *dest++ = r;
+ *dest++ = g;
+ *dest++ = b;
+ if(mHasAlpha)
+ *dest++ = a;
+ }
+ }
+
+ free(line);
+ return true;
+}
+
+// -------------------------------------------------------------------
+bool BmpLoader::loadBmp(const char *filename)
+{
+ PxFileHandle f = NULL;
+ PxToolkit::fopen_s(&f, filename, "rb");
+ bool ret = loadBmp(f);
+ if(f) fclose(f);
+ return ret;
+}
diff --git a/PhysX_3.4/Samples/PxToolkit/src/PxTkFPS.cpp b/PhysX_3.4/Samples/PxToolkit/src/PxTkFPS.cpp
new file mode 100644
index 00000000..2161d769
--- /dev/null
+++ b/PhysX_3.4/Samples/PxToolkit/src/PxTkFPS.cpp
@@ -0,0 +1,69 @@
+// This code contains NVIDIA Confidential Information and is disclosed to you
+// under a form of NVIDIA software license agreement provided separately to you.
+//
+// Notice
+// NVIDIA Corporation and its licensors retain all intellectual property and
+// proprietary rights in and to this software and related documentation and
+// any modifications thereto. Any use, reproduction, disclosure, or
+// distribution of this software and related documentation without an express
+// license agreement from NVIDIA Corporation is strictly prohibited.
+//
+// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
+// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
+// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
+// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// Information and code furnished is believed to be accurate and reliable.
+// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
+// information or for any infringement of patents or other rights of third parties that may
+// result from its use. No license is granted by implication or otherwise under any patent
+// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
+// This code supersedes and replaces all information previously supplied.
+// NVIDIA Corporation products are not authorized for use as critical
+// components in life support devices or systems without express written approval of
+// NVIDIA Corporation.
+//
+// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved.
+// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
+// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
+
+#include "PxTkFPS.h"
+
+using namespace PxToolkit;
+
+FPS::FPS()
+{
+ mFrames = 0;
+ mFrames2 = 0;
+ mFPS = 0.0f;
+ mInstantFPS = 0.0f;
+}
+
+FPS::~FPS()
+{
+}
+
+void FPS::update()
+{
+ // Keep track of the time lapse and frame count
+ mFrames++;
+ mFrames2++;
+
+ // Instant frame rate
+ PxReal Delta = PxReal(mTimer2.peekElapsedSeconds());
+ if(Delta > 0.01f)
+ {
+ mInstantFPS = PxReal(mFrames2) / Delta;
+ mTimer2.getElapsedSeconds();
+ mFrames2 = 0;
+ }
+
+ // Update the frame rate once per second
+ Delta = PxReal(mTimer.peekElapsedSeconds());
+ if(Delta > 1.0f)
+ {
+ mFPS = PxReal(mFrames) / Delta;
+ mTimer.getElapsedSeconds();
+ mFrames = 0;
+ }
+}
diff --git a/PhysX_3.4/Samples/PxToolkit/src/PxTkMatrixUtils.cpp b/PhysX_3.4/Samples/PxToolkit/src/PxTkMatrixUtils.cpp
new file mode 100644
index 00000000..39b8e7e5
--- /dev/null
+++ b/PhysX_3.4/Samples/PxToolkit/src/PxTkMatrixUtils.cpp
@@ -0,0 +1,89 @@
+// This code contains NVIDIA Confidential Information and is disclosed to you
+// under a form of NVIDIA software license agreement provided separately to you.
+//
+// Notice
+// NVIDIA Corporation and its licensors retain all intellectual property and
+// proprietary rights in and to this software and related documentation and
+// any modifications thereto. Any use, reproduction, disclosure, or
+// distribution of this software and related documentation without an express
+// license agreement from NVIDIA Corporation is strictly prohibited.
+//
+// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
+// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
+// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
+// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// Information and code furnished is believed to be accurate and reliable.
+// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
+// information or for any infringement of patents or other rights of third parties that may
+// result from its use. No license is granted by implication or otherwise under any patent
+// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
+// This code supersedes and replaces all information previously supplied.
+// NVIDIA Corporation products are not authorized for use as critical
+// components in life support devices or systems without express written approval of
+// NVIDIA Corporation.
+//
+// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved.
+// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
+// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
+
+#include "PxTkMatrixUtils.h"
+
+using namespace PxToolkit;
+
+void PxToolkit::setRotX(PxMat33& m, PxReal angle)
+{
+ m = PxMat33(PxIdentity);
+
+ const PxReal cos = cosf(angle);
+ const PxReal sin = sinf(angle);
+
+ m[1][1] = m[2][2] = cos;
+ m[1][2] = sin;
+ m[2][1] = -sin;
+}
+
+void PxToolkit::setRotY(PxMat33& m, PxReal angle)
+{
+ m = PxMat33(PxIdentity);
+
+ const PxReal cos = cosf(angle);
+ const PxReal sin = sinf(angle);
+
+ m[0][0] = m[2][2] = cos;
+ m[0][2] = -sin;
+ m[2][0] = sin;
+}
+
+void PxToolkit::setRotZ(PxMat33& m, PxReal angle)
+{
+ m = PxMat33(PxIdentity);
+
+ const PxReal cos = cosf(angle);
+ const PxReal sin = sinf(angle);
+
+ m[0][0] = m[1][1] = cos;
+ m[0][1] = sin;
+ m[1][0] = -sin;
+}
+
+PxQuat PxToolkit::getRotXQuat(float angle)
+{
+ PxMat33 m;
+ setRotX(m, angle);
+ return PxQuat(m);
+}
+
+PxQuat PxToolkit::getRotYQuat(float angle)
+{
+ PxMat33 m;
+ setRotY(m, angle);
+ return PxQuat(m);
+}
+
+PxQuat PxToolkit::getRotZQuat(float angle)
+{
+ PxMat33 m;
+ setRotZ(m, angle);
+ return PxQuat(m);
+}
diff --git a/PhysX_3.4/Samples/PxToolkit/src/PxTkRandom.cpp b/PhysX_3.4/Samples/PxToolkit/src/PxTkRandom.cpp
new file mode 100644
index 00000000..e25a9357
--- /dev/null
+++ b/PhysX_3.4/Samples/PxToolkit/src/PxTkRandom.cpp
@@ -0,0 +1,141 @@
+// This code contains NVIDIA Confidential Information and is disclosed to you
+// under a form of NVIDIA software license agreement provided separately to you.
+//
+// Notice
+// NVIDIA Corporation and its licensors retain all intellectual property and
+// proprietary rights in and to this software and related documentation and
+// any modifications thereto. Any use, reproduction, disclosure, or
+// distribution of this software and related documentation without an express
+// license agreement from NVIDIA Corporation is strictly prohibited.
+//
+// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
+// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
+// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
+// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// Information and code furnished is believed to be accurate and reliable.
+// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
+// information or for any infringement of patents or other rights of third parties that may
+// result from its use. No license is granted by implication or otherwise under any patent
+// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
+// This code supersedes and replaces all information previously supplied.
+// NVIDIA Corporation products are not authorized for use as critical
+// components in life support devices or systems without express written approval of
+// NVIDIA Corporation.
+//
+// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved.
+// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
+// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
+
+#include "PxTkRandom.h"
+#include "foundation/PxQuat.h"
+
+using namespace physx;
+using namespace PxToolkit;
+
+static RandomR250 gRandomR250(0x95d6739b);
+
+PxVec3 BasicRandom::unitRandomPt()
+{
+ PxVec3 v;
+ do
+ {
+ v.x = randomFloat();
+ v.y = randomFloat();
+ v.z = randomFloat();
+ }
+ while(v.normalize()<1e-6f);
+ return v;
+}
+
+PxQuat BasicRandom::unitRandomQuat()
+{
+ PxQuat v;
+ do
+ {
+ v.x = randomFloat();
+ v.y = randomFloat();
+ v.z = randomFloat();
+ v.w = randomFloat();
+ }
+ while(v.normalize()<1e-6f);
+
+ return v;
+}
+
+
+void BasicRandom::unitRandomPt(PxVec3& v)
+{
+ v = unitRandomPt();
+}
+void BasicRandom::unitRandomQuat(PxQuat& v)
+{
+ v = unitRandomQuat();
+}
+
+
+void PxToolkit::SetSeed(PxU32 seed)
+{
+ gRandomR250.setSeed(seed);
+}
+
+PxU32 PxToolkit::Rand()
+{
+ return gRandomR250.randI() & TEST_MAX_RAND;
+}
+
+
+RandomR250::RandomR250(PxI32 s)
+{
+ setSeed(s);
+}
+
+void RandomR250::setSeed(PxI32 s)
+{
+ BasicRandom lcg(s);
+ mIndex = 0;
+
+ PxI32 j;
+ for (j = 0; j < 250; j++) // fill r250 buffer with bit values
+ mBuffer[j] = lcg.randomize();
+
+ for (j = 0; j < 250; j++) // set some MSBs to 1
+ if ( lcg.randomize() > 0x40000000L )
+ mBuffer[j] |= 0x80000000L;
+
+ PxU32 msb = 0x80000000; // turn on diagonal bit
+ PxU32 mask = 0xffffffff; // turn off the leftmost bits
+
+ for (j = 0; j < 32; j++)
+ {
+ const PxI32 k = 7 * j + 3; // select a word to operate on
+ mBuffer[k] &= mask; // turn off bits left of the diagonal
+ mBuffer[k] |= msb; // turn on the diagonal bit
+ mask >>= 1;
+ msb >>= 1;
+ }
+}
+
+PxU32 RandomR250::randI()
+{
+ PxI32 j;
+
+ // wrap pointer around
+ if ( mIndex >= 147 ) j = mIndex - 147;
+ else j = mIndex + 103;
+
+ const PxU32 new_rand = mBuffer[ mIndex ] ^ mBuffer[ j ];
+ mBuffer[ mIndex ] = new_rand;
+
+ // increment pointer for next time
+ if ( mIndex >= 249 ) mIndex = 0;
+ else mIndex++;
+
+ return new_rand >> 1;
+}
+
+PxReal RandomR250::randUnit()
+{
+ PxU32 mask = (1<<23)-1;
+ return PxF32(randI()&(mask))/PxF32(mask);
+}
diff --git a/PhysX_3.4/Samples/PxToolkit/src/PxTkStream.cpp b/PhysX_3.4/Samples/PxToolkit/src/PxTkStream.cpp
new file mode 100644
index 00000000..2d289af1
--- /dev/null
+++ b/PhysX_3.4/Samples/PxToolkit/src/PxTkStream.cpp
@@ -0,0 +1,155 @@
+// This code contains NVIDIA Confidential Information and is disclosed to you
+// under a form of NVIDIA software license agreement provided separately to you.
+//
+// Notice
+// NVIDIA Corporation and its licensors retain all intellectual property and
+// proprietary rights in and to this software and related documentation and
+// any modifications thereto. Any use, reproduction, disclosure, or
+// distribution of this software and related documentation without an express
+// license agreement from NVIDIA Corporation is strictly prohibited.
+//
+// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
+// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
+// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
+// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// Information and code furnished is believed to be accurate and reliable.
+// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
+// information or for any infringement of patents or other rights of third parties that may
+// result from its use. No license is granted by implication or otherwise under any patent
+// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
+// This code supersedes and replaces all information previously supplied.
+// NVIDIA Corporation products are not authorized for use as critical
+// components in life support devices or systems without express written approval of
+// NVIDIA Corporation.
+//
+// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved.
+// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
+// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
+
+#include "PxTkStream.h"
+#include "foundation/PxAssert.h"
+#include "PxTkFile.h"
+#include "PxTkNamespaceMangle.h"
+#include "PsIntrinsics.h"
+#include "foundation/PxMath.h"
+#include "PxPhysics.h"
+#include "geometry/PxConvexMesh.h"
+#include "cooking/PxCooking.h"
+#include "foundation/PxBounds3.h"
+#include "extensions/PxDefaultStreams.h"
+
+using namespace PxToolkit;
+///////////////////////////////////////////////////////////////////////////////
+
+PxTriangleMesh* PxToolkit::createTriangleMesh32(PxPhysics& physics, PxCooking& cooking, const PxVec3* verts, PxU32 vertCount, const PxU32* indices32, PxU32 triCount, bool insert)
+{
+ PxTriangleMeshDesc meshDesc;
+ meshDesc.points.count = vertCount;
+ meshDesc.points.stride = sizeof(PxVec3);
+ meshDesc.points.data = verts;
+
+ meshDesc.triangles.count = triCount;
+ meshDesc.triangles.stride = 3*sizeof(PxU32);
+ meshDesc.triangles.data = indices32;
+
+ if(!insert)
+ {
+ PxDefaultMemoryOutputStream writeBuffer;
+ bool status = cooking.cookTriangleMesh(meshDesc, writeBuffer);
+ if(!status)
+ return NULL;
+
+ PxDefaultMemoryInputData readBuffer(writeBuffer.getData(), writeBuffer.getSize());
+ return physics.createTriangleMesh(readBuffer);
+ }
+ else
+ {
+ return cooking.createTriangleMesh(meshDesc,physics.getPhysicsInsertionCallback());
+ }
+}
+
+PxTriangleMesh* PxToolkit::createTriangleMesh32(PxPhysics& physics, PxCooking& cooking, PxTriangleMeshDesc* meshDesc, bool insert)
+{
+ if(!insert)
+ {
+ PxDefaultMemoryOutputStream writeBuffer;
+ bool status = cooking.cookTriangleMesh(*meshDesc, writeBuffer);
+ if(!status)
+ return NULL;
+
+ PxDefaultMemoryInputData readBuffer(writeBuffer.getData(), writeBuffer.getSize());
+ return physics.createTriangleMesh(readBuffer);
+ }
+ else
+ {
+ return cooking.createTriangleMesh(*meshDesc,physics.getPhysicsInsertionCallback());
+ }
+}
+
+PxConvexMesh* PxToolkit::createConvexMesh(PxPhysics& physics, PxCooking& cooking, const PxVec3* verts, PxU32 vertCount, PxConvexFlags flags)
+{
+ PxConvexMeshDesc convexDesc;
+ convexDesc.points.count = vertCount;
+ convexDesc.points.stride = sizeof(PxVec3);
+ convexDesc.points.data = verts;
+ convexDesc.flags = flags;
+
+ PxDefaultMemoryOutputStream buf;
+ if(!cooking.cookConvexMesh(convexDesc, buf))
+ return NULL;
+
+ PxDefaultMemoryInputData input(buf.getData(), buf.getSize());
+ return physics.createConvexMesh(input);
+}
+
+PxConvexMesh* PxToolkit::createConvexMeshSafe(PxPhysics& physics, PxCooking& cooking, const PxVec3* verts, PxU32 vertCount, PxConvexFlags flags, PxU32 vLimit)
+{
+ PxConvexMeshDesc convexDesc;
+ convexDesc.points.count = vertCount;
+ convexDesc.points.stride = sizeof(PxVec3);
+ convexDesc.points.data = verts;
+ convexDesc.flags = flags;
+ convexDesc.vertexLimit = vLimit;
+
+ PxDefaultMemoryOutputStream buf;
+ bool retVal = cooking.cookConvexMesh(convexDesc, buf);
+ if(!retVal)
+ {
+ // create AABB
+ PxBounds3 aabb;
+ aabb.setEmpty();
+ for (PxU32 i = 0; i < vertCount; i++)
+ {
+ aabb.include(verts[i]);
+ }
+
+ PxVec3 aabbVerts[8];
+ aabbVerts[0] = PxVec3(aabb.minimum.x,aabb.minimum.y,aabb.minimum.z);
+ aabbVerts[1] = PxVec3(aabb.maximum.x,aabb.minimum.y,aabb.minimum.z);
+ aabbVerts[2] = PxVec3(aabb.maximum.x,aabb.maximum.y,aabb.minimum.z);
+ aabbVerts[3] = PxVec3(aabb.minimum.x,aabb.maximum.y,aabb.minimum.z);
+
+ aabbVerts[4] = PxVec3(aabb.minimum.x,aabb.minimum.y,aabb.maximum.z);
+ aabbVerts[5] = PxVec3(aabb.maximum.x,aabb.minimum.y,aabb.maximum.z);
+ aabbVerts[6] = PxVec3(aabb.maximum.x,aabb.maximum.y,aabb.maximum.z);
+ aabbVerts[7] = PxVec3(aabb.minimum.x,aabb.maximum.y,aabb.maximum.z);
+
+ convexDesc.points.count = 8;
+ convexDesc.points.stride = sizeof(PxVec3);
+ convexDesc.points.data = &aabbVerts[0];
+ convexDesc.flags = flags;
+
+ retVal = cooking.cookConvexMesh(convexDesc, buf);
+ }
+
+ if(!retVal)
+ {
+ return NULL;
+ }
+
+ PxDefaultMemoryInputData input(buf.getData(), buf.getSize());
+ return physics.createConvexMesh(input);
+}
+
+