aboutsummaryrefslogtreecommitdiff
path: root/sdk/extensions/physx
diff options
context:
space:
mode:
authorBryan Galdrikian <[email protected]>2019-05-03 00:25:46 -0700
committerBryan Galdrikian <[email protected]>2019-05-03 00:25:46 -0700
commit74b64a27f8e07b1b0b47b809b1a060518fa11a97 (patch)
tree34cca01711be56892c149706f02ba7358d87ec54 /sdk/extensions/physx
parentFixing chunk reorder bug in BlastTool, when importing a prefractured mesh (diff)
downloadblast-1.1.5_pre1.tar.xz
blast-1.1.5_pre1.zip
Blast SDK 1.1.5 prerelease #1v1.1.5_pre1
Diffstat (limited to 'sdk/extensions/physx')
-rw-r--r--sdk/extensions/physx/include/NvBlastExtPxCollisionBuilder.h73
-rwxr-xr-xsdk/extensions/physx/include/NvBlastExtPxManager.h76
-rw-r--r--sdk/extensions/physx/source/physics/NvBlastExtPxCollisionBuilderImpl.cpp232
-rw-r--r--sdk/extensions/physx/source/physics/NvBlastExtPxCollisionBuilderImpl.h74
-rwxr-xr-xsdk/extensions/physx/source/physics/NvBlastExtPxManagerImpl.cpp7
-rwxr-xr-xsdk/extensions/physx/source/physics/NvBlastExtPxStressSolverImpl.cpp8
6 files changed, 436 insertions, 34 deletions
diff --git a/sdk/extensions/physx/include/NvBlastExtPxCollisionBuilder.h b/sdk/extensions/physx/include/NvBlastExtPxCollisionBuilder.h
new file mode 100644
index 0000000..b7a2f14
--- /dev/null
+++ b/sdk/extensions/physx/include/NvBlastExtPxCollisionBuilder.h
@@ -0,0 +1,73 @@
+// 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) 2016-2018 NVIDIA Corporation. All rights reserved.
+
+
+#ifndef NVBLASTEXTPXCOLLISIONBUILDER_H
+#define NVBLASTEXTPXCOLLISIONBUILDER_H
+
+#include "NvBlastExtAuthoringConvexMeshBuilder.h"
+
+namespace physx
+{
+ class PxConvexMesh;
+}
+namespace Nv
+{
+namespace Blast
+{
+struct AuthoringResult;
+struct ExtPxChunk;
+struct ExtPxSubchunk;
+
+/**
+ConvexMeshBuilder provides routine to build collision hulls from array of vertices.
+Collision hull is built as convex hull of provided point set.
+If due to some reason building of convex hull is failed, collision hull is built as bounding box of vertex set.
+PhysX implementation can be found in NvBlastExtPx.
+*/
+class ExtPxCollisionBuilder : public ConvexMeshBuilder
+{
+ public:
+ /**
+ Method creates user defined collision mesh from provided array of vertices.
+ ConvexMeshBuilder from ExtPhysX returns PxConvexMesh pointer.
+ \param[in] hull Collision hull.
+ */
+ virtual physx::PxConvexMesh* buildConvexMesh(const CollisionHull& hull) = 0;
+
+ /**
+ Build physics chunks and subchunks from collision hulls
+ */
+ virtual void buildPhysicsChunks(uint32_t chunkCount, uint32_t* hullOffsets, CollisionHull** hulls,
+ ExtPxChunk* physicsChunks, ExtPxSubchunk* physicsSubchunks) = 0;
+};
+
+} // namespace Blast
+} // namespace Nv
+
+
+#endif // ifndef NVBLASTEXTPXCOLLISIONBUILDER_H
diff --git a/sdk/extensions/physx/include/NvBlastExtPxManager.h b/sdk/extensions/physx/include/NvBlastExtPxManager.h
index 1a6e5e3..690ab90 100755
--- a/sdk/extensions/physx/include/NvBlastExtPxManager.h
+++ b/sdk/extensions/physx/include/NvBlastExtPxManager.h
@@ -39,6 +39,7 @@
namespace physx
{
class PxPhysics;
+class PxCooking;
class PxRigidDynamic;
class PxJoint;
@@ -46,7 +47,7 @@ namespace general_PxIOStream2
{
class PxFileBuf;
}
-}
+} // namespace physx
namespace Nv
@@ -63,6 +64,7 @@ class TkFamily;
class TkFramework;
class TkGroup;
class TkJoint;
+class ExtPxCollisionBuilder;
/**
@@ -72,9 +74,10 @@ Used to create Physics Family.
*/
struct ExtPxFamilyDesc
{
- ExtPxAsset* pxAsset; //!< px asset to create from, pointer will be stored in family.
- const NvBlastActorDesc* actorDesc; //!< actor descriptor to be used when creating TkActor. If nullptr, default NvBlastActorDesc from ExtPxAsset will be used.
- TkGroup* group; //!< if not nullptr, created TkActor will be placed in group
+ ExtPxAsset* pxAsset; //!< px asset to create from, pointer will be stored in family.
+ const NvBlastActorDesc* actorDesc; //!< actor descriptor to be used when creating TkActor. If nullptr, default
+ //!< NvBlastActorDesc from ExtPxAsset will be used.
+ TkGroup* group; //!< if not nullptr, created TkActor will be placed in group
};
@@ -83,7 +86,9 @@ Function pointer for PxJoint creation.
It will be called when new joints are being created. It should return valid PxJoint pointer or nullptr.
*/
-typedef physx::PxJoint*(*ExtPxCreateJointFunction)(ExtPxActor* actor0, const physx::PxTransform& localFrame0, ExtPxActor* actor1, const physx::PxTransform& localFrame1, physx::PxPhysics& physics, TkJoint& joint);
+typedef physx::PxJoint* (*ExtPxCreateJointFunction)(ExtPxActor* actor0, const physx::PxTransform& localFrame0,
+ ExtPxActor* actor1, const physx::PxTransform& localFrame1,
+ physx::PxPhysics& physics, TkJoint& joint);
/**
@@ -93,7 +98,7 @@ Used to create and manage Physics Families.
*/
class NV_DLL_EXPORT ExtPxManager
{
-public:
+ public:
//////// manager creation ////////
/**
@@ -101,18 +106,25 @@ public:
\param[in] physics The PxPhysics instance to be used by ExtPxManager.
\param[in] framework The TkFramework instance to be used by ExtPxManager.
+ \param[in] cooking The optional PxCooking. Required for collision builder.
\param[in] createFn The function to be used when creating joints, can be nullptr.
- \param[in] useUserData Flag if ExtPxManager is allowed to override PxActor's userData, it will store pointer to PxActor there.
- It is recommended as fastest way. If set to 'false' HashMap will be used.
+ \param[in] useUserData Flag if ExtPxManager is allowed to override PxActor's userData, it will store pointer to
+ PxActor there. It is recommended as fastest way. If set to 'false' HashMap will be used.
\return the new ExtPxManager if successful, NULL otherwise.
*/
- static ExtPxManager* create(physx::PxPhysics& physics, TkFramework& framework, ExtPxCreateJointFunction createFn = nullptr, bool useUserData = true);
+ static ExtPxManager* create(physx::PxPhysics& physics, TkFramework& framework,
+ ExtPxCreateJointFunction createFn = nullptr, bool useUserData = true);
+
+ /**
+ Create PhysX based convex mesh builder.
+ */
+ static ExtPxCollisionBuilder* createCollisionBuilder(physx::PxPhysics& physics, physx::PxCooking& cooking);
/**
Release this manager.
*/
- virtual void release() = 0;
+ virtual void release() = 0;
//////// impact ////////
@@ -133,9 +145,10 @@ public:
\param[in] desc The family descriptor (see ExtPxFamilyDesc).
- \return the created family, if the descriptor was valid and memory was available for the operation. Otherwise, returns NULL.
+ \return the created family, if the descriptor was valid and memory was available for the operation. Otherwise,
+ returns NULL.
*/
- virtual ExtPxFamily* createFamily(const ExtPxFamilyDesc& desc) = 0;
+ virtual ExtPxFamily* createFamily(const ExtPxFamilyDesc& desc) = 0;
/**
Create a px joint associated with TkJoint.
@@ -147,28 +160,28 @@ public:
\return true iff Joint was created.
*/
- virtual bool createJoint(TkJoint& joint) = 0;
+ virtual bool createJoint(TkJoint& joint) = 0;
/**
Destroy a px joint associated with TkJoint.
\param[in] joint TkJoint to be used to destroy px joint.
*/
- virtual void destroyJoint(TkJoint& joint) = 0;
+ virtual void destroyJoint(TkJoint& joint) = 0;
/**
Set ExtPxCreateJointFunction to be used when new joints are being created.\
\param[in] createFn Create function pointer to set, can be nullptr.
*/
- virtual void setCreateJointFunction(ExtPxCreateJointFunction createFn) = 0;
+ virtual void setCreateJointFunction(ExtPxCreateJointFunction createFn) = 0;
/**
The number of families currently in this manager.
\return the number of ExtPxFamily that currently exist in this manger.
*/
- virtual uint32_t getFamilyCount() const = 0;
+ virtual uint32_t getFamilyCount() const = 0;
/**
Retrieve an array of pointers (into the user-supplied buffer) to families.
@@ -178,7 +191,7 @@ public:
\return the number of ExtPxFamily pointers written to the buffer.
*/
- virtual uint32_t getFamilies(ExtPxFamily** buffer, uint32_t bufferSize) const = 0;
+ virtual uint32_t getFamilies(ExtPxFamily** buffer, uint32_t bufferSize) const = 0;
/**
Look up an associated ExtPxFamily by TkFamily pointer.
@@ -187,7 +200,7 @@ public:
\return pointer to the ExtPxFamily object if it exists, NULL otherwise.
*/
- virtual ExtPxFamily* getFamilyFromTkFamily(TkFamily& family) const = 0;
+ virtual ExtPxFamily* getFamilyFromTkFamily(TkFamily& family) const = 0;
/**
Look up an associated ExtPxActor by PxRigidDynamic pointer.
@@ -196,68 +209,69 @@ public:
\return pointer to the ExtPxActor object if it exists, NULL otherwise.
*/
- virtual ExtPxActor* getActorFromPhysXActor(const physx::PxRigidDynamic& pxActor) const = 0;
+ virtual ExtPxActor* getActorFromPhysXActor(const physx::PxRigidDynamic& pxActor) const = 0;
/**
Get a PxPhysics object pointer used upon manager creation.
\return a pointer to the (const) PxPhysics object.
*/
- virtual physx::PxPhysics& getPhysics() const = 0;
+ virtual physx::PxPhysics& getPhysics() const = 0;
/**
Get a TkFramework object pointer used upon manager creation.
\return a pointer to the TkFramework object.
*/
- virtual TkFramework& getFramework() const = 0;
+ virtual TkFramework& getFramework() const = 0;
/**
Get if useUserData was set upon manager creation.
\return true iff PxActor userData is used by manager.
*/
- virtual bool isPxUserDataUsed() const = 0;
+ virtual bool isPxUserDataUsed() const = 0;
/**
Limits the total number of actors that can exist at a given time. A value of zero disables this (gives no limit).
\param[in] limit If not zero, the maximum number of actors that will be allowed to exist.
*/
- virtual void setActorCountLimit(uint32_t limit) = 0;
+ virtual void setActorCountLimit(uint32_t limit) = 0;
/**
- Retrieve the limit to the total number of actors that can exist at a given time. A value of zero disables this (gives no limit).
+ Retrieve the limit to the total number of actors that can exist at a given time. A value of zero disables this
+ (gives no limit).
\return the limit to the total number of actors that can exist at a given time (or zero if there is no limit).
*/
- virtual uint32_t getActorCountLimit() = 0;
+ virtual uint32_t getActorCountLimit() = 0;
/**
The total number of PxActors generated by Blast.
\return the total number of PxActors generated by Blast.
*/
- virtual uint32_t getPxActorCount() const = 0;
+ virtual uint32_t getPxActorCount() const = 0;
/**
Add a user implementation of ExtPxListener to this family's list of listeners.
\param[in] listener The event listener to add.
*/
- virtual void subscribe(ExtPxListener& listener) = 0;
+ virtual void subscribe(ExtPxListener& listener) = 0;
/**
Remove a user implementation of ExtPxListener from this family's list of listeners.
\param[in] listener The event listener to remove.
*/
- virtual void unsubscribe(ExtPxListener& listener) = 0;
+ virtual void unsubscribe(ExtPxListener& listener) = 0;
};
-} // namespace Blast
-} // namespace Nv
+} // namespace Blast
+} // namespace Nv
-#endif // ifndef NVBLASTEXTPXMANAGER_H
+#endif // ifndef NVBLASTEXTPXMANAGER_H
diff --git a/sdk/extensions/physx/source/physics/NvBlastExtPxCollisionBuilderImpl.cpp b/sdk/extensions/physx/source/physics/NvBlastExtPxCollisionBuilderImpl.cpp
new file mode 100644
index 0000000..4f653a7
--- /dev/null
+++ b/sdk/extensions/physx/source/physics/NvBlastExtPxCollisionBuilderImpl.cpp
@@ -0,0 +1,232 @@
+// 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) 2016-2018 NVIDIA Corporation. All rights reserved.
+
+#include <NvBlastGlobals.h>
+#include "NvBlastExtPxCollisionBuilderImpl.h"
+#include "NvBlastExtAuthoringTypes.h"
+#include "NvBlastExtPxAsset.h"
+#include <PxConvexMesh.h>
+#include "PxPhysics.h"
+#include "cooking/PxCooking.h"
+#include <NvBlastPxSharedHelpers.h>
+#include <vector>
+#include <set>
+
+using namespace physx;
+
+#define SAFE_ARRAY_NEW(T, x) ((x) > 0) ? reinterpret_cast<T*>(NVBLAST_ALLOC(sizeof(T) * (x))) : nullptr;
+#define SAFE_ARRAY_DELETE(x) \
+ if (x != nullptr) \
+ { \
+ NVBLAST_FREE(x); \
+ x = nullptr; \
+ }
+
+namespace Nv
+{
+namespace Blast
+{
+
+CollisionHullImpl::~CollisionHullImpl()
+{
+ SAFE_ARRAY_DELETE(points);
+ SAFE_ARRAY_DELETE(indices);
+ SAFE_ARRAY_DELETE(polygonData);
+}
+
+CollisionHullImpl::CollisionHullImpl(const CollisionHull& hullToCopy)
+{
+ pointsCount = hullToCopy.pointsCount;
+ indicesCount = hullToCopy.indicesCount;
+ polygonDataCount = hullToCopy.polygonDataCount;
+
+ points = SAFE_ARRAY_NEW(NvcVec3, pointsCount);
+ indices = SAFE_ARRAY_NEW(uint32_t, indicesCount);
+ polygonData = SAFE_ARRAY_NEW(HullPolygon, polygonDataCount);
+ memcpy(points, hullToCopy.points, sizeof(points[0]) * pointsCount);
+ memcpy(indices, hullToCopy.indices, sizeof(indices[0]) * indicesCount);
+ memcpy(polygonData, hullToCopy.polygonData, sizeof(polygonData[0]) * polygonDataCount);
+}
+
+CollisionHull* ExtPxCollisionBuilderImpl::buildCollisionGeometry(uint32_t verticesCount, const NvcVec3* vData)
+{
+ CollisionHull* output = new CollisionHullImpl();
+ std::vector<physx::PxVec3> vertexData(verticesCount);
+ memcpy(vertexData.data(), vData, sizeof(physx::PxVec3) * verticesCount);
+
+ PxConvexMeshDesc convexMeshDescr;
+ PxConvexMesh* resultConvexMesh;
+ PxBounds3 bounds;
+ // Scale chunk to unit cube size, to avoid numerical errors
+ bounds.setEmpty();
+ for (uint32_t i = 0; i < vertexData.size(); ++i)
+ {
+ bounds.include(vertexData[i]);
+ }
+ PxVec3 bbCenter = bounds.getCenter();
+ float scale = PxMax(PxAbs(bounds.getExtents(0)), PxMax(PxAbs(bounds.getExtents(1)), PxAbs(bounds.getExtents(2))));
+ for (uint32_t i = 0; i < vertexData.size(); ++i)
+ {
+ vertexData[i] = vertexData[i] - bbCenter;
+ vertexData[i] *= (1.0f / scale);
+ }
+ bounds.setEmpty();
+ for (uint32_t i = 0; i < vertexData.size(); ++i)
+ {
+ bounds.include(vertexData[i]);
+ }
+ convexMeshDescr.points.data = vertexData.data();
+ convexMeshDescr.points.stride = sizeof(PxVec3);
+ convexMeshDescr.points.count = (uint32_t)vertexData.size();
+ convexMeshDescr.flags = PxConvexFlag::eCOMPUTE_CONVEX;
+ resultConvexMesh = mCooking->createConvexMesh(convexMeshDescr, *mInsertionCallback);
+ if (!resultConvexMesh)
+ {
+ vertexData.clear();
+ vertexData.push_back(bounds.minimum);
+ vertexData.push_back(PxVec3(bounds.minimum.x, bounds.maximum.y, bounds.minimum.z));
+ vertexData.push_back(PxVec3(bounds.maximum.x, bounds.maximum.y, bounds.minimum.z));
+ vertexData.push_back(PxVec3(bounds.maximum.x, bounds.minimum.y, bounds.minimum.z));
+ vertexData.push_back(PxVec3(bounds.minimum.x, bounds.minimum.y, bounds.maximum.z));
+ vertexData.push_back(PxVec3(bounds.minimum.x, bounds.maximum.y, bounds.maximum.z));
+ vertexData.push_back(PxVec3(bounds.maximum.x, bounds.maximum.y, bounds.maximum.z));
+ vertexData.push_back(PxVec3(bounds.maximum.x, bounds.minimum.y, bounds.maximum.z));
+ convexMeshDescr.points.data = vertexData.data();
+ convexMeshDescr.points.count = (uint32_t)vertexData.size();
+ resultConvexMesh = mCooking->createConvexMesh(convexMeshDescr, *mInsertionCallback);
+ }
+ output->polygonDataCount = resultConvexMesh->getNbPolygons();
+ if (output->polygonDataCount)
+ output->polygonData = SAFE_ARRAY_NEW(HullPolygon, output->polygonDataCount);
+ output->pointsCount = resultConvexMesh->getNbVertices();
+ output->points = SAFE_ARRAY_NEW(NvcVec3, output->pointsCount);
+ int32_t indicesCount = 0;
+ PxHullPolygon hPoly;
+ for (uint32_t i = 0; i < resultConvexMesh->getNbPolygons(); ++i)
+ {
+ HullPolygon& pd = output->polygonData[i];
+ resultConvexMesh->getPolygonData(i, hPoly);
+ pd.indexBase = hPoly.mIndexBase;
+ pd.vertexCount = hPoly.mNbVerts;
+ pd.plane[0] = hPoly.mPlane[0];
+ pd.plane[1] = hPoly.mPlane[1];
+ pd.plane[2] = hPoly.mPlane[2];
+ pd.plane[3] = hPoly.mPlane[3];
+
+ pd.plane[0] /= scale;
+ pd.plane[1] /= scale;
+ pd.plane[2] /= scale;
+ pd.plane[3] -= (pd.plane[0] * bbCenter.x + pd.plane[1] * bbCenter.y + pd.plane[2] * bbCenter.z);
+ float length = sqrt(pd.plane[0] * pd.plane[0] + pd.plane[1] * pd.plane[1] + pd.plane[2] * pd.plane[2]);
+ pd.plane[0] /= length;
+ pd.plane[1] /= length;
+ pd.plane[2] /= length;
+ pd.plane[3] /= length;
+ indicesCount = PxMax(indicesCount, pd.indexBase + pd.vertexCount);
+ }
+ output->indicesCount = indicesCount;
+ output->indices = SAFE_ARRAY_NEW(uint32_t, indicesCount);
+ for (uint32_t i = 0; i < resultConvexMesh->getNbVertices(); ++i)
+ {
+ PxVec3 p = resultConvexMesh->getVertices()[i] * scale + bbCenter;
+ output->points[i] = fromPxShared(p);
+ }
+ for (int32_t i = 0; i < indicesCount; ++i)
+ {
+ output->indices[i] = resultConvexMesh->getIndexBuffer()[i];
+ }
+ resultConvexMesh->release();
+ return output;
+}
+
+void ExtPxCollisionBuilderImpl::releaseCollisionHull(Nv::Blast::CollisionHull* ch) const
+{
+ if (ch)
+ {
+ SAFE_ARRAY_DELETE(ch->indices);
+ SAFE_ARRAY_DELETE(ch->points);
+ SAFE_ARRAY_DELETE(ch->polygonData);
+ delete ch;
+ }
+}
+
+physx::PxConvexMesh* ExtPxCollisionBuilderImpl::buildConvexMesh(const CollisionHull& hull)
+{
+ /* PxCooking::createConvexMesh expects PxHullPolygon input, which matches HullPolygon */
+ static_assert(sizeof(PxHullPolygon) == sizeof(HullPolygon), "HullPolygon size mismatch");
+ static_assert(offsetof(PxHullPolygon, mPlane) == offsetof(HullPolygon, plane), "HullPolygon layout mismatch");
+ static_assert(offsetof(PxHullPolygon, mNbVerts) == offsetof(HullPolygon, vertexCount), "HullPolygon layout mismatch");
+ static_assert(offsetof(PxHullPolygon, mIndexBase) == offsetof(HullPolygon, indexBase),
+ "HullPolygon layout mismatch");
+
+ PxConvexMeshDesc convexMeshDescr;
+ convexMeshDescr.indices.data = hull.indices;
+ convexMeshDescr.indices.count = (uint32_t)hull.indicesCount;
+ convexMeshDescr.indices.stride = sizeof(uint32_t);
+
+ convexMeshDescr.points.data = hull.points;
+ convexMeshDescr.points.count = (uint32_t)hull.pointsCount;
+ convexMeshDescr.points.stride = sizeof(PxVec3);
+
+ convexMeshDescr.polygons.data = hull.polygonData;
+ convexMeshDescr.polygons.count = (uint32_t)hull.polygonDataCount;
+ convexMeshDescr.polygons.stride = sizeof(PxHullPolygon);
+
+ return mCooking->createConvexMesh(convexMeshDescr, *mInsertionCallback);
+}
+
+void ExtPxCollisionBuilderImpl::buildPhysicsChunks(uint32_t chunkCount, uint32_t* hullOffsets,
+ CollisionHull** hulls, ExtPxChunk* physicsChunks,
+ ExtPxSubchunk* physicsSubchunks)
+{
+ //Nv::Blast::AuthoringResult& result = *ar;
+ //uint32_t chunkCount = (uint32_t)result.chunkCount;
+ //uint32_t* hullOffsets = result.collisionHullOffset;
+ //CollisionHull** hulls = result.collisionHull;
+ for (uint32_t i = 0; i < chunkCount; ++i)
+ {
+ int32_t beg = hullOffsets[i];
+ int32_t end = hullOffsets[i + 1];
+ for (int32_t subhull = beg; subhull < end; ++subhull)
+ {
+ physicsSubchunks[subhull].transform = physx::PxTransform(physx::PxIdentity);
+ physicsSubchunks[subhull].geometry = physx::PxConvexMeshGeometry(
+ reinterpret_cast<physx::PxConvexMesh*>(buildConvexMesh(*hulls[subhull])));
+ }
+ physicsChunks[i].isStatic = false;
+ physicsChunks[i].subchunkCount = static_cast<uint32_t>(end - beg);
+ physicsChunks[i].firstSubchunkIndex = beg;
+ }
+}
+
+void ExtPxCollisionBuilderImpl::release()
+{
+ NVBLAST_DELETE(this, ExtPxCollisionBuilderImpl);
+}
+
+} // namespace Blast
+} // namespace Nv
diff --git a/sdk/extensions/physx/source/physics/NvBlastExtPxCollisionBuilderImpl.h b/sdk/extensions/physx/source/physics/NvBlastExtPxCollisionBuilderImpl.h
new file mode 100644
index 0000000..9fb5c5e
--- /dev/null
+++ b/sdk/extensions/physx/source/physics/NvBlastExtPxCollisionBuilderImpl.h
@@ -0,0 +1,74 @@
+// 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) 2016-2018 NVIDIA Corporation. All rights reserved.
+
+
+#ifndef NVBLASTEXTPXCOLLISIONBUILDERIMPL_H
+#define NVBLASTEXTPXCOLLISIONBUILDERIMPL_H
+
+#include "NvBlastExtPxCollisionBuilder.h"
+#include "NvBlastExtAuthoringTypes.h"
+
+namespace physx
+{
+ class PxCooking;
+ class PxPhysicsInsertionCallback;
+}
+namespace Nv
+{
+ namespace Blast
+ {
+
+ struct CollisionHullImpl : public CollisionHull
+ {
+ CollisionHullImpl() {};
+ CollisionHullImpl(const CollisionHull& hullToCopy);
+ ~CollisionHullImpl();
+ };
+
+ class ExtPxCollisionBuilderImpl : public ExtPxCollisionBuilder
+ {
+ public:
+ ExtPxCollisionBuilderImpl(physx::PxCooking* cooking,
+ physx::PxPhysicsInsertionCallback* insertionCallback) : mCooking(cooking), mInsertionCallback(insertionCallback) {}
+ virtual ~ExtPxCollisionBuilderImpl() {};
+ void release() override;
+ CollisionHull* buildCollisionGeometry(uint32_t verticesCount, const NvcVec3* vertexData) override;
+ void releaseCollisionHull(CollisionHull* hull) const override;
+
+ physx::PxConvexMesh* buildConvexMesh(const CollisionHull& hull) override;
+ void buildPhysicsChunks(uint32_t chunkCount, uint32_t* hullOffsets, CollisionHull** hulls,
+ ExtPxChunk* physicsChunks, ExtPxSubchunk* physicsSubchunks) override;
+ private:
+ physx::PxCooking* mCooking;
+ physx::PxPhysicsInsertionCallback* mInsertionCallback;
+ };
+
+ } // namespace Blast
+} // namespace Nv
+
+
+#endif // ifndef NVBLASTEXTPXCOLLISIONBUILDERIMPL_H
diff --git a/sdk/extensions/physx/source/physics/NvBlastExtPxManagerImpl.cpp b/sdk/extensions/physx/source/physics/NvBlastExtPxManagerImpl.cpp
index 018ff74..223d5f3 100755
--- a/sdk/extensions/physx/source/physics/NvBlastExtPxManagerImpl.cpp
+++ b/sdk/extensions/physx/source/physics/NvBlastExtPxManagerImpl.cpp
@@ -29,6 +29,7 @@
#include "NvBlastExtPxManagerImpl.h"
#include "NvBlastExtPxAssetImpl.h"
#include "NvBlastExtPxActorImpl.h"
+#include "NvBlastExtPxCollisionBuilderImpl.h"
#include "NvBlastExtPxFamilyImpl.h"
#include "NvBlastAssert.h"
@@ -38,6 +39,7 @@
#include "NvBlastTkGroup.h"
#include "NvBlastTkJoint.h"
+#include "PxPhysics.h"
#include "PxRigidDynamic.h"
#include "PxJoint.h"
@@ -53,6 +55,11 @@ ExtPxManager* ExtPxManager::create(PxPhysics& physics, TkFramework& framework, E
return NVBLAST_NEW(ExtPxManagerImpl)(physics, framework, createFn, useUserData);
}
+ExtPxCollisionBuilder* ExtPxManager::createCollisionBuilder(PxPhysics& physics, PxCooking& cooking)
+{
+ return NVBLAST_NEW(ExtPxCollisionBuilderImpl(&cooking, &physics.getPhysicsInsertionCallback()));
+}
+
void ExtPxManagerImpl::release()
{
NVBLAST_DELETE(this, ExtPxManagerImpl);
diff --git a/sdk/extensions/physx/source/physics/NvBlastExtPxStressSolverImpl.cpp b/sdk/extensions/physx/source/physics/NvBlastExtPxStressSolverImpl.cpp
index b18df25..308c4ae 100755
--- a/sdk/extensions/physx/source/physics/NvBlastExtPxStressSolverImpl.cpp
+++ b/sdk/extensions/physx/source/physics/NvBlastExtPxStressSolverImpl.cpp
@@ -37,6 +37,8 @@
#include "NvBlastTkActor.h"
#include "NvBlastTkFamily.h"
+#include "NvBlastPxSharedHelpers.h"
+
#include "PxScene.h"
#include "PxRigidDynamic.h"
@@ -130,7 +132,7 @@ ExtPxStressSolverImpl::ExtPxStressSolverImpl(ExtPxFamily& family, ExtStressSolve
localPos = PxVec3(PxZero);
isChunkStatic = true;
}
- m_solver->setNodeInfo(node0, mass, volume, localPos, isChunkStatic);
+ m_solver->setNodeInfo(node0, mass, volume, fromPxShared(localPos), isChunkStatic);
}
#else
m_solver->setAllNodesInfoFromLL();
@@ -182,13 +184,13 @@ void ExtPxStressSolverImpl::update(bool doDamage)
PxVec3 gravity = rigidDynamic.getScene()->getGravity();
PxVec3 localGravity = rigidDynamic.getGlobalPose().rotateInv(gravity);
- m_solver->addGravityForce(*actor->getTkActor().getActorLL(), localGravity);
+ m_solver->addGravityForce(*actor->getTkActor().getActorLL(), fromPxShared(localGravity));
}
else
{
PxVec3 localCenterMass = rigidDynamic.getCMassLocalPose().p;
PxVec3 localAngularVelocity = rigidDynamic.getGlobalPose().rotateInv(rigidDynamic.getAngularVelocity());
- m_solver->addAngularVelocity(*actor->getTkActor().getActorLL(), localCenterMass, localAngularVelocity);
+ m_solver->addAngularVelocity(*actor->getTkActor().getActorLL(), fromPxShared(localCenterMass), fromPxShared(localAngularVelocity));
}
}