aboutsummaryrefslogtreecommitdiff
path: root/samples/SampleBase/blast
diff options
context:
space:
mode:
Diffstat (limited to 'samples/SampleBase/blast')
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastAsset.cpp174
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastAsset.h262
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastAssetBoxes.cpp204
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastAssetBoxes.h146
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastAssetModel.cpp468
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastAssetModel.h146
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastAssetModelSimple.cpp136
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastAssetModelSimple.h128
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastAssetModelSkinned.cpp120
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastAssetModelSkinned.h126
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastController.cpp1066
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastController.h618
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastFamily.cpp1166
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastFamily.h462
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastFamilyBoxes.cpp218
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastFamilyBoxes.h108
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastFamilyModelSimple.cpp708
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastFamilyModelSimple.h138
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastFamilyModelSkinned.cpp370
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastFamilyModelSkinned.h160
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastModel.cpp504
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastModel.h146
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastReplay.cpp356
-rwxr-xr-x[-rw-r--r--]samples/SampleBase/blast/BlastReplay.h184
24 files changed, 4057 insertions, 4057 deletions
diff --git a/samples/SampleBase/blast/BlastAsset.cpp b/samples/SampleBase/blast/BlastAsset.cpp
index 05e411a..5e7abd1 100644..100755
--- a/samples/SampleBase/blast/BlastAsset.cpp
+++ b/samples/SampleBase/blast/BlastAsset.cpp
@@ -1,87 +1,87 @@
-// 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-2018 NVIDIA Corporation. All rights reserved.
-
-
-#include "BlastAsset.h"
-#include "NvBlastExtPxAsset.h"
-#include "NvBlastTkAsset.h"
-#include "NvBlastExtDamageShaders.h"
-#include <algorithm>
-
-
-BlastAsset::BlastAsset(Renderer& renderer)
- : m_renderer(renderer), m_bondHealthMax(1.0f), m_supportChunkHealthMax(1.0f), m_damageAccelerator(nullptr)
-{
-}
-
-BlastAsset::~BlastAsset()
-{
- if (m_damageAccelerator)
- {
- m_damageAccelerator->release();
- }
-}
-
-void BlastAsset::initialize()
-{
- // calc max healths
- const auto& actorDesc = m_pxAsset->getDefaultActorDesc();
- if (actorDesc.initialBondHealths)
- {
- m_bondHealthMax = FLT_MIN;
- const uint32_t bondCount = m_pxAsset->getTkAsset().getBondCount();
- for (uint32_t i = 0; i < bondCount; ++i)
- {
- m_bondHealthMax = std::max<float>(m_bondHealthMax, actorDesc.initialBondHealths[i]);
- }
- }
- else
- {
- m_bondHealthMax = actorDesc.uniformInitialBondHealth;
- }
-
- if(actorDesc.initialSupportChunkHealths)
- {
- m_supportChunkHealthMax = FLT_MIN;
- const uint32_t nodeCount = m_pxAsset->getTkAsset().getGraph().nodeCount;
- for (uint32_t i = 0; i < nodeCount; ++i)
- {
- m_supportChunkHealthMax = std::max<float>(m_supportChunkHealthMax, actorDesc.initialSupportChunkHealths[i]);
- }
- }
- else
- {
- m_supportChunkHealthMax = actorDesc.uniformInitialLowerSupportChunkHealth;
- }
-
- m_damageAccelerator = NvBlastExtDamageAcceleratorCreate(m_pxAsset->getTkAsset().getAssetLL(), 3);
-}
-
-size_t BlastAsset::getBlastAssetSize() const
-{
- return m_pxAsset->getTkAsset().getDataSize();
-}
+// 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-2018 NVIDIA Corporation. All rights reserved.
+
+
+#include "BlastAsset.h"
+#include "NvBlastExtPxAsset.h"
+#include "NvBlastTkAsset.h"
+#include "NvBlastExtDamageShaders.h"
+#include <algorithm>
+
+
+BlastAsset::BlastAsset(Renderer& renderer)
+ : m_renderer(renderer), m_bondHealthMax(1.0f), m_supportChunkHealthMax(1.0f), m_damageAccelerator(nullptr)
+{
+}
+
+BlastAsset::~BlastAsset()
+{
+ if (m_damageAccelerator)
+ {
+ m_damageAccelerator->release();
+ }
+}
+
+void BlastAsset::initialize()
+{
+ // calc max healths
+ const auto& actorDesc = m_pxAsset->getDefaultActorDesc();
+ if (actorDesc.initialBondHealths)
+ {
+ m_bondHealthMax = FLT_MIN;
+ const uint32_t bondCount = m_pxAsset->getTkAsset().getBondCount();
+ for (uint32_t i = 0; i < bondCount; ++i)
+ {
+ m_bondHealthMax = std::max<float>(m_bondHealthMax, actorDesc.initialBondHealths[i]);
+ }
+ }
+ else
+ {
+ m_bondHealthMax = actorDesc.uniformInitialBondHealth;
+ }
+
+ if(actorDesc.initialSupportChunkHealths)
+ {
+ m_supportChunkHealthMax = FLT_MIN;
+ const uint32_t nodeCount = m_pxAsset->getTkAsset().getGraph().nodeCount;
+ for (uint32_t i = 0; i < nodeCount; ++i)
+ {
+ m_supportChunkHealthMax = std::max<float>(m_supportChunkHealthMax, actorDesc.initialSupportChunkHealths[i]);
+ }
+ }
+ else
+ {
+ m_supportChunkHealthMax = actorDesc.uniformInitialLowerSupportChunkHealth;
+ }
+
+ m_damageAccelerator = NvBlastExtDamageAcceleratorCreate(m_pxAsset->getTkAsset().getAssetLL(), 3);
+}
+
+size_t BlastAsset::getBlastAssetSize() const
+{
+ return m_pxAsset->getTkAsset().getDataSize();
+}
diff --git a/samples/SampleBase/blast/BlastAsset.h b/samples/SampleBase/blast/BlastAsset.h
index 9b2beb2..0fda6ac 100644..100755
--- a/samples/SampleBase/blast/BlastAsset.h
+++ b/samples/SampleBase/blast/BlastAsset.h
@@ -1,132 +1,132 @@
-// 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-2018 NVIDIA Corporation. All rights reserved.
-
-
-#ifndef BLAST_ASSET_H
-#define BLAST_ASSET_H
-
-#include <memory>
-#include "PxTransform.h"
-#include "NvBlastTypes.h"
-
-
-using namespace physx;
-
-class Renderer;
-class BlastFamily;
-class PhysXController;
-class NvBlastExtDamageAccelerator;
-
-namespace Nv
-{
-namespace Blast
-{
-class ExtPxFamily;
-class ExtPxAsset;
-class ExtPxManager;
-class TkGroup;
-}
-}
-
-using namespace Nv::Blast;
-
-typedef std::shared_ptr<BlastFamily> BlastFamilyPtr;
-
-
-class BlastAsset
-{
-public:
- //////// ctor ////////
-
- BlastAsset(Renderer& renderer);
- virtual ~BlastAsset();
-
-
- //////// desc ////////
-
- /**
- Descriptor with actor initial settings.
- */
- struct ActorDesc
- {
- NvBlastID id;
- PxTransform transform;
- TkGroup* group;
- };
-
-
- //////// abstract ////////
-
- virtual BlastFamilyPtr createFamily(PhysXController& physXConroller, ExtPxManager& pxManager, const ActorDesc& desc) = 0;
-
-
- //////// data getters ////////
-
- ExtPxAsset* getPxAsset() const
- {
- return m_pxAsset;
- }
-
- size_t getBlastAssetSize() const;
-
- float getBondHealthMax() const
- {
- return m_bondHealthMax;
- }
-
- float getSupportChunkHealthMax() const
- {
- return m_bondHealthMax;
- }
-
- NvBlastExtDamageAccelerator* getAccelerator() const
- {
- return m_damageAccelerator;
- }
-
-protected:
- //////// internal operations ////////
-
- void initialize();
-
-
- //////// input data ////////
-
- Renderer& m_renderer;
-
-
- //////// internal data ////////
-
- ExtPxAsset* m_pxAsset;
- float m_bondHealthMax;
- float m_supportChunkHealthMax;
- NvBlastExtDamageAccelerator* m_damageAccelerator;
-};
-
-
-
+// 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-2018 NVIDIA Corporation. All rights reserved.
+
+
+#ifndef BLAST_ASSET_H
+#define BLAST_ASSET_H
+
+#include <memory>
+#include "PxTransform.h"
+#include "NvBlastTypes.h"
+
+
+using namespace physx;
+
+class Renderer;
+class BlastFamily;
+class PhysXController;
+class NvBlastExtDamageAccelerator;
+
+namespace Nv
+{
+namespace Blast
+{
+class ExtPxFamily;
+class ExtPxAsset;
+class ExtPxManager;
+class TkGroup;
+}
+}
+
+using namespace Nv::Blast;
+
+typedef std::shared_ptr<BlastFamily> BlastFamilyPtr;
+
+
+class BlastAsset
+{
+public:
+ //////// ctor ////////
+
+ BlastAsset(Renderer& renderer);
+ virtual ~BlastAsset();
+
+
+ //////// desc ////////
+
+ /**
+ Descriptor with actor initial settings.
+ */
+ struct ActorDesc
+ {
+ NvBlastID id;
+ PxTransform transform;
+ TkGroup* group;
+ };
+
+
+ //////// abstract ////////
+
+ virtual BlastFamilyPtr createFamily(PhysXController& physXConroller, ExtPxManager& pxManager, const ActorDesc& desc) = 0;
+
+
+ //////// data getters ////////
+
+ ExtPxAsset* getPxAsset() const
+ {
+ return m_pxAsset;
+ }
+
+ size_t getBlastAssetSize() const;
+
+ float getBondHealthMax() const
+ {
+ return m_bondHealthMax;
+ }
+
+ float getSupportChunkHealthMax() const
+ {
+ return m_bondHealthMax;
+ }
+
+ NvBlastExtDamageAccelerator* getAccelerator() const
+ {
+ return m_damageAccelerator;
+ }
+
+protected:
+ //////// internal operations ////////
+
+ void initialize();
+
+
+ //////// input data ////////
+
+ Renderer& m_renderer;
+
+
+ //////// internal data ////////
+
+ ExtPxAsset* m_pxAsset;
+ float m_bondHealthMax;
+ float m_supportChunkHealthMax;
+ NvBlastExtDamageAccelerator* m_damageAccelerator;
+};
+
+
+
#endif //BLAST_ASSET_H \ No newline at end of file
diff --git a/samples/SampleBase/blast/BlastAssetBoxes.cpp b/samples/SampleBase/blast/BlastAssetBoxes.cpp
index b31e67c..0bb23b3 100644..100755
--- a/samples/SampleBase/blast/BlastAssetBoxes.cpp
+++ b/samples/SampleBase/blast/BlastAssetBoxes.cpp
@@ -1,102 +1,102 @@
-// 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-2018 NVIDIA Corporation. All rights reserved.
-
-
-#include "BlastAssetBoxes.h"
-#include "BlastFamilyBoxes.h"
-#include "NvBlastExtPxAsset.h"
-#include "PxPhysics.h"
-#include "cooking/PxCooking.h"
-
-
-BlastAssetBoxes::BlastAssetBoxes(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, Renderer& renderer, const Desc& desc)
- : BlastAsset(renderer)
-{
- // generate boxes slices procedurally
- CubeAssetGenerator::generate(m_generatorAsset, desc.generatorSettings);
-
- // asset desc / tk asset
- ExtPxAssetDesc assetDesc;
- assetDesc.chunkDescs = m_generatorAsset.solverChunks.data();
- assetDesc.chunkCount = (uint32_t)m_generatorAsset.solverChunks.size();
- assetDesc.bondDescs = m_generatorAsset.solverBonds.data();
- assetDesc.bondCount = (uint32_t)m_generatorAsset.solverBonds.size();
- std::vector<uint8_t> bondFlags(assetDesc.bondCount);
- std::fill(bondFlags.begin(), bondFlags.end(), desc.jointAllBonds ? 1 : 0);
- assetDesc.bondFlags = bondFlags.data();
-
- // box convex
- PxVec3 vertices[8] = { { -1, -1, -1 }, { -1, -1, 1 }, { -1, 1, -1 }, { -1, 1, 1 }, { 1, -1, -1 }, { 1, -1, 1 }, { 1, 1, -1 }, { 1, 1, 1 } };
- PxConvexMeshDesc convexMeshDesc;
- convexMeshDesc.points.count = 8;
- convexMeshDesc.points.data = vertices;
- convexMeshDesc.points.stride = sizeof(PxVec3);
- convexMeshDesc.flags = PxConvexFlag::eCOMPUTE_CONVEX;
- m_boxMesh = cooking.createConvexMesh(convexMeshDesc, physics.getPhysicsInsertionCallback());
-
- // prepare chunks
- const uint32_t chunkCount = (uint32_t)m_generatorAsset.solverChunks.size();
- std::vector<ExtPxAssetDesc::ChunkDesc> pxChunks(chunkCount);
- std::vector<ExtPxAssetDesc::SubchunkDesc> pxSubchunks;
- pxSubchunks.reserve(chunkCount);
- for (uint32_t i = 0; i < m_generatorAsset.solverChunks.size(); i++)
- {
- uint32_t chunkID = m_generatorAsset.solverChunks[i].userData;
- GeneratorAsset::BlastChunkCube& cube = m_generatorAsset.chunks[chunkID];
- PxVec3 position = *reinterpret_cast<PxVec3*>(&cube.position);
- PxVec3 extents = *reinterpret_cast<PxVec3*>(&cube.extents);
- ExtPxAssetDesc::ChunkDesc& chunk = pxChunks[chunkID];
- ExtPxAssetDesc::SubchunkDesc subchunk =
- {
- PxTransform(position),
- PxConvexMeshGeometry(m_boxMesh, PxMeshScale(extents / 2))
- };
- pxSubchunks.push_back(subchunk);
- chunk.subchunks = &pxSubchunks.back();
- chunk.subchunkCount = 1;
- chunk.isStatic = (position.y - (extents.y - desc.generatorSettings.extents.y) / 2) <= desc.staticHeight;
- }
-
- // create asset
- assetDesc.pxChunks = pxChunks.data();
- m_pxAsset = ExtPxAsset::create(assetDesc, framework);
-
- initialize();
-}
-
-
-BlastAssetBoxes::~BlastAssetBoxes()
-{
- m_boxMesh->release();
- m_pxAsset->release();
-}
-
-
-BlastFamilyPtr BlastAssetBoxes::createFamily(PhysXController& physXConroller, ExtPxManager& pxManager, const ActorDesc& desc)
-{
- return BlastFamilyPtr(new BlastFamilyBoxes(physXConroller, pxManager, m_renderer, *this, desc));
-}
+// 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-2018 NVIDIA Corporation. All rights reserved.
+
+
+#include "BlastAssetBoxes.h"
+#include "BlastFamilyBoxes.h"
+#include "NvBlastExtPxAsset.h"
+#include "PxPhysics.h"
+#include "cooking/PxCooking.h"
+
+
+BlastAssetBoxes::BlastAssetBoxes(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, Renderer& renderer, const Desc& desc)
+ : BlastAsset(renderer)
+{
+ // generate boxes slices procedurally
+ CubeAssetGenerator::generate(m_generatorAsset, desc.generatorSettings);
+
+ // asset desc / tk asset
+ ExtPxAssetDesc assetDesc;
+ assetDesc.chunkDescs = m_generatorAsset.solverChunks.data();
+ assetDesc.chunkCount = (uint32_t)m_generatorAsset.solverChunks.size();
+ assetDesc.bondDescs = m_generatorAsset.solverBonds.data();
+ assetDesc.bondCount = (uint32_t)m_generatorAsset.solverBonds.size();
+ std::vector<uint8_t> bondFlags(assetDesc.bondCount);
+ std::fill(bondFlags.begin(), bondFlags.end(), desc.jointAllBonds ? 1 : 0);
+ assetDesc.bondFlags = bondFlags.data();
+
+ // box convex
+ PxVec3 vertices[8] = { { -1, -1, -1 }, { -1, -1, 1 }, { -1, 1, -1 }, { -1, 1, 1 }, { 1, -1, -1 }, { 1, -1, 1 }, { 1, 1, -1 }, { 1, 1, 1 } };
+ PxConvexMeshDesc convexMeshDesc;
+ convexMeshDesc.points.count = 8;
+ convexMeshDesc.points.data = vertices;
+ convexMeshDesc.points.stride = sizeof(PxVec3);
+ convexMeshDesc.flags = PxConvexFlag::eCOMPUTE_CONVEX;
+ m_boxMesh = cooking.createConvexMesh(convexMeshDesc, physics.getPhysicsInsertionCallback());
+
+ // prepare chunks
+ const uint32_t chunkCount = (uint32_t)m_generatorAsset.solverChunks.size();
+ std::vector<ExtPxAssetDesc::ChunkDesc> pxChunks(chunkCount);
+ std::vector<ExtPxAssetDesc::SubchunkDesc> pxSubchunks;
+ pxSubchunks.reserve(chunkCount);
+ for (uint32_t i = 0; i < m_generatorAsset.solverChunks.size(); i++)
+ {
+ uint32_t chunkID = m_generatorAsset.solverChunks[i].userData;
+ GeneratorAsset::BlastChunkCube& cube = m_generatorAsset.chunks[chunkID];
+ PxVec3 position = *reinterpret_cast<PxVec3*>(&cube.position);
+ PxVec3 extents = *reinterpret_cast<PxVec3*>(&cube.extents);
+ ExtPxAssetDesc::ChunkDesc& chunk = pxChunks[chunkID];
+ ExtPxAssetDesc::SubchunkDesc subchunk =
+ {
+ PxTransform(position),
+ PxConvexMeshGeometry(m_boxMesh, PxMeshScale(extents / 2))
+ };
+ pxSubchunks.push_back(subchunk);
+ chunk.subchunks = &pxSubchunks.back();
+ chunk.subchunkCount = 1;
+ chunk.isStatic = (position.y - (extents.y - desc.generatorSettings.extents.y) / 2) <= desc.staticHeight;
+ }
+
+ // create asset
+ assetDesc.pxChunks = pxChunks.data();
+ m_pxAsset = ExtPxAsset::create(assetDesc, framework);
+
+ initialize();
+}
+
+
+BlastAssetBoxes::~BlastAssetBoxes()
+{
+ m_boxMesh->release();
+ m_pxAsset->release();
+}
+
+
+BlastFamilyPtr BlastAssetBoxes::createFamily(PhysXController& physXConroller, ExtPxManager& pxManager, const ActorDesc& desc)
+{
+ return BlastFamilyPtr(new BlastFamilyBoxes(physXConroller, pxManager, m_renderer, *this, desc));
+}
diff --git a/samples/SampleBase/blast/BlastAssetBoxes.h b/samples/SampleBase/blast/BlastAssetBoxes.h
index 6603be4..0be8a74 100644..100755
--- a/samples/SampleBase/blast/BlastAssetBoxes.h
+++ b/samples/SampleBase/blast/BlastAssetBoxes.h
@@ -1,74 +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) 2008-2018 NVIDIA Corporation. All rights reserved.
-
-
-#ifndef BLAST_ASSET_BOXES_H
-#define BLAST_ASSET_BOXES_H
-
-#include "BlastAsset.h"
-#include "AssetGenerator.h"
-#include "PxConvexMesh.h"
-
-
-namespace physx
-{
-class PxPhysics;
-class PxCooking;
-}
-
-namespace Nv
-{
-namespace Blast
-{
-class TkFramework;
-}
-}
-
-
-class BlastAssetBoxes : public BlastAsset
-{
-public:
- struct Desc
- {
- CubeAssetGenerator::Settings generatorSettings;
- float staticHeight;
- bool jointAllBonds;
- };
-
- BlastAssetBoxes(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, Renderer& renderer, const Desc& desc);
- virtual ~BlastAssetBoxes();
-
- BlastFamilyPtr createFamily(PhysXController& physXConroller, ExtPxManager& pxManager, const ActorDesc& desc);
-
-private:
- PxConvexMesh* m_boxMesh;
- GeneratorAsset m_generatorAsset;
-};
-
-
-
+// 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-2018 NVIDIA Corporation. All rights reserved.
+
+
+#ifndef BLAST_ASSET_BOXES_H
+#define BLAST_ASSET_BOXES_H
+
+#include "BlastAsset.h"
+#include "AssetGenerator.h"
+#include "PxConvexMesh.h"
+
+
+namespace physx
+{
+class PxPhysics;
+class PxCooking;
+}
+
+namespace Nv
+{
+namespace Blast
+{
+class TkFramework;
+}
+}
+
+
+class BlastAssetBoxes : public BlastAsset
+{
+public:
+ struct Desc
+ {
+ CubeAssetGenerator::Settings generatorSettings;
+ float staticHeight;
+ bool jointAllBonds;
+ };
+
+ BlastAssetBoxes(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, Renderer& renderer, const Desc& desc);
+ virtual ~BlastAssetBoxes();
+
+ BlastFamilyPtr createFamily(PhysXController& physXConroller, ExtPxManager& pxManager, const ActorDesc& desc);
+
+private:
+ PxConvexMesh* m_boxMesh;
+ GeneratorAsset m_generatorAsset;
+};
+
+
+
#endif //BLAST_ASSET_BOXES_H \ No newline at end of file
diff --git a/samples/SampleBase/blast/BlastAssetModel.cpp b/samples/SampleBase/blast/BlastAssetModel.cpp
index 90888f6..942820a 100644..100755
--- a/samples/SampleBase/blast/BlastAssetModel.cpp
+++ b/samples/SampleBase/blast/BlastAssetModel.cpp
@@ -1,234 +1,234 @@
-// 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-2018 NVIDIA Corporation. All rights reserved.
-
-
-#include "BlastAssetModel.h"
-#include "Renderer.h"
-#include "BlastController.h"
-#include "Utils.h"
-#include "ResourceManager.h"
-#include "NvBlastExtPxAsset.h"
-#include <sstream>
-#include <fstream>
-#include "NvBlastExtExporter.h"
-#include "PxPhysics.h"
-#include <NvBlastGlobals.h>
-#include "NvBlastExtAssetUtils.h"
-#include "NvBlastExtPxAsset.h"
-#include "NvBlastTkAsset.h"
-#include "NvBlastExtSerialization.h"
-#include "NvBlastExtLlSerialization.h"
-#include "NvBlastExtTkSerialization.h"
-#include "NvBlastExtPxSerialization.h"
-#include "NvBlastExtAuthoring.h"
-#include "NvBlastExtAuthoringCollisionBuilder.h"
-
-BlastAssetModel::BlastAssetModel(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName)
- : BlastAsset(renderer)
-{
- const float unitConversion = 1.f;
-
- const NvcVec3 inputScale = { unitConversion, unitConversion, unitConversion };
-
- ResourceManager& resourceManager = m_renderer.getResourceManager();
- std::string path;
-
- // load obj file
- std::ostringstream objFileName;
- objFileName << modelName << ".obj";
-
- if (resourceManager.findFile(objFileName.str(), path))
- {
- m_model = BlastModel::loadFromFileTinyLoader(path.c_str());
- if (!m_model)
- {
- ASSERT_PRINT(false, "obj load failed");
- }
- }
- else // Obj is not found, try FBX
- {
- objFileName.clear();
- objFileName.str("");
- objFileName << modelName << ".fbx";
- if (resourceManager.findFile(objFileName.str(), path))
- {
- m_model = BlastModel::loadFromFbxFile(path.c_str());
- if (!m_model)
- {
- ASSERT_PRINT(false, "fbx load failed");
- }
-
- }
- else
- {
- ASSERT_PRINT(false, "mesh file not found");
- }
- }
-
- for (auto& chunk : m_model->chunks)
- {
- for (auto& mesh : chunk.meshes)
- {
- SimpleMesh& smesh = const_cast<SimpleMesh&>(mesh.mesh);
- smesh.center *= unitConversion;
- smesh.extents *= unitConversion;
- for (auto& vertex : smesh.vertices)
- {
- vertex.position *= unitConversion;
- }
- }
- }
-
- // Physics Asset
-
- // Read file into buffer
- std::ostringstream blastFileName;
- blastFileName << modelName << ".blast";
- if (resourceManager.findFile(blastFileName.str(), path))
- {
- std::ifstream stream(path.c_str(), std::ios::binary);
- std::streampos size = stream.tellg();
- stream.seekg(0, std::ios::end);
- size = stream.tellg() - size;
- stream.seekg(0, std::ios::beg);
- std::vector<char> buffer(size);
- stream.read(buffer.data(), buffer.size());
- stream.close();
- uint32_t objectTypeID;
- void* asset = serialization.deserializeFromBuffer(buffer.data(), buffer.size(), &objectTypeID);
- if (asset == nullptr)
- {
- ASSERT_PRINT(asset != nullptr, "can't load .blast file.");
- }
- else
- if (objectTypeID == Nv::Blast::ExtPxObjectTypeID::Asset)
- {
- m_pxAsset = reinterpret_cast<ExtPxAsset*>(asset);
- const TkAsset& tkAsset = m_pxAsset->getTkAsset();
- NvBlastAsset* llasset = const_cast<NvBlastAsset*>(tkAsset.getAssetLL());
- NvBlastExtAssetTransformInPlace(llasset, &inputScale, nullptr, nullptr);
- ExtPxSubchunk* subchunks = const_cast<ExtPxSubchunk*>(m_pxAsset->getSubchunks());
- for (uint32_t i = 0; i < m_pxAsset->getSubchunkCount(); ++i)
- {
- subchunks[i].geometry.scale.scale = PxVec3(unitConversion);
- }
- }
- else
- {
- TkAsset* tkAsset = nullptr;
- if (objectTypeID == Nv::Blast::TkObjectTypeID::Asset)
- {
- tkAsset = reinterpret_cast<TkAsset*>(asset);
- NvBlastAsset* llasset = const_cast<NvBlastAsset*>(tkAsset->getAssetLL());
- NvBlastExtAssetTransformInPlace(llasset, &inputScale, nullptr, nullptr);
- }
- else
- if (objectTypeID == Nv::Blast::LlObjectTypeID::Asset)
- {
- NvBlastAsset* llasset = reinterpret_cast<NvBlastAsset*>(asset);
- NvBlastExtAssetTransformInPlace(llasset, &inputScale, nullptr, nullptr);
- tkAsset = framework.createAsset(llasset, nullptr, 0, true);
- }
- else
- {
- ASSERT_PRINT(false, ".blast file contains unknown object.");
- }
-
- if (tkAsset != nullptr)
- {
- std::vector<ExtPxAssetDesc::ChunkDesc> physicsChunks;
- std::vector<std::vector<ExtPxAssetDesc::SubchunkDesc> > physicsSubchunks;
- /**
- Try find FBX and check whether it contains collision geometry.
- */
- objFileName.str("");
- objFileName << modelName << ".fbx";
- if (resourceManager.findFile(objFileName.str(), path))
- {
- std::shared_ptr<IFbxFileReader> rdr(NvBlastExtExporterCreateFbxFileReader(), [](IFbxFileReader* p) {p->release(); });
- rdr->loadFromFile(path.c_str());
- if (rdr->isCollisionLoaded() == 0)
- {
- ASSERT_PRINT(false, "fbx doesn't contain collision geometry");
- }
- uint32_t* hullsOffsets = nullptr;
- CollisionHull** hulls = nullptr;
- uint32_t meshCount = rdr->getCollision(hullsOffsets, hulls);
-
- /**
- Create physics meshes;
- */
- std::shared_ptr<Nv::Blast::ConvexMeshBuilder> collisionBuilder(
- NvBlastExtAuthoringCreateConvexMeshBuilder(&cooking, &physics.getPhysicsInsertionCallback()),
- [](Nv::Blast::ConvexMeshBuilder* cmb) {cmb->release(); });
-
- physicsChunks.resize(meshCount);
- physicsSubchunks.resize(meshCount);
-
- for (uint32_t i = 0; i < meshCount; ++i)
- {
- for (uint32_t sbHulls = hullsOffsets[i]; sbHulls < hullsOffsets[i+1]; ++sbHulls)
- {
- PxConvexMeshGeometry temp = physx::PxConvexMeshGeometry(collisionBuilder.get()->buildConvexMesh(*hulls[sbHulls]));
- if (temp.isValid())
- {
- physicsSubchunks[i].push_back(ExtPxAssetDesc::SubchunkDesc());
- physicsSubchunks[i].back().geometry = temp;
- physicsSubchunks[i].back().transform = physx::PxTransform(physx::PxIdentity);
- }
- }
- }
- for (uint32_t i = 0; i < meshCount; ++i)
- {
- physicsChunks[i].isStatic = false;
- physicsChunks[i].subchunkCount = (uint32_t)physicsSubchunks[i].size();
- physicsChunks[i].subchunks = physicsSubchunks[i].data();
- }
- if (hulls && hullsOffsets)
- {
- for (uint32_t h = 0; h < hullsOffsets[meshCount]; h++)
- {
- hulls[h]->release();
- }
- NVBLAST_FREE(hulls);
- NVBLAST_FREE(hullsOffsets);
- }
- }
- m_pxAsset = ExtPxAsset::create(tkAsset, physicsChunks.data(), (uint32_t)physicsChunks.size());
- ASSERT_PRINT(m_pxAsset != nullptr, "can't create asset");
- }
- }
- }
-
- initialize();
-}
-
-
-BlastAssetModel::~BlastAssetModel()
-{
- m_pxAsset->release();
-}
+// 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-2018 NVIDIA Corporation. All rights reserved.
+
+
+#include "BlastAssetModel.h"
+#include "Renderer.h"
+#include "BlastController.h"
+#include "Utils.h"
+#include "ResourceManager.h"
+#include "NvBlastExtPxAsset.h"
+#include <sstream>
+#include <fstream>
+#include "NvBlastExtExporter.h"
+#include "PxPhysics.h"
+#include <NvBlastGlobals.h>
+#include "NvBlastExtAssetUtils.h"
+#include "NvBlastExtPxAsset.h"
+#include "NvBlastTkAsset.h"
+#include "NvBlastExtSerialization.h"
+#include "NvBlastExtLlSerialization.h"
+#include "NvBlastExtTkSerialization.h"
+#include "NvBlastExtPxSerialization.h"
+#include "NvBlastExtAuthoring.h"
+#include "NvBlastExtAuthoringCollisionBuilder.h"
+
+BlastAssetModel::BlastAssetModel(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName)
+ : BlastAsset(renderer)
+{
+ const float unitConversion = 1.f;
+
+ const NvcVec3 inputScale = { unitConversion, unitConversion, unitConversion };
+
+ ResourceManager& resourceManager = m_renderer.getResourceManager();
+ std::string path;
+
+ // load obj file
+ std::ostringstream objFileName;
+ objFileName << modelName << ".obj";
+
+ if (resourceManager.findFile(objFileName.str(), path))
+ {
+ m_model = BlastModel::loadFromFileTinyLoader(path.c_str());
+ if (!m_model)
+ {
+ ASSERT_PRINT(false, "obj load failed");
+ }
+ }
+ else // Obj is not found, try FBX
+ {
+ objFileName.clear();
+ objFileName.str("");
+ objFileName << modelName << ".fbx";
+ if (resourceManager.findFile(objFileName.str(), path))
+ {
+ m_model = BlastModel::loadFromFbxFile(path.c_str());
+ if (!m_model)
+ {
+ ASSERT_PRINT(false, "fbx load failed");
+ }
+
+ }
+ else
+ {
+ ASSERT_PRINT(false, "mesh file not found");
+ }
+ }
+
+ for (auto& chunk : m_model->chunks)
+ {
+ for (auto& mesh : chunk.meshes)
+ {
+ SimpleMesh& smesh = const_cast<SimpleMesh&>(mesh.mesh);
+ smesh.center *= unitConversion;
+ smesh.extents *= unitConversion;
+ for (auto& vertex : smesh.vertices)
+ {
+ vertex.position *= unitConversion;
+ }
+ }
+ }
+
+ // Physics Asset
+
+ // Read file into buffer
+ std::ostringstream blastFileName;
+ blastFileName << modelName << ".blast";
+ if (resourceManager.findFile(blastFileName.str(), path))
+ {
+ std::ifstream stream(path.c_str(), std::ios::binary);
+ std::streampos size = stream.tellg();
+ stream.seekg(0, std::ios::end);
+ size = stream.tellg() - size;
+ stream.seekg(0, std::ios::beg);
+ std::vector<char> buffer(size);
+ stream.read(buffer.data(), buffer.size());
+ stream.close();
+ uint32_t objectTypeID;
+ void* asset = serialization.deserializeFromBuffer(buffer.data(), buffer.size(), &objectTypeID);
+ if (asset == nullptr)
+ {
+ ASSERT_PRINT(asset != nullptr, "can't load .blast file.");
+ }
+ else
+ if (objectTypeID == Nv::Blast::ExtPxObjectTypeID::Asset)
+ {
+ m_pxAsset = reinterpret_cast<ExtPxAsset*>(asset);
+ const TkAsset& tkAsset = m_pxAsset->getTkAsset();
+ NvBlastAsset* llasset = const_cast<NvBlastAsset*>(tkAsset.getAssetLL());
+ NvBlastExtAssetTransformInPlace(llasset, &inputScale, nullptr, nullptr);
+ ExtPxSubchunk* subchunks = const_cast<ExtPxSubchunk*>(m_pxAsset->getSubchunks());
+ for (uint32_t i = 0; i < m_pxAsset->getSubchunkCount(); ++i)
+ {
+ subchunks[i].geometry.scale.scale = PxVec3(unitConversion);
+ }
+ }
+ else
+ {
+ TkAsset* tkAsset = nullptr;
+ if (objectTypeID == Nv::Blast::TkObjectTypeID::Asset)
+ {
+ tkAsset = reinterpret_cast<TkAsset*>(asset);
+ NvBlastAsset* llasset = const_cast<NvBlastAsset*>(tkAsset->getAssetLL());
+ NvBlastExtAssetTransformInPlace(llasset, &inputScale, nullptr, nullptr);
+ }
+ else
+ if (objectTypeID == Nv::Blast::LlObjectTypeID::Asset)
+ {
+ NvBlastAsset* llasset = reinterpret_cast<NvBlastAsset*>(asset);
+ NvBlastExtAssetTransformInPlace(llasset, &inputScale, nullptr, nullptr);
+ tkAsset = framework.createAsset(llasset, nullptr, 0, true);
+ }
+ else
+ {
+ ASSERT_PRINT(false, ".blast file contains unknown object.");
+ }
+
+ if (tkAsset != nullptr)
+ {
+ std::vector<ExtPxAssetDesc::ChunkDesc> physicsChunks;
+ std::vector<std::vector<ExtPxAssetDesc::SubchunkDesc> > physicsSubchunks;
+ /**
+ Try find FBX and check whether it contains collision geometry.
+ */
+ objFileName.str("");
+ objFileName << modelName << ".fbx";
+ if (resourceManager.findFile(objFileName.str(), path))
+ {
+ std::shared_ptr<IFbxFileReader> rdr(NvBlastExtExporterCreateFbxFileReader(), [](IFbxFileReader* p) {p->release(); });
+ rdr->loadFromFile(path.c_str());
+ if (rdr->isCollisionLoaded() == 0)
+ {
+ ASSERT_PRINT(false, "fbx doesn't contain collision geometry");
+ }
+ uint32_t* hullsOffsets = nullptr;
+ CollisionHull** hulls = nullptr;
+ uint32_t meshCount = rdr->getCollision(hullsOffsets, hulls);
+
+ /**
+ Create physics meshes;
+ */
+ std::shared_ptr<Nv::Blast::ConvexMeshBuilder> collisionBuilder(
+ NvBlastExtAuthoringCreateConvexMeshBuilder(&cooking, &physics.getPhysicsInsertionCallback()),
+ [](Nv::Blast::ConvexMeshBuilder* cmb) {cmb->release(); });
+
+ physicsChunks.resize(meshCount);
+ physicsSubchunks.resize(meshCount);
+
+ for (uint32_t i = 0; i < meshCount; ++i)
+ {
+ for (uint32_t sbHulls = hullsOffsets[i]; sbHulls < hullsOffsets[i+1]; ++sbHulls)
+ {
+ PxConvexMeshGeometry temp = physx::PxConvexMeshGeometry(collisionBuilder.get()->buildConvexMesh(*hulls[sbHulls]));
+ if (temp.isValid())
+ {
+ physicsSubchunks[i].push_back(ExtPxAssetDesc::SubchunkDesc());
+ physicsSubchunks[i].back().geometry = temp;
+ physicsSubchunks[i].back().transform = physx::PxTransform(physx::PxIdentity);
+ }
+ }
+ }
+ for (uint32_t i = 0; i < meshCount; ++i)
+ {
+ physicsChunks[i].isStatic = false;
+ physicsChunks[i].subchunkCount = (uint32_t)physicsSubchunks[i].size();
+ physicsChunks[i].subchunks = physicsSubchunks[i].data();
+ }
+ if (hulls && hullsOffsets)
+ {
+ for (uint32_t h = 0; h < hullsOffsets[meshCount]; h++)
+ {
+ hulls[h]->release();
+ }
+ NVBLAST_FREE(hulls);
+ NVBLAST_FREE(hullsOffsets);
+ }
+ }
+ m_pxAsset = ExtPxAsset::create(tkAsset, physicsChunks.data(), (uint32_t)physicsChunks.size());
+ ASSERT_PRINT(m_pxAsset != nullptr, "can't create asset");
+ }
+ }
+ }
+
+ initialize();
+}
+
+
+BlastAssetModel::~BlastAssetModel()
+{
+ m_pxAsset->release();
+}
diff --git a/samples/SampleBase/blast/BlastAssetModel.h b/samples/SampleBase/blast/BlastAssetModel.h
index cdd5e42..cb76b75 100644..100755
--- a/samples/SampleBase/blast/BlastAssetModel.h
+++ b/samples/SampleBase/blast/BlastAssetModel.h
@@ -1,74 +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) 2008-2018 NVIDIA Corporation. All rights reserved.
-
-
-#ifndef BLAST_ASSET_MODEL_H
-#define BLAST_ASSET_MODEL_H
-
-#include "BlastAsset.h"
-#include "BlastModel.h"
-
-
-namespace physx
-{
-class PxPhysics;
-class PxCooking;
-}
-
-namespace Nv
-{
-namespace Blast
-{
-class TkFramework;
-class ExtSerialization;
-}
-}
-
-
-class BlastAssetModel : public BlastAsset
-{
-public:
- //////// ctor ////////
-
- BlastAssetModel(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName);
- virtual ~BlastAssetModel();
-
-
- //////// data getters ////////
-
- const BlastModel& getModel() const
- {
- return *m_model.get();
- }
-
-private:
- //////// private internal data ////////
-
- BlastModelPtr m_model;
-};
-
+// 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-2018 NVIDIA Corporation. All rights reserved.
+
+
+#ifndef BLAST_ASSET_MODEL_H
+#define BLAST_ASSET_MODEL_H
+
+#include "BlastAsset.h"
+#include "BlastModel.h"
+
+
+namespace physx
+{
+class PxPhysics;
+class PxCooking;
+}
+
+namespace Nv
+{
+namespace Blast
+{
+class TkFramework;
+class ExtSerialization;
+}
+}
+
+
+class BlastAssetModel : public BlastAsset
+{
+public:
+ //////// ctor ////////
+
+ BlastAssetModel(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName);
+ virtual ~BlastAssetModel();
+
+
+ //////// data getters ////////
+
+ const BlastModel& getModel() const
+ {
+ return *m_model.get();
+ }
+
+private:
+ //////// private internal data ////////
+
+ BlastModelPtr m_model;
+};
+
#endif //BLAST_ASSET_MODEL_H \ No newline at end of file
diff --git a/samples/SampleBase/blast/BlastAssetModelSimple.cpp b/samples/SampleBase/blast/BlastAssetModelSimple.cpp
index 7acc4fd..3af5b1f 100644..100755
--- a/samples/SampleBase/blast/BlastAssetModelSimple.cpp
+++ b/samples/SampleBase/blast/BlastAssetModelSimple.cpp
@@ -1,68 +1,68 @@
-// 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-2018 NVIDIA Corporation. All rights reserved.
-
-
-#include "BlastAssetModelSimple.h"
-#include "BlastFamilyModelSimple.h"
-#include "CustomRenderMesh.h"
-#include "Renderer.h"
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// BlastAssetModelSimple
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-BlastAssetModelSimple::BlastAssetModelSimple(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName)
- : BlastAssetModel(framework, physics, cooking, serialization, renderer, modelName)
-{
- // prepare materials
- for (const BlastModel::Material& material : getModel().materials)
- {
- if (material.diffuseTexture.empty())
- m_renderMaterials.push_back(new RenderMaterial(renderer.getResourceManager(), "model_simple"));
- else
- m_renderMaterials.push_back(new RenderMaterial(renderer.getResourceManager(), "model_simple_textured", material.diffuseTexture.c_str()));
- }
-
- initialize();
-}
-
-
-BlastAssetModelSimple::~BlastAssetModelSimple()
-{
- // release materials
- for (RenderMaterial* r : m_renderMaterials)
- {
- SAFE_DELETE(r);
- }
-}
-
-
-BlastFamilyPtr BlastAssetModelSimple::createFamily(PhysXController& physXConroller, ExtPxManager& pxManager, const ActorDesc& desc)
-{
- return BlastFamilyPtr(new BlastFamilyModelSimple(physXConroller, pxManager, m_renderer, *this, desc));
-}
+// 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-2018 NVIDIA Corporation. All rights reserved.
+
+
+#include "BlastAssetModelSimple.h"
+#include "BlastFamilyModelSimple.h"
+#include "CustomRenderMesh.h"
+#include "Renderer.h"
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// BlastAssetModelSimple
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+BlastAssetModelSimple::BlastAssetModelSimple(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName)
+ : BlastAssetModel(framework, physics, cooking, serialization, renderer, modelName)
+{
+ // prepare materials
+ for (const BlastModel::Material& material : getModel().materials)
+ {
+ if (material.diffuseTexture.empty())
+ m_renderMaterials.push_back(new RenderMaterial(renderer.getResourceManager(), "model_simple"));
+ else
+ m_renderMaterials.push_back(new RenderMaterial(renderer.getResourceManager(), "model_simple_textured", material.diffuseTexture.c_str()));
+ }
+
+ initialize();
+}
+
+
+BlastAssetModelSimple::~BlastAssetModelSimple()
+{
+ // release materials
+ for (RenderMaterial* r : m_renderMaterials)
+ {
+ SAFE_DELETE(r);
+ }
+}
+
+
+BlastFamilyPtr BlastAssetModelSimple::createFamily(PhysXController& physXConroller, ExtPxManager& pxManager, const ActorDesc& desc)
+{
+ return BlastFamilyPtr(new BlastFamilyModelSimple(physXConroller, pxManager, m_renderer, *this, desc));
+}
diff --git a/samples/SampleBase/blast/BlastAssetModelSimple.h b/samples/SampleBase/blast/BlastAssetModelSimple.h
index c226b02..1aa31e0 100644..100755
--- a/samples/SampleBase/blast/BlastAssetModelSimple.h
+++ b/samples/SampleBase/blast/BlastAssetModelSimple.h
@@ -1,65 +1,65 @@
-// 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-2018 NVIDIA Corporation. All rights reserved.
-
-
-#ifndef BLAST_ASSET_MODEL_SIMPLE_H
-#define BLAST_ASSET_MODEL_SIMPLE_H
-
-#include "BlastAssetModel.h"
-
-
-class RenderMaterial;
-
-class BlastAssetModelSimple : public BlastAssetModel
-{
-public:
- //////// ctor ////////
-
- BlastAssetModelSimple(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName);
- virtual ~BlastAssetModelSimple();
-
-
- //////// interface implementation ////////
-
- virtual BlastFamilyPtr createFamily(PhysXController& physXConroller, ExtPxManager& pxManager, const ActorDesc& desc);
-
-
- //////// data getters ////////
-
- const std::vector<RenderMaterial*>& getRenderMaterials() const
- {
- return m_renderMaterials;
- }
-
-
-private:
- //////// private internal data ////////
-
- std::vector<RenderMaterial*> m_renderMaterials;
-};
-
+// 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-2018 NVIDIA Corporation. All rights reserved.
+
+
+#ifndef BLAST_ASSET_MODEL_SIMPLE_H
+#define BLAST_ASSET_MODEL_SIMPLE_H
+
+#include "BlastAssetModel.h"
+
+
+class RenderMaterial;
+
+class BlastAssetModelSimple : public BlastAssetModel
+{
+public:
+ //////// ctor ////////
+
+ BlastAssetModelSimple(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName);
+ virtual ~BlastAssetModelSimple();
+
+
+ //////// interface implementation ////////
+
+ virtual BlastFamilyPtr createFamily(PhysXController& physXConroller, ExtPxManager& pxManager, const ActorDesc& desc);
+
+
+ //////// data getters ////////
+
+ const std::vector<RenderMaterial*>& getRenderMaterials() const
+ {
+ return m_renderMaterials;
+ }
+
+
+private:
+ //////// private internal data ////////
+
+ std::vector<RenderMaterial*> m_renderMaterials;
+};
+
#endif //BLAST_ASSET_MODEL_SIMPLE_H \ No newline at end of file
diff --git a/samples/SampleBase/blast/BlastAssetModelSkinned.cpp b/samples/SampleBase/blast/BlastAssetModelSkinned.cpp
index 331ca15..405178d 100644..100755
--- a/samples/SampleBase/blast/BlastAssetModelSkinned.cpp
+++ b/samples/SampleBase/blast/BlastAssetModelSkinned.cpp
@@ -1,60 +1,60 @@
-// 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-2018 NVIDIA Corporation. All rights reserved.
-
-
-#include "BlastAssetModelSkinned.h"
-#include "BlastFamilyModelSkinned.h"
-#include "RenderMaterial.h"
-#include "Renderer.h"
-
-
-BlastAssetModelSkinned::BlastAssetModelSkinned(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName)
- : BlastAssetModel(framework, physics, cooking, serialization, renderer, modelName)
-{
- for (const BlastModel::Material& material : getModel().materials)
- {
- if (material.diffuseTexture.empty())
- m_renderMaterials.push_back(new RenderMaterial(renderer.getResourceManager(), "model_skinned"));
- else
- m_renderMaterials.push_back(new RenderMaterial(renderer.getResourceManager(), "model_skinned_textured", material.diffuseTexture.c_str()));
- }
-
- initialize();
-}
-
-BlastAssetModelSkinned::~BlastAssetModelSkinned()
-{
- for (RenderMaterial* r : m_renderMaterials)
- {
- SAFE_DELETE(r);
- }
-}
-
-BlastFamilyPtr BlastAssetModelSkinned::createFamily(PhysXController& physXConroller, ExtPxManager& pxManager, const ActorDesc& desc)
-{
- return BlastFamilyPtr(new BlastFamilyModelSkinned(physXConroller, pxManager, m_renderer, *this, desc));
-}
+// 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-2018 NVIDIA Corporation. All rights reserved.
+
+
+#include "BlastAssetModelSkinned.h"
+#include "BlastFamilyModelSkinned.h"
+#include "RenderMaterial.h"
+#include "Renderer.h"
+
+
+BlastAssetModelSkinned::BlastAssetModelSkinned(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName)
+ : BlastAssetModel(framework, physics, cooking, serialization, renderer, modelName)
+{
+ for (const BlastModel::Material& material : getModel().materials)
+ {
+ if (material.diffuseTexture.empty())
+ m_renderMaterials.push_back(new RenderMaterial(renderer.getResourceManager(), "model_skinned"));
+ else
+ m_renderMaterials.push_back(new RenderMaterial(renderer.getResourceManager(), "model_skinned_textured", material.diffuseTexture.c_str()));
+ }
+
+ initialize();
+}
+
+BlastAssetModelSkinned::~BlastAssetModelSkinned()
+{
+ for (RenderMaterial* r : m_renderMaterials)
+ {
+ SAFE_DELETE(r);
+ }
+}
+
+BlastFamilyPtr BlastAssetModelSkinned::createFamily(PhysXController& physXConroller, ExtPxManager& pxManager, const ActorDesc& desc)
+{
+ return BlastFamilyPtr(new BlastFamilyModelSkinned(physXConroller, pxManager, m_renderer, *this, desc));
+}
diff --git a/samples/SampleBase/blast/BlastAssetModelSkinned.h b/samples/SampleBase/blast/BlastAssetModelSkinned.h
index 8ebb722..9075e04 100644..100755
--- a/samples/SampleBase/blast/BlastAssetModelSkinned.h
+++ b/samples/SampleBase/blast/BlastAssetModelSkinned.h
@@ -1,64 +1,64 @@
-// 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-2018 NVIDIA Corporation. All rights reserved.
-
-
-#ifndef BLAST_ASSET_MODEL_SKINNED_H
-#define BLAST_ASSET_MODEL_SKINNED_H
-
-#include "BlastAssetModel.h"
-
-class RenderMaterial;
-
-class BlastAssetModelSkinned : public BlastAssetModel
-{
-public:
- //////// ctor ////////
-
- BlastAssetModelSkinned(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName);
- virtual ~BlastAssetModelSkinned();
-
-
- //////// interface implementation ////////
-
- BlastFamilyPtr createFamily(PhysXController& physXConroller, ExtPxManager& pxManager, const ActorDesc& desc);
-
-
- //////// public getter ////////
-
- const std::vector<RenderMaterial*>& getRenderMaterials() const
- {
- return m_renderMaterials;
- }
-
-
-private:
- //////// internal data ////////
-
- std::vector<RenderMaterial*> m_renderMaterials;
-};
-
+// 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-2018 NVIDIA Corporation. All rights reserved.
+
+
+#ifndef BLAST_ASSET_MODEL_SKINNED_H
+#define BLAST_ASSET_MODEL_SKINNED_H
+
+#include "BlastAssetModel.h"
+
+class RenderMaterial;
+
+class BlastAssetModelSkinned : public BlastAssetModel
+{
+public:
+ //////// ctor ////////
+
+ BlastAssetModelSkinned(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName);
+ virtual ~BlastAssetModelSkinned();
+
+
+ //////// interface implementation ////////
+
+ BlastFamilyPtr createFamily(PhysXController& physXConroller, ExtPxManager& pxManager, const ActorDesc& desc);
+
+
+ //////// public getter ////////
+
+ const std::vector<RenderMaterial*>& getRenderMaterials() const
+ {
+ return m_renderMaterials;
+ }
+
+
+private:
+ //////// internal data ////////
+
+ std::vector<RenderMaterial*> m_renderMaterials;
+};
+
#endif //BLAST_ASSET_MODEL_SKINNED_H \ No newline at end of file
diff --git a/samples/SampleBase/blast/BlastController.cpp b/samples/SampleBase/blast/BlastController.cpp
index c1e977e..e185922 100644..100755
--- a/samples/SampleBase/blast/BlastController.cpp
+++ b/samples/SampleBase/blast/BlastController.cpp
@@ -1,533 +1,533 @@
-// 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-2018 NVIDIA Corporation. All rights reserved.
-
-
-#include "BlastController.h"
-#include "BlastFamily.h"
-#include "BlastAsset.h"
-#include "BlastReplay.h"
-#include "PhysXController.h"
-#include "SampleTime.h"
-#include "SampleProfiler.h"
-#include "Utils.h"
-#include "Renderer.h"
-
-#include "NvBlastExtPxTask.h"
-
-#include "NvBlast.h"
-#include "NvBlastPxCallbacks.h"
-#include "NvBlastExtPxManager.h"
-#include "NvBlastExtPxFamily.h"
-#include "NvBlastExtPxActor.h"
-#include "NvBlastExtPxAsset.h"
-#include "NvBlastExtSerialization.h"
-#include "NvBlastExtTkSerialization.h"
-#include "NvBlastExtPxSerialization.h"
-
-#include "NvBlastTkFramework.h"
-
-#include "PsString.h"
-#include "PxTaskManager.h"
-#include "PxDefaultCpuDispatcher.h"
-#include "PxRigidBody.h"
-#include "PxScene.h"
-#include "PxRigidDynamic.h"
-#include "PxDistanceJoint.h"
-
-#include <sstream>
-#include <numeric>
-#include <cstdlib>
-
-#include "imgui.h"
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Joint creation
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-static physx::PxJoint* createPxJointCallback(ExtPxActor* actor0, const physx::PxTransform& localFrame0, ExtPxActor* actor1, const physx::PxTransform& localFrame1, physx::PxPhysics& physics, TkJoint& joint)
-{
- PxDistanceJoint* pxJoint = PxDistanceJointCreate(physics, actor0 ? &actor0->getPhysXActor() : nullptr, localFrame0, actor1 ? &actor1->getPhysXActor() : nullptr, localFrame1);
- pxJoint->setMaxDistance(1.0f);
- return pxJoint;
-}
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Controller
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-BlastController::BlastController()
-: m_eventCallback(nullptr), debugRenderMode(BlastFamily::DEBUG_RENDER_DISABLED), m_impactDamageEnabled(true),
-m_impactDamageToStressEnabled(false), m_rigidBodyLimitEnabled(true), m_rigidBodyLimit(40000), m_blastAssetsSize(0), debugRenderScale(0.01f),
-m_taskManager(nullptr), m_extGroupTaskManager(nullptr), m_damageDescBuffer(64 * 1024), m_damageParamsBuffer(1024)
-{
- m_impactDamageToStressFactor = 0.01f;
- m_draggingToStressFactor = 100.0f;
-}
-
-
-BlastController::~BlastController()
-{
-}
-
-void BlastController::reinitialize()
-{
- onSampleStop();
- onSampleStart();
-}
-
-void BlastController::onSampleStart()
-{
- m_tkFramework = NvBlastTkFrameworkCreate();
-
- m_replay = new BlastReplay();
-
- m_taskManager = PxTaskManager::createTaskManager(NvBlastGetPxErrorCallback(), getPhysXController().getCPUDispatcher(), 0);
-
- TkGroupDesc gdesc;
- gdesc.workerCount = m_taskManager->getCpuDispatcher()->getWorkerCount();
- m_tkGroup = m_tkFramework->createGroup(gdesc);
-
- m_extPxManager = ExtPxManager::create(getPhysXController().getPhysics(), *m_tkFramework, createPxJointCallback);
- m_extPxManager->setActorCountLimit(m_rigidBodyLimitEnabled ? m_rigidBodyLimit : 0);
- m_extImpactDamageManager = ExtImpactDamageManager::create(m_extPxManager, m_extImpactDamageManagerSettings);
- m_eventCallback = new EventCallback(m_extImpactDamageManager);
-
- m_extGroupTaskManager = ExtGroupTaskManager::create(*m_taskManager);
- m_extGroupTaskManager->setGroup(m_tkGroup);
-
- setImpactDamageEnabled(m_impactDamageEnabled, true);
-
- m_extSerialization = NvBlastExtSerializationCreate();
- if (m_extSerialization != nullptr)
- {
- NvBlastExtTkSerializerLoadSet(*m_tkFramework, *m_extSerialization);
- NvBlastExtPxSerializerLoadSet(*m_tkFramework, getPhysXController().getPhysics(), getPhysXController().getCooking(), *m_extSerialization);
- }
-}
-
-
-void BlastController::onSampleStop()
-{
- getPhysXController().simualtionSyncEnd();
-
- removeAllFamilies();
-
- m_extImpactDamageManager->release();
- m_extPxManager->release();
- SAFE_DELETE(m_eventCallback);
-
- m_tkGroup->release();
-
- delete m_replay;
-
- m_tkFramework->release();
-
- if (m_extGroupTaskManager != nullptr)
- {
- m_extGroupTaskManager->release();
- m_extGroupTaskManager = nullptr;
- }
-
- if (m_taskManager != nullptr)
- {
- m_taskManager->release();
- }
-}
-
-
-void BlastController::notifyPhysXControllerRelease()
-{
- if (m_extGroupTaskManager != nullptr)
- {
- m_extGroupTaskManager->release();
- m_extGroupTaskManager = nullptr;
- }
-
- if (m_taskManager != nullptr)
- {
- m_taskManager->release();
- m_taskManager = nullptr;
- }
-}
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Deffered/Immediate damage
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-void BlastController::deferDamage(ExtPxActor *actor, BlastFamily& family, const NvBlastDamageProgram& program, const void* damageDesc, uint32_t damageDescSize)
-{
- const void* bufferedDamageDesc = m_damageDescBuffer.push(damageDesc, damageDescSize);
- PX_ASSERT_WITH_MESSAGE(bufferedDamageDesc, "Damage desc buffer exhausted.");
-
- NvBlastExtProgramParams programParams = { bufferedDamageDesc, &family.getMaterial(), actor->getFamily().getPxAsset().getAccelerator() };
-
- const void* bufferedProgramParams = m_damageParamsBuffer.push(&programParams, sizeof(NvBlastExtProgramParams));
- PX_ASSERT_WITH_MESSAGE(bufferedProgramParams, "Damage params buffer exhausted.");
-
- if (bufferedDamageDesc && bufferedProgramParams)
- {
- actor->getTkActor().damage(program, bufferedProgramParams);
- }
-}
-
-NvBlastFractureBuffers& BlastController::getFractureBuffers(ExtPxActor* actor)
-{
- const TkAsset* tkAsset = actor->getTkActor().getAsset();
- const uint32_t chunkCount = tkAsset->getChunkCount();
- const uint32_t bondCount = tkAsset->getBondCount();
-
- m_fractureBuffers.bondFractureCount = bondCount;
- m_fractureBuffers.chunkFractureCount = chunkCount;
- m_fractureData.resize((uint32_t)(m_fractureBuffers.bondFractureCount * sizeof(NvBlastBondFractureData) + m_fractureBuffers.chunkFractureCount * sizeof(NvBlastChunkFractureData))); // chunk count + bond count
- m_fractureBuffers.chunkFractures = reinterpret_cast<NvBlastChunkFractureData*>(m_fractureData.data());
- m_fractureBuffers.bondFractures = reinterpret_cast<NvBlastBondFractureData*>(&m_fractureData.data()[m_fractureBuffers.chunkFractureCount * sizeof(NvBlastChunkFractureData)]);
- return m_fractureBuffers;
-}
-
-void BlastController::immediateDamage(ExtPxActor *actor, BlastFamily& family, const NvBlastDamageProgram& program, const void* damageDesc)
-{
- NvBlastExtProgramParams programParams = { damageDesc, &family.getMaterial(), actor->getFamily().getPxAsset().getAccelerator() };
-
- NvBlastFractureBuffers& fractureEvents = getFractureBuffers(actor);
- actor->getTkActor().generateFracture(&fractureEvents, program, &programParams);
- actor->getTkActor().applyFracture(nullptr, &fractureEvents);
-}
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Impact damage
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-void BlastController::updateImpactDamage()
-{
- if (m_impactDamageUpdatePending)
- {
- getPhysXController().getPhysXScene().setSimulationEventCallback(m_impactDamageEnabled ? m_eventCallback : nullptr);
- refreshImpactDamageSettings();
- m_impactDamageUpdatePending = false;
- }
-}
-
-void BlastController::setImpactDamageEnabled(bool enabled, bool forceUpdate)
-{
- if (m_impactDamageEnabled != enabled || forceUpdate)
- {
- m_impactDamageEnabled = enabled;
- m_impactDamageUpdatePending = true;
- }
-}
-
-bool BlastController::customImpactDamageFunction(void* data, ExtPxActor* actor, physx::PxShape* shape, physx::PxVec3 position, physx::PxVec3 force)
-{
- return reinterpret_cast<BlastController*>(data)->stressDamage(actor, position, force);
-}
-
-bool BlastController::stressDamage(ExtPxActor *actor, physx::PxVec3 position, physx::PxVec3 force)
-{
- if (actor->getTkActor().getGraphNodeCount() > 1)
- {
- void* userData = actor->getFamily().userData;
- if (userData)
- {
- ExtPxStressSolver* solver = reinterpret_cast<ExtPxStressSolver*>(userData);
- solver->getSolver().addForce(*actor->getTkActor().getActorLL(), position, force * m_impactDamageToStressFactor);
- return true;
- }
- }
-
- return false;
-}
-
-void BlastController::refreshImpactDamageSettings()
-{
- m_extImpactDamageManagerSettings.damageFunction = m_impactDamageToStressEnabled ? customImpactDamageFunction : nullptr;
- m_extImpactDamageManagerSettings.damageFunctionData = this;
- m_extImpactDamageManager->setSettings(m_extImpactDamageManagerSettings);
-}
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Stress
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-void BlastController::updateDraggingStress()
-{
- auto physxController = getPhysXController();
- auto actor = physxController.getDraggingActor();
- if (actor)
- {
- ExtPxActor* pxActor = m_extPxManager->getActorFromPhysXActor(*actor);
- if (pxActor && pxActor->getTkActor().getGraphNodeCount() > 1 && pxActor->getPhysXActor().getRigidBodyFlags() & PxRigidBodyFlag::eKINEMATIC)
- {
- void* userData = pxActor->getFamily().userData;
- if (userData)
- {
- ExtPxStressSolver* solver = reinterpret_cast<ExtPxStressSolver*>(userData);
- PxTransform t(pxActor->getPhysXActor().getGlobalPose().getInverse());
- PxVec3 dragVector = t.rotate(physxController.getDragVector());
- const float factor = dragVector.magnitudeSquared() * m_draggingToStressFactor;
- solver->getSolver().addForce(*pxActor->getTkActor().getActorLL(), physxController.getDragActorHookLocalPoint(), dragVector.getNormalized() * factor);
- }
- }
- }
-}
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Stats
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-uint32_t BlastController::getActorCount() const
-{
- return std::accumulate(m_families.begin(), m_families.end(), (uint32_t)0, [](uint32_t sum, const BlastFamilyPtr& a)
- {
- return sum += a->getActorCount();
- });
-}
-
-uint32_t BlastController::getTotalVisibleChunkCount() const
-{
- return std::accumulate(m_families.begin(), m_families.end(), (uint32_t)0, [](uint32_t sum, const BlastFamilyPtr& a)
- {
- return sum += a->getTotalVisibleChunkCount();
- });
-}
-
-size_t BlastController::getFamilySize() const
-{
- return std::accumulate(m_families.begin(), m_families.end(), (size_t)0, [](size_t sum, const BlastFamilyPtr& a)
- {
- return sum += a->getFamilySize();
- });
-}
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Time
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-const double Time::s_secondsPerTick = Time::getTickDuration();
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Controller events
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-void BlastController::Animate(double dt)
-{
- PROFILER_SCOPED_FUNCTION();
-
- PROFILER_BEGIN("Apply Impact Damage");
- m_extImpactDamageManager->applyDamage();
- PROFILER_END();
-
- updateDraggingStress();
-
- fillDebugRender();
-
- getPhysXController().simualtionSyncEnd();
-
- updateImpactDamage();
-
- Time blastTime;
- for (uint32_t i = 0; i < m_families.size(); ++i)
- {
- if (m_families[i])
- {
- m_families[i]->updatePreSplit(dt);
- }
- }
-
- m_replay->update();
-
- PROFILER_BEGIN("Tk Group Process/Sync");
-
-#if 1
-
- m_extGroupTaskManager->process();
- m_extGroupTaskManager->wait();
-
-#else // process group on main thread
-
- m_tkGroup->process();
-
-#endif
-
- m_damageParamsBuffer.clear();
- m_damageDescBuffer.clear();
-
- PROFILER_END();
-
- getPhysXController().simulationBegin(dt);
-
- TkGroupStats gstats;
- m_tkGroup->getStats(gstats);
-
- this->m_lastBlastTimers.blastDamageMaterial = NvBlastTicksToSeconds(gstats.timers.material);
- this->m_lastBlastTimers.blastDamageFracture = NvBlastTicksToSeconds(gstats.timers.fracture);
- this->m_lastBlastTimers.blastSplitIsland = NvBlastTicksToSeconds(gstats.timers.island);
- this->m_lastBlastTimers.blastSplitPartition = NvBlastTicksToSeconds(gstats.timers.partition);
- this->m_lastBlastTimers.blastSplitVisibility = NvBlastTicksToSeconds(gstats.timers.visibility);
-
- for (uint32_t i = 0; i < m_families.size(); ++i)
- {
- if (m_families[i])
- {
- m_families[i]->updateAfterSplit(dt);
- }
- }
-}
-
-
-void BlastController::drawUI()
-{
- // impact damage
- bool impactEnabled = getImpactDamageEnabled();
- if (ImGui::Checkbox("Impact Damage", &impactEnabled))
- {
- setImpactDamageEnabled(impactEnabled);
- }
- {
- bool refresh = false;
- refresh |= ImGui::Checkbox("Use Shear Damage", &m_extImpactDamageManagerSettings.shearDamage);
- refresh |= ImGui::DragFloat("Material Hardness", &m_extImpactDamageManagerSettings.hardness);
- refresh |= ImGui::DragFloat("Damage Radius (Max)", &m_extImpactDamageManagerSettings.damageRadiusMax);
- refresh |= ImGui::DragFloat("Damage Threshold (Min)", &m_extImpactDamageManagerSettings.damageThresholdMin, 1.0f, 0.0f, 1.0f);
- refresh |= ImGui::DragFloat("Damage Threshold (Max)", &m_extImpactDamageManagerSettings.damageThresholdMax, 1.0f, 0.0f, 1.0f);
- refresh |= ImGui::DragFloat("Damage Falloff Radius Factor", &m_extImpactDamageManagerSettings.damageFalloffRadiusFactor, 1.0f, 0.0f, 32.0f);
- refresh |= ImGui::Checkbox("Impact Damage To Stress Solver", &m_impactDamageToStressEnabled);
-
- if (refresh)
- {
- refreshImpactDamageSettings();
- }
- }
-
- ImGui::DragFloat("Impact Damage To Stress Factor", &m_impactDamageToStressFactor, 0.001f, 0.0f, 1000.0f, "%.4f");
- ImGui::DragFloat("Dragging To Stress Factor", &m_draggingToStressFactor, 0.1f, 0.0f, 1000.0f, "%.3f");
-
- ImGui::Checkbox("Limit Rigid Body Count", &m_rigidBodyLimitEnabled);
- if (m_rigidBodyLimitEnabled)
- {
- ImGui::DragInt("Rigid Body Limit", (int*)&m_rigidBodyLimit, 100, 1000, 100000);
- }
- m_extPxManager->setActorCountLimit(m_rigidBodyLimitEnabled ? m_rigidBodyLimit : 0);
-}
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// actor management
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-BlastFamilyPtr BlastController::spawnFamily(BlastAsset* blastAsset, const BlastAsset::ActorDesc& desc)
-{
- BlastFamilyPtr actor = blastAsset->createFamily(getPhysXController(), *m_extPxManager, desc);
- m_families.push_back(actor);
- recalculateAssetsSize();
- m_replay->addFamily(&actor->getFamily()->getTkFamily());
- return actor;
-}
-
-void BlastController::removeFamily(BlastFamilyPtr actor)
-{
- m_replay->removeFamily(&actor->getFamily()->getTkFamily());
- m_families.erase(std::remove(m_families.begin(), m_families.end(), actor), m_families.end());
- recalculateAssetsSize();
- getPhysXController().resetDragging();
-}
-
-void BlastController::removeAllFamilies()
-{
- while (!m_families.empty())
- {
- removeFamily(m_families.back());
- }
- m_replay->reset();
-}
-
-void BlastController::recalculateAssetsSize()
-{
- std::set<const BlastAsset*> uniquedAssets;
- m_blastAssetsSize = 0;
- for (uint32_t i = 0; i < m_families.size(); ++i)
- {
- if (uniquedAssets.find(&m_families[i]->getBlastAsset()) == uniquedAssets.end())
- {
- m_blastAssetsSize += m_families[i]->getBlastAsset().getBlastAssetSize();
- uniquedAssets.insert(&m_families[i]->getBlastAsset());
- }
- }
-}
-
-bool BlastController::overlap(const PxGeometry& geometry, const PxTransform& pose, std::function<void(ExtPxActor*, BlastFamily&)> hitCall)
-{
- PROFILER_SCOPED_FUNCTION();
-
- bool anyHit = false;
- for (uint32_t i = 0; i < m_families.size(); ++i)
- {
- if (m_families[i])
- {
- anyHit |= m_families[i]->overlap(geometry, pose, hitCall);
- }
- }
- return anyHit;
-}
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// debug render
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-void BlastController::fillDebugRender()
-{
- PROFILER_SCOPED_FUNCTION();
-
- m_debugRenderBuffer.clear();
-
- if (debugRenderMode != BlastFamily::DEBUG_RENDER_DISABLED)
- {
- getPhysXController().getPhysXScene().setVisualizationParameter(PxVisualizationParameter::eSCALE, 1);
- for (uint32_t i = 0; i < m_families.size(); ++i)
- {
- m_families[i]->fillDebugRender(m_debugRenderBuffer, debugRenderMode, debugRenderScale);
- }
- }
- else
- {
- getPhysXController().getPhysXScene().setVisualizationParameter(PxVisualizationParameter::eSCALE, 0);
- }
-
- getRenderer().queueRenderBuffer(&m_debugRenderBuffer);
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// 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-2018 NVIDIA Corporation. All rights reserved.
+
+
+#include "BlastController.h"
+#include "BlastFamily.h"
+#include "BlastAsset.h"
+#include "BlastReplay.h"
+#include "PhysXController.h"
+#include "SampleTime.h"
+#include "SampleProfiler.h"
+#include "Utils.h"
+#include "Renderer.h"
+
+#include "NvBlastExtPxTask.h"
+
+#include "NvBlast.h"
+#include "NvBlastPxCallbacks.h"
+#include "NvBlastExtPxManager.h"
+#include "NvBlastExtPxFamily.h"
+#include "NvBlastExtPxActor.h"
+#include "NvBlastExtPxAsset.h"
+#include "NvBlastExtSerialization.h"
+#include "NvBlastExtTkSerialization.h"
+#include "NvBlastExtPxSerialization.h"
+
+#include "NvBlastTkFramework.h"
+
+#include "PsString.h"
+#include "PxTaskManager.h"
+#include "PxDefaultCpuDispatcher.h"
+#include "PxRigidBody.h"
+#include "PxScene.h"
+#include "PxRigidDynamic.h"
+#include "PxDistanceJoint.h"
+
+#include <sstream>
+#include <numeric>
+#include <cstdlib>
+
+#include "imgui.h"
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Joint creation
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+static physx::PxJoint* createPxJointCallback(ExtPxActor* actor0, const physx::PxTransform& localFrame0, ExtPxActor* actor1, const physx::PxTransform& localFrame1, physx::PxPhysics& physics, TkJoint& joint)
+{
+ PxDistanceJoint* pxJoint = PxDistanceJointCreate(physics, actor0 ? &actor0->getPhysXActor() : nullptr, localFrame0, actor1 ? &actor1->getPhysXActor() : nullptr, localFrame1);
+ pxJoint->setMaxDistance(1.0f);
+ return pxJoint;
+}
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Controller
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+BlastController::BlastController()
+: m_eventCallback(nullptr), debugRenderMode(BlastFamily::DEBUG_RENDER_DISABLED), m_impactDamageEnabled(true),
+m_impactDamageToStressEnabled(false), m_rigidBodyLimitEnabled(true), m_rigidBodyLimit(40000), m_blastAssetsSize(0), debugRenderScale(0.01f),
+m_taskManager(nullptr), m_extGroupTaskManager(nullptr), m_damageDescBuffer(64 * 1024), m_damageParamsBuffer(1024)
+{
+ m_impactDamageToStressFactor = 0.01f;
+ m_draggingToStressFactor = 100.0f;
+}
+
+
+BlastController::~BlastController()
+{
+}
+
+void BlastController::reinitialize()
+{
+ onSampleStop();
+ onSampleStart();
+}
+
+void BlastController::onSampleStart()
+{
+ m_tkFramework = NvBlastTkFrameworkCreate();
+
+ m_replay = new BlastReplay();
+
+ m_taskManager = PxTaskManager::createTaskManager(NvBlastGetPxErrorCallback(), getPhysXController().getCPUDispatcher(), 0);
+
+ TkGroupDesc gdesc;
+ gdesc.workerCount = m_taskManager->getCpuDispatcher()->getWorkerCount();
+ m_tkGroup = m_tkFramework->createGroup(gdesc);
+
+ m_extPxManager = ExtPxManager::create(getPhysXController().getPhysics(), *m_tkFramework, createPxJointCallback);
+ m_extPxManager->setActorCountLimit(m_rigidBodyLimitEnabled ? m_rigidBodyLimit : 0);
+ m_extImpactDamageManager = ExtImpactDamageManager::create(m_extPxManager, m_extImpactDamageManagerSettings);
+ m_eventCallback = new EventCallback(m_extImpactDamageManager);
+
+ m_extGroupTaskManager = ExtGroupTaskManager::create(*m_taskManager);
+ m_extGroupTaskManager->setGroup(m_tkGroup);
+
+ setImpactDamageEnabled(m_impactDamageEnabled, true);
+
+ m_extSerialization = NvBlastExtSerializationCreate();
+ if (m_extSerialization != nullptr)
+ {
+ NvBlastExtTkSerializerLoadSet(*m_tkFramework, *m_extSerialization);
+ NvBlastExtPxSerializerLoadSet(*m_tkFramework, getPhysXController().getPhysics(), getPhysXController().getCooking(), *m_extSerialization);
+ }
+}
+
+
+void BlastController::onSampleStop()
+{
+ getPhysXController().simualtionSyncEnd();
+
+ removeAllFamilies();
+
+ m_extImpactDamageManager->release();
+ m_extPxManager->release();
+ SAFE_DELETE(m_eventCallback);
+
+ m_tkGroup->release();
+
+ delete m_replay;
+
+ m_tkFramework->release();
+
+ if (m_extGroupTaskManager != nullptr)
+ {
+ m_extGroupTaskManager->release();
+ m_extGroupTaskManager = nullptr;
+ }
+
+ if (m_taskManager != nullptr)
+ {
+ m_taskManager->release();
+ }
+}
+
+
+void BlastController::notifyPhysXControllerRelease()
+{
+ if (m_extGroupTaskManager != nullptr)
+ {
+ m_extGroupTaskManager->release();
+ m_extGroupTaskManager = nullptr;
+ }
+
+ if (m_taskManager != nullptr)
+ {
+ m_taskManager->release();
+ m_taskManager = nullptr;
+ }
+}
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Deffered/Immediate damage
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void BlastController::deferDamage(ExtPxActor *actor, BlastFamily& family, const NvBlastDamageProgram& program, const void* damageDesc, uint32_t damageDescSize)
+{
+ const void* bufferedDamageDesc = m_damageDescBuffer.push(damageDesc, damageDescSize);
+ PX_ASSERT_WITH_MESSAGE(bufferedDamageDesc, "Damage desc buffer exhausted.");
+
+ NvBlastExtProgramParams programParams = { bufferedDamageDesc, &family.getMaterial(), actor->getFamily().getPxAsset().getAccelerator() };
+
+ const void* bufferedProgramParams = m_damageParamsBuffer.push(&programParams, sizeof(NvBlastExtProgramParams));
+ PX_ASSERT_WITH_MESSAGE(bufferedProgramParams, "Damage params buffer exhausted.");
+
+ if (bufferedDamageDesc && bufferedProgramParams)
+ {
+ actor->getTkActor().damage(program, bufferedProgramParams);
+ }
+}
+
+NvBlastFractureBuffers& BlastController::getFractureBuffers(ExtPxActor* actor)
+{
+ const TkAsset* tkAsset = actor->getTkActor().getAsset();
+ const uint32_t chunkCount = tkAsset->getChunkCount();
+ const uint32_t bondCount = tkAsset->getBondCount();
+
+ m_fractureBuffers.bondFractureCount = bondCount;
+ m_fractureBuffers.chunkFractureCount = chunkCount;
+ m_fractureData.resize((uint32_t)(m_fractureBuffers.bondFractureCount * sizeof(NvBlastBondFractureData) + m_fractureBuffers.chunkFractureCount * sizeof(NvBlastChunkFractureData))); // chunk count + bond count
+ m_fractureBuffers.chunkFractures = reinterpret_cast<NvBlastChunkFractureData*>(m_fractureData.data());
+ m_fractureBuffers.bondFractures = reinterpret_cast<NvBlastBondFractureData*>(&m_fractureData.data()[m_fractureBuffers.chunkFractureCount * sizeof(NvBlastChunkFractureData)]);
+ return m_fractureBuffers;
+}
+
+void BlastController::immediateDamage(ExtPxActor *actor, BlastFamily& family, const NvBlastDamageProgram& program, const void* damageDesc)
+{
+ NvBlastExtProgramParams programParams = { damageDesc, &family.getMaterial(), actor->getFamily().getPxAsset().getAccelerator() };
+
+ NvBlastFractureBuffers& fractureEvents = getFractureBuffers(actor);
+ actor->getTkActor().generateFracture(&fractureEvents, program, &programParams);
+ actor->getTkActor().applyFracture(nullptr, &fractureEvents);
+}
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Impact damage
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void BlastController::updateImpactDamage()
+{
+ if (m_impactDamageUpdatePending)
+ {
+ getPhysXController().getPhysXScene().setSimulationEventCallback(m_impactDamageEnabled ? m_eventCallback : nullptr);
+ refreshImpactDamageSettings();
+ m_impactDamageUpdatePending = false;
+ }
+}
+
+void BlastController::setImpactDamageEnabled(bool enabled, bool forceUpdate)
+{
+ if (m_impactDamageEnabled != enabled || forceUpdate)
+ {
+ m_impactDamageEnabled = enabled;
+ m_impactDamageUpdatePending = true;
+ }
+}
+
+bool BlastController::customImpactDamageFunction(void* data, ExtPxActor* actor, physx::PxShape* shape, physx::PxVec3 position, physx::PxVec3 force)
+{
+ return reinterpret_cast<BlastController*>(data)->stressDamage(actor, position, force);
+}
+
+bool BlastController::stressDamage(ExtPxActor *actor, physx::PxVec3 position, physx::PxVec3 force)
+{
+ if (actor->getTkActor().getGraphNodeCount() > 1)
+ {
+ void* userData = actor->getFamily().userData;
+ if (userData)
+ {
+ ExtPxStressSolver* solver = reinterpret_cast<ExtPxStressSolver*>(userData);
+ solver->getSolver().addForce(*actor->getTkActor().getActorLL(), position, force * m_impactDamageToStressFactor);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void BlastController::refreshImpactDamageSettings()
+{
+ m_extImpactDamageManagerSettings.damageFunction = m_impactDamageToStressEnabled ? customImpactDamageFunction : nullptr;
+ m_extImpactDamageManagerSettings.damageFunctionData = this;
+ m_extImpactDamageManager->setSettings(m_extImpactDamageManagerSettings);
+}
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Stress
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void BlastController::updateDraggingStress()
+{
+ auto physxController = getPhysXController();
+ auto actor = physxController.getDraggingActor();
+ if (actor)
+ {
+ ExtPxActor* pxActor = m_extPxManager->getActorFromPhysXActor(*actor);
+ if (pxActor && pxActor->getTkActor().getGraphNodeCount() > 1 && pxActor->getPhysXActor().getRigidBodyFlags() & PxRigidBodyFlag::eKINEMATIC)
+ {
+ void* userData = pxActor->getFamily().userData;
+ if (userData)
+ {
+ ExtPxStressSolver* solver = reinterpret_cast<ExtPxStressSolver*>(userData);
+ PxTransform t(pxActor->getPhysXActor().getGlobalPose().getInverse());
+ PxVec3 dragVector = t.rotate(physxController.getDragVector());
+ const float factor = dragVector.magnitudeSquared() * m_draggingToStressFactor;
+ solver->getSolver().addForce(*pxActor->getTkActor().getActorLL(), physxController.getDragActorHookLocalPoint(), dragVector.getNormalized() * factor);
+ }
+ }
+ }
+}
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Stats
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+uint32_t BlastController::getActorCount() const
+{
+ return std::accumulate(m_families.begin(), m_families.end(), (uint32_t)0, [](uint32_t sum, const BlastFamilyPtr& a)
+ {
+ return sum += a->getActorCount();
+ });
+}
+
+uint32_t BlastController::getTotalVisibleChunkCount() const
+{
+ return std::accumulate(m_families.begin(), m_families.end(), (uint32_t)0, [](uint32_t sum, const BlastFamilyPtr& a)
+ {
+ return sum += a->getTotalVisibleChunkCount();
+ });
+}
+
+size_t BlastController::getFamilySize() const
+{
+ return std::accumulate(m_families.begin(), m_families.end(), (size_t)0, [](size_t sum, const BlastFamilyPtr& a)
+ {
+ return sum += a->getFamilySize();
+ });
+}
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Time
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+const double Time::s_secondsPerTick = Time::getTickDuration();
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Controller events
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void BlastController::Animate(double dt)
+{
+ PROFILER_SCOPED_FUNCTION();
+
+ PROFILER_BEGIN("Apply Impact Damage");
+ m_extImpactDamageManager->applyDamage();
+ PROFILER_END();
+
+ updateDraggingStress();
+
+ fillDebugRender();
+
+ getPhysXController().simualtionSyncEnd();
+
+ updateImpactDamage();
+
+ Time blastTime;
+ for (uint32_t i = 0; i < m_families.size(); ++i)
+ {
+ if (m_families[i])
+ {
+ m_families[i]->updatePreSplit(dt);
+ }
+ }
+
+ m_replay->update();
+
+ PROFILER_BEGIN("Tk Group Process/Sync");
+
+#if 1
+
+ m_extGroupTaskManager->process();
+ m_extGroupTaskManager->wait();
+
+#else // process group on main thread
+
+ m_tkGroup->process();
+
+#endif
+
+ m_damageParamsBuffer.clear();
+ m_damageDescBuffer.clear();
+
+ PROFILER_END();
+
+ getPhysXController().simulationBegin(dt);
+
+ TkGroupStats gstats;
+ m_tkGroup->getStats(gstats);
+
+ this->m_lastBlastTimers.blastDamageMaterial = NvBlastTicksToSeconds(gstats.timers.material);
+ this->m_lastBlastTimers.blastDamageFracture = NvBlastTicksToSeconds(gstats.timers.fracture);
+ this->m_lastBlastTimers.blastSplitIsland = NvBlastTicksToSeconds(gstats.timers.island);
+ this->m_lastBlastTimers.blastSplitPartition = NvBlastTicksToSeconds(gstats.timers.partition);
+ this->m_lastBlastTimers.blastSplitVisibility = NvBlastTicksToSeconds(gstats.timers.visibility);
+
+ for (uint32_t i = 0; i < m_families.size(); ++i)
+ {
+ if (m_families[i])
+ {
+ m_families[i]->updateAfterSplit(dt);
+ }
+ }
+}
+
+
+void BlastController::drawUI()
+{
+ // impact damage
+ bool impactEnabled = getImpactDamageEnabled();
+ if (ImGui::Checkbox("Impact Damage", &impactEnabled))
+ {
+ setImpactDamageEnabled(impactEnabled);
+ }
+ {
+ bool refresh = false;
+ refresh |= ImGui::Checkbox("Use Shear Damage", &m_extImpactDamageManagerSettings.shearDamage);
+ refresh |= ImGui::DragFloat("Material Hardness", &m_extImpactDamageManagerSettings.hardness);
+ refresh |= ImGui::DragFloat("Damage Radius (Max)", &m_extImpactDamageManagerSettings.damageRadiusMax);
+ refresh |= ImGui::DragFloat("Damage Threshold (Min)", &m_extImpactDamageManagerSettings.damageThresholdMin, 1.0f, 0.0f, 1.0f);
+ refresh |= ImGui::DragFloat("Damage Threshold (Max)", &m_extImpactDamageManagerSettings.damageThresholdMax, 1.0f, 0.0f, 1.0f);
+ refresh |= ImGui::DragFloat("Damage Falloff Radius Factor", &m_extImpactDamageManagerSettings.damageFalloffRadiusFactor, 1.0f, 0.0f, 32.0f);
+ refresh |= ImGui::Checkbox("Impact Damage To Stress Solver", &m_impactDamageToStressEnabled);
+
+ if (refresh)
+ {
+ refreshImpactDamageSettings();
+ }
+ }
+
+ ImGui::DragFloat("Impact Damage To Stress Factor", &m_impactDamageToStressFactor, 0.001f, 0.0f, 1000.0f, "%.4f");
+ ImGui::DragFloat("Dragging To Stress Factor", &m_draggingToStressFactor, 0.1f, 0.0f, 1000.0f, "%.3f");
+
+ ImGui::Checkbox("Limit Rigid Body Count", &m_rigidBodyLimitEnabled);
+ if (m_rigidBodyLimitEnabled)
+ {
+ ImGui::DragInt("Rigid Body Limit", (int*)&m_rigidBodyLimit, 100, 1000, 100000);
+ }
+ m_extPxManager->setActorCountLimit(m_rigidBodyLimitEnabled ? m_rigidBodyLimit : 0);
+}
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// actor management
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+BlastFamilyPtr BlastController::spawnFamily(BlastAsset* blastAsset, const BlastAsset::ActorDesc& desc)
+{
+ BlastFamilyPtr actor = blastAsset->createFamily(getPhysXController(), *m_extPxManager, desc);
+ m_families.push_back(actor);
+ recalculateAssetsSize();
+ m_replay->addFamily(&actor->getFamily()->getTkFamily());
+ return actor;
+}
+
+void BlastController::removeFamily(BlastFamilyPtr actor)
+{
+ m_replay->removeFamily(&actor->getFamily()->getTkFamily());
+ m_families.erase(std::remove(m_families.begin(), m_families.end(), actor), m_families.end());
+ recalculateAssetsSize();
+ getPhysXController().resetDragging();
+}
+
+void BlastController::removeAllFamilies()
+{
+ while (!m_families.empty())
+ {
+ removeFamily(m_families.back());
+ }
+ m_replay->reset();
+}
+
+void BlastController::recalculateAssetsSize()
+{
+ std::set<const BlastAsset*> uniquedAssets;
+ m_blastAssetsSize = 0;
+ for (uint32_t i = 0; i < m_families.size(); ++i)
+ {
+ if (uniquedAssets.find(&m_families[i]->getBlastAsset()) == uniquedAssets.end())
+ {
+ m_blastAssetsSize += m_families[i]->getBlastAsset().getBlastAssetSize();
+ uniquedAssets.insert(&m_families[i]->getBlastAsset());
+ }
+ }
+}
+
+bool BlastController::overlap(const PxGeometry& geometry, const PxTransform& pose, std::function<void(ExtPxActor*, BlastFamily&)> hitCall)
+{
+ PROFILER_SCOPED_FUNCTION();
+
+ bool anyHit = false;
+ for (uint32_t i = 0; i < m_families.size(); ++i)
+ {
+ if (m_families[i])
+ {
+ anyHit |= m_families[i]->overlap(geometry, pose, hitCall);
+ }
+ }
+ return anyHit;
+}
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// debug render
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void BlastController::fillDebugRender()
+{
+ PROFILER_SCOPED_FUNCTION();
+
+ m_debugRenderBuffer.clear();
+
+ if (debugRenderMode != BlastFamily::DEBUG_RENDER_DISABLED)
+ {
+ getPhysXController().getPhysXScene().setVisualizationParameter(PxVisualizationParameter::eSCALE, 1);
+ for (uint32_t i = 0; i < m_families.size(); ++i)
+ {
+ m_families[i]->fillDebugRender(m_debugRenderBuffer, debugRenderMode, debugRenderScale);
+ }
+ }
+ else
+ {
+ getPhysXController().getPhysXScene().setVisualizationParameter(PxVisualizationParameter::eSCALE, 0);
+ }
+
+ getRenderer().queueRenderBuffer(&m_debugRenderBuffer);
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/samples/SampleBase/blast/BlastController.h b/samples/SampleBase/blast/BlastController.h
index f54226d..438435f 100644..100755
--- a/samples/SampleBase/blast/BlastController.h
+++ b/samples/SampleBase/blast/BlastController.h
@@ -1,309 +1,309 @@
-// 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-2018 NVIDIA Corporation. All rights reserved.
-
-
-#ifndef BLAST_CONTROLLER_H
-#define BLAST_CONTROLLER_H
-
-#include "SampleManager.h"
-#include "BlastFamily.h"
-#include "DebugRenderBuffer.h"
-#include "PxSimulationEventCallback.h"
-#include "NvBlastExtImpactDamageManager.h"
-
-using namespace physx;
-
-class BlastAsset;
-class BlastReplay;
-
-namespace physx
-{
-class PxTaskManager;
-}
-namespace Nv
-{
-namespace Blast
-{
-class TkFramework;
-class ExtGroupTaskManager;
-class ExtSerialization;
-}
-}
-
-
-struct BlastTimers
-{
- double blastDamageMaterial;
- double blastDamageFracture;
- double blastSplitIsland;
- double blastSplitPartition;
- double blastSplitVisibility;
-};
-
-/**
-Blast Controller. Entry point for all blast related code, keeps blast actors and controls them.
-*/
-class BlastController : public ISampleController
-{
-public:
- //////// ctor ////////
-
- BlastController();
- virtual ~BlastController();
-
- void reinitialize();
-
- //////// controller callbacks ////////
-
- virtual void onSampleStart();
- virtual void onSampleStop();
-
- virtual void Animate(double dt);
- void drawUI();
-
-
- //////// public API ////////
-
- bool overlap(const PxGeometry& geometry, const PxTransform& pose, std::function<void(ExtPxActor*, BlastFamily&)> hitCall);
-
- bool stressDamage(ExtPxActor *actor, PxVec3 position, PxVec3 force);
-
- void deferDamage(ExtPxActor *actor, BlastFamily& family, const NvBlastDamageProgram& program, const void* damageDesc, uint32_t damageDescSize);
- void immediateDamage(ExtPxActor *actor, BlastFamily& family, const NvBlastDamageProgram& program, const void* damageDesc);
- NvBlastFractureBuffers& getFractureBuffers(ExtPxActor* actor);
-
- BlastFamilyPtr spawnFamily(BlastAsset* blastAsset, const BlastAsset::ActorDesc& desc);
- void removeFamily(BlastFamilyPtr actor);
- void removeAllFamilies();
-
-
- //////// public getters/setters ////////
-
- TkFramework& getTkFramework() const
- {
- return *m_tkFramework;
- }
-
- TkGroup* getTkGroup() const
- {
- return m_tkGroup;
- }
-
- ExtPxManager& getExtPxManager() const
- {
- return *m_extPxManager;
- }
-
- ExtImpactDamageManager* getExtImpactDamageManager() const
- {
- return m_extImpactDamageManager;
- }
-
- BlastReplay* getReplay() const
- {
- return m_replay;
- }
-
- uint32_t getActorCount() const;
-
- uint32_t getTotalVisibleChunkCount() const;
-
- size_t getFamilySize() const;
-
- size_t getBlastAssetsSize() const
- {
- return m_blastAssetsSize;
- }
-
- const BlastTimers& getLastBlastTimers() const
- {
- return m_lastBlastTimers;
- }
-
- bool getImpactDamageEnabled() const
- {
- return m_impactDamageEnabled;
- }
-
- void setImpactDamageEnabled(bool enabled, bool forceUpdate = false);
-
- ExtStressSolverSettings& getStressSolverSettings()
- {
- return m_extStressSolverSettings;
- }
-
- float getLastStressDelta() const;
-
- void notifyPhysXControllerRelease();
-
- ExtSerialization* getExtSerialization() const
- {
- return m_extSerialization;
- }
-
- //////// public variables for UI ////////
-
- BlastFamily::DebugRenderMode debugRenderMode;
- float debugRenderScale;
-
-
- //////// Filter shader enum ////////
-
- enum FilterDataAttributes
- {
- SUPPRESS_CONTACT_NOTIFY = 1,
- };
-
-private:
- //////// impact damage event callback ////////
-
- class EventCallback : public PxSimulationEventCallback
- {
- public:
- EventCallback(ExtImpactDamageManager* manager) : m_manager(manager) {}
-
- // implemented
- virtual void onContact(const PxContactPairHeader& pairHeader, const PxContactPair* pairs, uint32_t nbPairs)
- {
- m_manager->onContact(pairHeader, pairs, nbPairs);
- }
-
- private:
- // unused
- void onConstraintBreak(PxConstraintInfo*, PxU32) {}
- void onWake(PxActor**, PxU32) {}
- void onSleep(PxActor**, PxU32) {}
- void onTrigger(PxTriggerPair*, PxU32) {}
- void onAdvance(const PxRigidBody*const*, const PxTransform*, const PxU32) {}
-
- // data
- ExtImpactDamageManager* m_manager;
- };
-
-
- //////// private methods ////////
-
- void updateDraggingStress();
-
- void updateImpactDamage();
-
- void refreshImpactDamageSettings();
-
- void fillDebugRender();
-
- void recalculateAssetsSize();
-
- static bool customImpactDamageFunction(void* data, ExtPxActor* actor, PxShape* shape, PxVec3 position, PxVec3 force);
-
-
- //////// used controllers ////////
-
- Renderer& getRenderer() const
- {
- return getManager()->getRenderer();
- }
-
- PhysXController& getPhysXController() const
- {
- return getManager()->getPhysXController();
- }
-
-
- //////// buffer for damage ////////
-
- class FixedBuffer
- {
- public:
- FixedBuffer(const uint32_t size)
- {
- m_buffer.resize(size);
- m_index = 0;
- }
-
- void* push(const void* data, uint32_t size)
- {
- if (m_index + size > m_buffer.size())
- return nullptr;
-
- void* dst = &m_buffer[m_index];
- memcpy(dst, data, size);
- m_index += size;
- return dst;
- }
-
- void clear()
- {
- m_index = 0;
- }
-
- private:
- std::vector<char> m_buffer;
- uint32_t m_index;
- };
-
-
- //////// internal data ////////
-
- PxTaskManager* m_taskManager;
- TkFramework* m_tkFramework;
- TkGroup* m_tkGroup;
- ExtPxManager* m_extPxManager;
- ExtImpactDamageManager* m_extImpactDamageManager;
- ExtImpactSettings m_extImpactDamageManagerSettings;
- EventCallback* m_eventCallback;
- ExtStressSolverSettings m_extStressSolverSettings;
- ExtGroupTaskManager* m_extGroupTaskManager;
- ExtSerialization* m_extSerialization;
-
- std::vector<BlastFamilyPtr> m_families;
- DebugRenderBuffer m_debugRenderBuffer;
-
- FixedBuffer m_damageDescBuffer;
- FixedBuffer m_damageParamsBuffer;
-
- NvBlastFractureBuffers m_fractureBuffers;
- std::vector<char> m_fractureData;
-
- bool m_impactDamageEnabled;
- bool m_impactDamageUpdatePending;
- bool m_impactDamageToStressEnabled;
-
- float m_impactDamageToStressFactor;
- float m_draggingToStressFactor;
-
- bool m_rigidBodyLimitEnabled;
- uint32_t m_rigidBodyLimit;
-
- BlastReplay* m_replay;
-
- BlastTimers m_lastBlastTimers;
-
- size_t m_blastAssetsSize;
-};
-
-
-#endif
+// 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-2018 NVIDIA Corporation. All rights reserved.
+
+
+#ifndef BLAST_CONTROLLER_H
+#define BLAST_CONTROLLER_H
+
+#include "SampleManager.h"
+#include "BlastFamily.h"
+#include "DebugRenderBuffer.h"
+#include "PxSimulationEventCallback.h"
+#include "NvBlastExtImpactDamageManager.h"
+
+using namespace physx;
+
+class BlastAsset;
+class BlastReplay;
+
+namespace physx
+{
+class PxTaskManager;
+}
+namespace Nv
+{
+namespace Blast
+{
+class TkFramework;
+class ExtGroupTaskManager;
+class ExtSerialization;
+}
+}
+
+
+struct BlastTimers
+{
+ double blastDamageMaterial;
+ double blastDamageFracture;
+ double blastSplitIsland;
+ double blastSplitPartition;
+ double blastSplitVisibility;
+};
+
+/**
+Blast Controller. Entry point for all blast related code, keeps blast actors and controls them.
+*/
+class BlastController : public ISampleController
+{
+public:
+ //////// ctor ////////
+
+ BlastController();
+ virtual ~BlastController();
+
+ void reinitialize();
+
+ //////// controller callbacks ////////
+
+ virtual void onSampleStart();
+ virtual void onSampleStop();
+
+ virtual void Animate(double dt);
+ void drawUI();
+
+
+ //////// public API ////////
+
+ bool overlap(const PxGeometry& geometry, const PxTransform& pose, std::function<void(ExtPxActor*, BlastFamily&)> hitCall);
+
+ bool stressDamage(ExtPxActor *actor, PxVec3 position, PxVec3 force);
+
+ void deferDamage(ExtPxActor *actor, BlastFamily& family, const NvBlastDamageProgram& program, const void* damageDesc, uint32_t damageDescSize);
+ void immediateDamage(ExtPxActor *actor, BlastFamily& family, const NvBlastDamageProgram& program, const void* damageDesc);
+ NvBlastFractureBuffers& getFractureBuffers(ExtPxActor* actor);
+
+ BlastFamilyPtr spawnFamily(BlastAsset* blastAsset, const BlastAsset::ActorDesc& desc);
+ void removeFamily(BlastFamilyPtr actor);
+ void removeAllFamilies();
+
+
+ //////// public getters/setters ////////
+
+ TkFramework& getTkFramework() const
+ {
+ return *m_tkFramework;
+ }
+
+ TkGroup* getTkGroup() const
+ {
+ return m_tkGroup;
+ }
+
+ ExtPxManager& getExtPxManager() const
+ {
+ return *m_extPxManager;
+ }
+
+ ExtImpactDamageManager* getExtImpactDamageManager() const
+ {
+ return m_extImpactDamageManager;
+ }
+
+ BlastReplay* getReplay() const
+ {
+ return m_replay;
+ }
+
+ uint32_t getActorCount() const;
+
+ uint32_t getTotalVisibleChunkCount() const;
+
+ size_t getFamilySize() const;
+
+ size_t getBlastAssetsSize() const
+ {
+ return m_blastAssetsSize;
+ }
+
+ const BlastTimers& getLastBlastTimers() const
+ {
+ return m_lastBlastTimers;
+ }
+
+ bool getImpactDamageEnabled() const
+ {
+ return m_impactDamageEnabled;
+ }
+
+ void setImpactDamageEnabled(bool enabled, bool forceUpdate = false);
+
+ ExtStressSolverSettings& getStressSolverSettings()
+ {
+ return m_extStressSolverSettings;
+ }
+
+ float getLastStressDelta() const;
+
+ void notifyPhysXControllerRelease();
+
+ ExtSerialization* getExtSerialization() const
+ {
+ return m_extSerialization;
+ }
+
+ //////// public variables for UI ////////
+
+ BlastFamily::DebugRenderMode debugRenderMode;
+ float debugRenderScale;
+
+
+ //////// Filter shader enum ////////
+
+ enum FilterDataAttributes
+ {
+ SUPPRESS_CONTACT_NOTIFY = 1,
+ };
+
+private:
+ //////// impact damage event callback ////////
+
+ class EventCallback : public PxSimulationEventCallback
+ {
+ public:
+ EventCallback(ExtImpactDamageManager* manager) : m_manager(manager) {}
+
+ // implemented
+ virtual void onContact(const PxContactPairHeader& pairHeader, const PxContactPair* pairs, uint32_t nbPairs)
+ {
+ m_manager->onContact(pairHeader, pairs, nbPairs);
+ }
+
+ private:
+ // unused
+ void onConstraintBreak(PxConstraintInfo*, PxU32) {}
+ void onWake(PxActor**, PxU32) {}
+ void onSleep(PxActor**, PxU32) {}
+ void onTrigger(PxTriggerPair*, PxU32) {}
+ void onAdvance(const PxRigidBody*const*, const PxTransform*, const PxU32) {}
+
+ // data
+ ExtImpactDamageManager* m_manager;
+ };
+
+
+ //////// private methods ////////
+
+ void updateDraggingStress();
+
+ void updateImpactDamage();
+
+ void refreshImpactDamageSettings();
+
+ void fillDebugRender();
+
+ void recalculateAssetsSize();
+
+ static bool customImpactDamageFunction(void* data, ExtPxActor* actor, PxShape* shape, PxVec3 position, PxVec3 force);
+
+
+ //////// used controllers ////////
+
+ Renderer& getRenderer() const
+ {
+ return getManager()->getRenderer();
+ }
+
+ PhysXController& getPhysXController() const
+ {
+ return getManager()->getPhysXController();
+ }
+
+
+ //////// buffer for damage ////////
+
+ class FixedBuffer
+ {
+ public:
+ FixedBuffer(const uint32_t size)
+ {
+ m_buffer.resize(size);
+ m_index = 0;
+ }
+
+ void* push(const void* data, uint32_t size)
+ {
+ if (m_index + size > m_buffer.size())
+ return nullptr;
+
+ void* dst = &m_buffer[m_index];
+ memcpy(dst, data, size);
+ m_index += size;
+ return dst;
+ }
+
+ void clear()
+ {
+ m_index = 0;
+ }
+
+ private:
+ std::vector<char> m_buffer;
+ uint32_t m_index;
+ };
+
+
+ //////// internal data ////////
+
+ PxTaskManager* m_taskManager;
+ TkFramework* m_tkFramework;
+ TkGroup* m_tkGroup;
+ ExtPxManager* m_extPxManager;
+ ExtImpactDamageManager* m_extImpactDamageManager;
+ ExtImpactSettings m_extImpactDamageManagerSettings;
+ EventCallback* m_eventCallback;
+ ExtStressSolverSettings m_extStressSolverSettings;
+ ExtGroupTaskManager* m_extGroupTaskManager;
+ ExtSerialization* m_extSerialization;
+
+ std::vector<BlastFamilyPtr> m_families;
+ DebugRenderBuffer m_debugRenderBuffer;
+
+ FixedBuffer m_damageDescBuffer;
+ FixedBuffer m_damageParamsBuffer;
+
+ NvBlastFractureBuffers m_fractureBuffers;
+ std::vector<char> m_fractureData;
+
+ bool m_impactDamageEnabled;
+ bool m_impactDamageUpdatePending;
+ bool m_impactDamageToStressEnabled;
+
+ float m_impactDamageToStressFactor;
+ float m_draggingToStressFactor;
+
+ bool m_rigidBodyLimitEnabled;
+ uint32_t m_rigidBodyLimit;
+
+ BlastReplay* m_replay;
+
+ BlastTimers m_lastBlastTimers;
+
+ size_t m_blastAssetsSize;
+};
+
+
+#endif
diff --git a/samples/SampleBase/blast/BlastFamily.cpp b/samples/SampleBase/blast/BlastFamily.cpp
index ff86ea2..5d41eb7 100644..100755
--- a/samples/SampleBase/blast/BlastFamily.cpp
+++ b/samples/SampleBase/blast/BlastFamily.cpp
@@ -1,583 +1,583 @@
-// 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-2018 NVIDIA Corporation. All rights reserved.
-
-
-#include "BlastFamily.h"
-#include "SampleProfiler.h"
-#include "PhysXController.h"
-#include "RenderUtils.h"
-#include "SampleTime.h"
-#include "UIHelpers.h"
-
-#include "NvBlast.h"
-#include "NvBlastTkFamily.h"
-#include "NvBlastTkActor.h"
-#include "NvBlastTkAsset.h"
-#include "NvBlastTkJoint.h"
-#include "NvBlastExtPxAsset.h"
-#include "NvBlastExtPxActor.h"
-#include "NvBlastExtPxFamily.h"
-#include "NvBlastExtPxManager.h"
-
-#include "PxRigidDynamic.h"
-#include "PxScene.h"
-#include "PxJoint.h"
-
-
-const float RIGIDBODY_DENSITY = 2000.0f;
-
-BlastFamily::BlastFamily(PhysXController& physXController, ExtPxManager& pxManager, const BlastAsset& blastAsset)
- : m_physXController(physXController)
- , m_pxManager(pxManager)
- , m_blastAsset(blastAsset)
- , m_listener(this)
- , m_totalVisibleChunkCount(0)
- , m_stressSolver(nullptr)
- , m_spawned(false)
- , m_debugRenderDepth(-1)
-{
- m_settings.stressSolverEnabled = false;
- m_settings.stressDamageEnabled = false;
- m_settings.damageAcceleratorEnabled = true;
-}
-
-BlastFamily::~BlastFamily()
-{
- if (m_stressSolver)
- {
- m_stressSolver->release();
- }
-
- m_pxFamily->unsubscribe(m_listener);
-
- m_pxFamily->release();
-}
-
-void BlastFamily::initialize(const BlastAsset::ActorDesc& desc)
-{
- ExtPxFamilyDesc familyDesc;
- familyDesc.actorDesc = nullptr; // if you use it one day, consider changing code which needs getBondHealthMax() from BlastAsset.
- familyDesc.group = desc.group;
- familyDesc.pxAsset = m_blastAsset.getPxAsset();
- m_pxFamily = m_pxManager.createFamily(familyDesc);
- m_pxFamily->setMaterial(&m_settings.material);
-
-
- m_tkFamily = &m_pxFamily->getTkFamily();
- m_tkFamily->setID(desc.id);
-
- refreshDamageAcceleratorSettings();
-
- m_familySize = NvBlastFamilyGetSize(m_tkFamily->getFamilyLL(), nullptr);
-
- m_pxFamily->subscribe(m_listener);
-
- m_initialTransform = desc.transform;
-}
-
-void BlastFamily::updatePreSplit(float dt)
-{
- if (!m_spawned)
- {
- ExtPxSpawnSettings spawnSettings = {
- &m_physXController.getPhysXScene(),
- m_physXController.getDefaultMaterial(),
- RIGIDBODY_DENSITY
- };
-
- m_pxFamily->spawn(m_initialTransform, PxVec3(1.0f), spawnSettings);
- reloadStressSolver();
-
- m_spawned = true;
- }
-
- // collect potential actors to health update
- m_actorsToUpdateHealth.clear();
- for (const ExtPxActor* actor : m_actors)
- {
- if (actor->getTkActor().isPending())
- {
- m_actorsToUpdateHealth.emplace(actor);
- }
- }
-}
-
-void BlastFamily::updateAfterSplit(float dt)
-{
- PROFILER_BEGIN("Actor Health Update");
- for (const ExtPxActor* actor : m_actors)
- {
- onActorUpdate(*actor);
-
- // update health if neccessary
- if (m_actorsToUpdateHealth.find(actor) != m_actorsToUpdateHealth.end())
- {
- onActorHealthUpdate(*actor);
- }
- }
- PROFILER_END();
-
- PROFILER_BEGIN("Stress Solver");
- // update stress
- m_stressSolveTime = 0;
- if (m_stressSolver)
- {
- Time t;
- m_stressSolver->update(m_settings.stressDamageEnabled);
- m_stressSolveTime += t.getElapsedSeconds();
- }
- PROFILER_END();
-
- PROFILER_BEGIN("Actor Misc Update");
- onUpdate();
- PROFILER_END();
-
- m_pxFamily->postSplitUpdate();
-}
-
-void BlastFamily::processActorCreated(ExtPxFamily&, ExtPxActor& actor)
-{
- m_totalVisibleChunkCount += actor.getChunkCount();
- m_actors.emplace(&actor);
-
- onActorCreated(actor);
- onActorHealthUpdate(actor);
-}
-
-void BlastFamily::processActorDestroyed(ExtPxFamily&, ExtPxActor& actor)
-{
- m_totalVisibleChunkCount -= actor.getChunkCount();
- m_physXController.notifyRigidDynamicDestroyed(&actor.getPhysXActor());
-
- onActorDestroyed(actor);
-
- m_actors.erase(m_actors.find(&actor));
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Data Helpers
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-uint32_t BlastFamily::getActorCount() const
-{
- return (uint32_t)m_tkFamily->getActorCount();
-}
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// UI
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-void BlastFamily::drawUI()
-{
- // Blast Material
- ImGui::Spacing();
- ImGui::Text("Blast Material:");
- ImGui::DragFloat("Health", &m_settings.material.health);
- ImGui::DragFloat("Min Damage Threshold", &m_settings.material.minDamageThreshold, 0.01f, 0.f, m_settings.material.maxDamageThreshold);
- ImGui::DragFloat("Max Damage Threshold", &m_settings.material.maxDamageThreshold, 0.01f, m_settings.material.minDamageThreshold, 1.f);
-
- if (ImGui::Checkbox("AABB Tree (Damage Accelerator)", &m_settings.damageAcceleratorEnabled))
- {
- refreshDamageAcceleratorSettings();
- }
- if (m_settings.damageAcceleratorEnabled)
- {
- ImGui::DragInt("AABB Tree debug depth", &m_debugRenderDepth);
- }
-
-
- ImGui::Spacing();
-
- // Stress Solver Settings
- if (ImGui::Checkbox("Stress Solver Enabled", &m_settings.stressSolverEnabled))
- {
- reloadStressSolver();
- }
-
- if (m_settings.stressSolverEnabled)
- {
- // Settings
- bool changed = false;
-
- changed |= ImGui::DragInt("Bond Iterations Per Frame", (int*)&m_settings.stressSolverSettings.bondIterationsPerFrame, 100, 0, 500000);
- changed |= ImGui::DragFloat("Material Hardness", &m_settings.stressSolverSettings.hardness, 10.0f, 0.01f, 100000.0f, "%.2f");
- changed |= ImGui::DragFloat("Stress Linear Factor", &m_settings.stressSolverSettings.stressLinearFactor, 0.01f, 0.0f, 100.0f, "%.2f");
- changed |= ImGui::DragFloat("Stress Angular Factor", &m_settings.stressSolverSettings.stressAngularFactor, 0.01f, 0.0f, 100.0f, "%.2f");
- changed |= ImGui::SliderInt("Graph Reduction Level", (int*)&m_settings.stressSolverSettings.graphReductionLevel, 0, 32);
- if (changed)
- {
- refreshStressSolverSettings();
- }
-
- ImGui::Checkbox("Stress Damage Enabled", &m_settings.stressDamageEnabled);
-
- if (ImGui::Button("Recalculate Stress"))
- {
- resetStress();
- }
- }
-}
-
-void BlastFamily::drawStatsUI()
-{
- ImGui::PushStyleColor(ImGuiCol_Text, ImColor(10, 255, 10, 255));
- if (m_stressSolver)
- {
- const ExtStressSolver& stressSolver = m_stressSolver->getSolver();
- const float errorLinear = stressSolver.getStressErrorLinear();
- const float errorAngular = stressSolver.getStressErrorAngular();
-
- ImGui::Text("Stress Bond Count: %d", stressSolver.getBondCount());
- ImGui::Text("Stress Frame Iter: %d", stressSolver.getIterationsPerFrame());
- ImGui::Text("Stress Frames: %d", stressSolver.getFrameCount());
- ImGui::Text("Stress Error Lin / Ang: %.4f / %.4f", errorLinear, errorAngular);
- ImGui::Text("Stress Solve Time: %.3f ms", m_stressSolveTime * 1000);
-
- // plot errors
- {
- static float scale = 1.0f;
- scale = stressSolver.getFrameCount() <= 1 ? 1.0f : scale;
- scale = std::max<float>(scale, errorLinear);
- scale = std::max<float>(scale, errorAngular);
-
- static PlotLinesInstance<> linearErrorPlot;
- linearErrorPlot.plot("Stress Linear Error", errorLinear, "error/frame", 0.0f, 1.0f * scale);
- static PlotLinesInstance<> angularErrorPlot;
- angularErrorPlot.plot("Stress Angular Error", errorAngular, "error/frame", 0.0f, 1.0f * scale);
- }
- }
- else
- {
- ImGui::Text("No Stress Solver");
- }
- ImGui::PopStyleColor();
-}
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Stress Solver
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-void BlastFamily::setSettings(const Settings& settings)
-{
- bool reloadStressSolverNeeded = (m_settings.stressSolverEnabled != settings.stressSolverEnabled);
-
- m_settings = settings;
- refreshStressSolverSettings();
- refreshDamageAcceleratorSettings();
-
- if (reloadStressSolverNeeded)
- {
- reloadStressSolver();
- }
-
- m_pxFamily->setMaterial(&m_settings.material);
-}
-
-void BlastFamily::refreshDamageAcceleratorSettings()
-{
- m_pxFamily->getPxAsset().setAccelerator(m_settings.damageAcceleratorEnabled ? m_blastAsset.getAccelerator() : nullptr);
-}
-
-void BlastFamily::refreshStressSolverSettings()
-{
- if (m_stressSolver)
- {
- m_stressSolver->getSolver().setSettings(m_settings.stressSolverSettings);
- }
-}
-
-void BlastFamily::resetStress()
-{
- if (m_stressSolver)
- {
- m_stressSolver->getSolver().reset();
- }
-}
-
-void BlastFamily::reloadStressSolver()
-{
- if (m_stressSolver)
- {
- m_stressSolver->release();
- m_stressSolver = nullptr;
- }
-
- if (m_settings.stressSolverEnabled)
- {
- m_stressSolver = ExtPxStressSolver::create(*m_pxFamily, m_settings.stressSolverSettings);
- m_pxFamily->userData = m_stressSolver;
- }
-}
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// debug render
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-const DirectX::XMFLOAT4 BOND_NORMAL_COLOR(0.0f, 0.8f, 1.0f, 1.0f);
-const DirectX::XMFLOAT4 BOND_INVISIBLE_COLOR(0.65f, 0.16f, 0.16f, 1.0f);
-const DirectX::XMFLOAT4 BOND_IMPULSE_LINEAR_COLOR(0.0f, 1.0f, 0.0f, 1.0f);
-const DirectX::XMFLOAT4 BOND_IMPULSE_ANGULAR_COLOR(1.0f, 0.0f, 0.0f, 1.0f);
-const DirectX::XMFLOAT4 JOINT_COLOR(0.5f, 0.6f, 7.0f, 1.0f);
-
-
-inline void pushCentroid(std::vector<PxDebugLine>& lines, PxVec3 pos, PxU32 color, const float& area, const PxVec3& normal)
-{
- // draw square of area 'area' rotated by normal
- {
- // build world rotation
- PxVec3 n0(0, 0, 1);
- PxVec3 n1 = normal;
- PxVec3 axis = n0.cross(n1);
- float d = n0.dot(n1);
- PxQuat q(axis.x, axis.y, axis.z, 1.f + d);
- q.normalize();
- float e = PxSqrt(1.0f / 2.0f);
- float r = PxSqrt(area);
-
- // transform all 4 square points
- PxTransform t(pos, q);
- PxVec3 p0 = t.transform(PxVec3(-e, e, 0) * r);
- PxVec3 p1 = t.transform(PxVec3( e, e, 0) * r);
- PxVec3 p2 = t.transform(PxVec3( e, -e, 0) * r);
- PxVec3 p3 = t.transform(PxVec3(-e, -e, 0) * r);
-
- // push square edges
- lines.push_back(PxDebugLine(p0, p1, color));
- lines.push_back(PxDebugLine(p3, p2, color));
- lines.push_back(PxDebugLine(p1, p2, color));
- lines.push_back(PxDebugLine(p0, p3, color));
- }
-
- // draw normal
- lines.push_back(PxDebugLine(pos, pos + normal * 0.5f, XMFLOAT4ToU32Color(BOND_NORMAL_COLOR)));
-}
-
-inline DirectX::XMFLOAT4 bondHealthColor(float healthFraction)
-{
- const DirectX::XMFLOAT4 BOND_HEALTHY_COLOR(0.0f, 1.0f, 0.0f, 1.0f);
- const DirectX::XMFLOAT4 BOND_MID_COLOR(1.0f, 1.0f, 0.0f, 1.0f);
- const DirectX::XMFLOAT4 BOND_BROKEN_COLOR(1.0f, 0.0f, 0.0f, 1.0f);
-
- return healthFraction < 0.5 ? XMFLOAT4Lerp(BOND_BROKEN_COLOR, BOND_MID_COLOR, 2.0f * healthFraction) : XMFLOAT4Lerp(BOND_MID_COLOR, BOND_HEALTHY_COLOR, 2.0f * healthFraction - 1.0f);
-}
-
-void BlastFamily::fillDebugRender(DebugRenderBuffer& debugRenderBuffer, DebugRenderMode mode, float renderScale)
-{
- const NvBlastChunk* chunks = m_tkFamily->getAsset()->getChunks();
- const NvBlastBond* bonds = m_tkFamily->getAsset()->getBonds();
- const NvBlastSupportGraph graph = m_tkFamily->getAsset()->getGraph();
- const float bondHealthMax = m_blastAsset.getBondHealthMax();
- const uint32_t chunkCount = m_tkFamily->getAsset()->getChunkCount();
-
- for (const ExtPxActor* pxActor : m_actors)
- {
- TkActor& actor = pxActor->getTkActor();
- uint32_t lineStartIndex = (uint32_t)debugRenderBuffer.m_lines.size();
-
- uint32_t nodeCount = actor.getGraphNodeCount();
- if (nodeCount == 0) // subsupport chunks don't have graph nodes
- continue;
-
- std::vector<uint32_t> nodes(nodeCount);
- actor.getGraphNodeIndices(nodes.data(), static_cast<uint32_t>(nodes.size()));
-
- if (DEBUG_RENDER_HEALTH_GRAPH <= mode && mode <= DEBUG_RENDER_HEALTH_GRAPH_CENTROIDS)
- {
- const float* bondHealths = actor.getBondHealths();
-
- const ExtPxChunk* pxChunks = m_blastAsset.getPxAsset()->getChunks();
-
- for (uint32_t node0 : nodes)
- {
- const uint32_t chunkIndex0 = graph.chunkIndices[node0];
- const NvBlastChunk& blastChunk0 = chunks[chunkIndex0];
- const ExtPxChunk& assetChunk0 = pxChunks[chunkIndex0];
-
- for (uint32_t adjacencyIndex = graph.adjacencyPartition[node0]; adjacencyIndex < graph.adjacencyPartition[node0 + 1]; adjacencyIndex++)
- {
- uint32_t node1 = graph.adjacentNodeIndices[adjacencyIndex];
- const uint32_t chunkIndex1 = graph.chunkIndices[node1];
- const NvBlastChunk& blastChunk1 = chunks[chunkIndex1];
- const ExtPxChunk& assetChunk1 = pxChunks[chunkIndex1];
- if (node0 > node1)
- continue;
-
- bool invisibleBond = chunkIndex0 >= chunkCount || chunkIndex1 >= chunkCount || assetChunk0.subchunkCount == 0 || assetChunk1.subchunkCount == 0;
-
- // health
- uint32_t bondIndex = graph.adjacentBondIndices[adjacencyIndex];
- float healthVal = PxClamp(bondHealths[bondIndex] / bondHealthMax, 0.0f, 1.0f);
-
- DirectX::XMFLOAT4 color = bondHealthColor(healthVal);
-
- const NvBlastBond& solverBond = bonds[bondIndex];
- const PxVec3& centroid = reinterpret_cast<const PxVec3&>(solverBond.centroid);
-
- // centroid
- if (mode == DEBUG_RENDER_HEALTH_GRAPH_CENTROIDS || mode == DEBUG_RENDER_CENTROIDS)
- {
- const PxVec3& normal = reinterpret_cast<const PxVec3&>(solverBond.normal);
- pushCentroid(debugRenderBuffer.m_lines, centroid, XMFLOAT4ToU32Color(invisibleBond ? BOND_INVISIBLE_COLOR : color), solverBond.area, normal.getNormalized());
- }
-
- // chunk connection (bond)
- if ((mode == DEBUG_RENDER_HEALTH_GRAPH || mode == DEBUG_RENDER_HEALTH_GRAPH_CENTROIDS) && !invisibleBond)
- {
- const PxVec3& c0 = reinterpret_cast<const PxVec3&>(blastChunk0.centroid);
- const PxVec3& c1 = reinterpret_cast<const PxVec3&>(blastChunk1.centroid);
- debugRenderBuffer.m_lines.push_back(PxDebugLine(c0, c1, XMFLOAT4ToU32Color(color)));
- }
- }
- }
- }
-
- // stress
- if (DEBUG_RENDER_STRESS_GRAPH <= mode && mode <= DEBUG_RENDER_STRESS_GRAPH_BONDS_IMPULSES)
- {
- if (m_stressSolver)
- {
- const auto buffer = m_stressSolver->getSolver().fillDebugRender(nodes.data(), (uint32_t)nodes.size(), (ExtStressSolver::DebugRenderMode)(mode - DEBUG_RENDER_STRESS_GRAPH), renderScale);
- if (buffer.lineCount)
- {
- const auto lines = reinterpret_cast<const PxDebugLine*>(buffer.lines);
- debugRenderBuffer.m_lines.insert(debugRenderBuffer.m_lines.end(), lines, lines + buffer.lineCount);
- }
- }
- }
-
- // AABB tree
- if (mode == DEBUG_RENDER_AABB_TREE_CENTROIDS || mode == DEBUG_RENDER_AABB_TREE_SEGMENTS)
- {
- if (m_settings.damageAcceleratorEnabled && m_blastAsset.getAccelerator() && nodeCount > graph.nodeCount / 2)
- {
- const auto buffer = m_blastAsset.getAccelerator()->fillDebugRender(m_debugRenderDepth, mode == DEBUG_RENDER_AABB_TREE_SEGMENTS);
- if (buffer.lineCount)
- {
- const auto lines = reinterpret_cast<const PxDebugLine*>(buffer.lines);
- debugRenderBuffer.m_lines.insert(debugRenderBuffer.m_lines.end(), lines, lines + buffer.lineCount);
- }
- }
- }
-
- // transform all added lines from local to global
- PxTransform localToGlobal = pxActor->getPhysXActor().getGlobalPose();
- for (uint32_t i = lineStartIndex; i < debugRenderBuffer.m_lines.size(); i++)
- {
- PxDebugLine& line = debugRenderBuffer.m_lines[i];
- line.pos0 = localToGlobal.transform(line.pos0);
- line.pos1 = localToGlobal.transform(line.pos1);
- }
- }
-
- // joints debug render
- if (mode == DEBUG_RENDER_JOINTS)
- {
- for (const ExtPxActor* pxActor : m_actors)
- {
- TkActor& actor = pxActor->getTkActor();
- const uint32_t jointCount = actor.getJointCount();
- if (jointCount > 0)
- {
- std::vector<TkJoint*> joints(jointCount);
- actor.getJoints(joints.data(), jointCount);
- for (auto joint : joints)
- {
- PxJoint* pxJoint = reinterpret_cast<PxJoint*>(joint->userData);
- if (pxJoint)
- {
- PxRigidActor *actor0, *actor1;
- pxJoint->getActors(actor0, actor1);
- auto lp0 = pxJoint->getLocalPose(PxJointActorIndex::eACTOR0);
- auto lp1 = pxJoint->getLocalPose(PxJointActorIndex::eACTOR1);
- PxVec3 p0 = actor0 ? actor0->getGlobalPose().transform(lp0).p : lp0.p;
- PxVec3 p1 = actor1 ? actor1->getGlobalPose().transform(lp1).p : lp1.p;
- debugRenderBuffer.m_lines.push_back(PxDebugLine(p0, p1, XMFLOAT4ToU32Color(JOINT_COLOR)));
- }
- }
- }
- }
- }
-}
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// action!!!
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-class BlastOverlapCallback : public PxOverlapCallback
-{
-public:
- BlastOverlapCallback(ExtPxManager& pxManager, std::set<ExtPxActor*>& actorBuffer)
- : m_pxManager(pxManager), m_actorBuffer(actorBuffer), PxOverlapCallback(m_hitBuffer, sizeof(m_hitBuffer) / sizeof(m_hitBuffer[0])) {}
-
- PxAgain processTouches(const PxOverlapHit* buffer, PxU32 nbHits)
- {
- for (PxU32 i = 0; i < nbHits; ++i)
- {
- PxRigidDynamic* rigidDynamic = buffer[i].actor->is<PxRigidDynamic>();
- if (rigidDynamic)
- {
- ExtPxActor* actor = m_pxManager.getActorFromPhysXActor(*rigidDynamic);
- if (actor != nullptr)
- {
- m_actorBuffer.insert(actor);
- }
- }
- }
- return true;
- }
-
-private:
- ExtPxManager& m_pxManager;
- std::set<ExtPxActor*>& m_actorBuffer;
- PxOverlapHit m_hitBuffer[1000];
-};
-
-bool BlastFamily::overlap(const PxGeometry& geometry, const PxTransform& pose, std::function<void(ExtPxActor*, BlastFamily&)> hitCall)
-{
- std::set<ExtPxActor*> actorsToDamage;
-#if 1
- BlastOverlapCallback overlapCallback(m_pxManager, actorsToDamage);
- m_physXController.getPhysXScene().overlap(geometry, pose, overlapCallback);
-#else
- for (std::map<NvBlastActor*, PhysXController::Actor*>::iterator it = m_actorsMap.begin(); it != m_actorsMap.end(); it++)
- {
- actorsToDamage.insert(it->first);
- }
-#endif
-
- for (auto actor : actorsToDamage)
- {
- hitCall(actor, *this);
- }
-
- return !actorsToDamage.empty();
-}
-
+// 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-2018 NVIDIA Corporation. All rights reserved.
+
+
+#include "BlastFamily.h"
+#include "SampleProfiler.h"
+#include "PhysXController.h"
+#include "RenderUtils.h"
+#include "SampleTime.h"
+#include "UIHelpers.h"
+
+#include "NvBlast.h"
+#include "NvBlastTkFamily.h"
+#include "NvBlastTkActor.h"
+#include "NvBlastTkAsset.h"
+#include "NvBlastTkJoint.h"
+#include "NvBlastExtPxAsset.h"
+#include "NvBlastExtPxActor.h"
+#include "NvBlastExtPxFamily.h"
+#include "NvBlastExtPxManager.h"
+
+#include "PxRigidDynamic.h"
+#include "PxScene.h"
+#include "PxJoint.h"
+
+
+const float RIGIDBODY_DENSITY = 2000.0f;
+
+BlastFamily::BlastFamily(PhysXController& physXController, ExtPxManager& pxManager, const BlastAsset& blastAsset)
+ : m_physXController(physXController)
+ , m_pxManager(pxManager)
+ , m_blastAsset(blastAsset)
+ , m_listener(this)
+ , m_totalVisibleChunkCount(0)
+ , m_stressSolver(nullptr)
+ , m_spawned(false)
+ , m_debugRenderDepth(-1)
+{
+ m_settings.stressSolverEnabled = false;
+ m_settings.stressDamageEnabled = false;
+ m_settings.damageAcceleratorEnabled = true;
+}
+
+BlastFamily::~BlastFamily()
+{
+ if (m_stressSolver)
+ {
+ m_stressSolver->release();
+ }
+
+ m_pxFamily->unsubscribe(m_listener);
+
+ m_pxFamily->release();
+}
+
+void BlastFamily::initialize(const BlastAsset::ActorDesc& desc)
+{
+ ExtPxFamilyDesc familyDesc;
+ familyDesc.actorDesc = nullptr; // if you use it one day, consider changing code which needs getBondHealthMax() from BlastAsset.
+ familyDesc.group = desc.group;
+ familyDesc.pxAsset = m_blastAsset.getPxAsset();
+ m_pxFamily = m_pxManager.createFamily(familyDesc);
+ m_pxFamily->setMaterial(&m_settings.material);
+
+
+ m_tkFamily = &m_pxFamily->getTkFamily();
+ m_tkFamily->setID(desc.id);
+
+ refreshDamageAcceleratorSettings();
+
+ m_familySize = NvBlastFamilyGetSize(m_tkFamily->getFamilyLL(), nullptr);
+
+ m_pxFamily->subscribe(m_listener);
+
+ m_initialTransform = desc.transform;
+}
+
+void BlastFamily::updatePreSplit(float dt)
+{
+ if (!m_spawned)
+ {
+ ExtPxSpawnSettings spawnSettings = {
+ &m_physXController.getPhysXScene(),
+ m_physXController.getDefaultMaterial(),
+ RIGIDBODY_DENSITY
+ };
+
+ m_pxFamily->spawn(m_initialTransform, PxVec3(1.0f), spawnSettings);
+ reloadStressSolver();
+
+ m_spawned = true;
+ }
+
+ // collect potential actors to health update
+ m_actorsToUpdateHealth.clear();
+ for (const ExtPxActor* actor : m_actors)
+ {
+ if (actor->getTkActor().isPending())
+ {
+ m_actorsToUpdateHealth.emplace(actor);
+ }
+ }
+}
+
+void BlastFamily::updateAfterSplit(float dt)
+{
+ PROFILER_BEGIN("Actor Health Update");
+ for (const ExtPxActor* actor : m_actors)
+ {
+ onActorUpdate(*actor);
+
+ // update health if neccessary
+ if (m_actorsToUpdateHealth.find(actor) != m_actorsToUpdateHealth.end())
+ {
+ onActorHealthUpdate(*actor);
+ }
+ }
+ PROFILER_END();
+
+ PROFILER_BEGIN("Stress Solver");
+ // update stress
+ m_stressSolveTime = 0;
+ if (m_stressSolver)
+ {
+ Time t;
+ m_stressSolver->update(m_settings.stressDamageEnabled);
+ m_stressSolveTime += t.getElapsedSeconds();
+ }
+ PROFILER_END();
+
+ PROFILER_BEGIN("Actor Misc Update");
+ onUpdate();
+ PROFILER_END();
+
+ m_pxFamily->postSplitUpdate();
+}
+
+void BlastFamily::processActorCreated(ExtPxFamily&, ExtPxActor& actor)
+{
+ m_totalVisibleChunkCount += actor.getChunkCount();
+ m_actors.emplace(&actor);
+
+ onActorCreated(actor);
+ onActorHealthUpdate(actor);
+}
+
+void BlastFamily::processActorDestroyed(ExtPxFamily&, ExtPxActor& actor)
+{
+ m_totalVisibleChunkCount -= actor.getChunkCount();
+ m_physXController.notifyRigidDynamicDestroyed(&actor.getPhysXActor());
+
+ onActorDestroyed(actor);
+
+ m_actors.erase(m_actors.find(&actor));
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Data Helpers
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+uint32_t BlastFamily::getActorCount() const
+{
+ return (uint32_t)m_tkFamily->getActorCount();
+}
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// UI
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void BlastFamily::drawUI()
+{
+ // Blast Material
+ ImGui::Spacing();
+ ImGui::Text("Blast Material:");
+ ImGui::DragFloat("Health", &m_settings.material.health);
+ ImGui::DragFloat("Min Damage Threshold", &m_settings.material.minDamageThreshold, 0.01f, 0.f, m_settings.material.maxDamageThreshold);
+ ImGui::DragFloat("Max Damage Threshold", &m_settings.material.maxDamageThreshold, 0.01f, m_settings.material.minDamageThreshold, 1.f);
+
+ if (ImGui::Checkbox("AABB Tree (Damage Accelerator)", &m_settings.damageAcceleratorEnabled))
+ {
+ refreshDamageAcceleratorSettings();
+ }
+ if (m_settings.damageAcceleratorEnabled)
+ {
+ ImGui::DragInt("AABB Tree debug depth", &m_debugRenderDepth);
+ }
+
+
+ ImGui::Spacing();
+
+ // Stress Solver Settings
+ if (ImGui::Checkbox("Stress Solver Enabled", &m_settings.stressSolverEnabled))
+ {
+ reloadStressSolver();
+ }
+
+ if (m_settings.stressSolverEnabled)
+ {
+ // Settings
+ bool changed = false;
+
+ changed |= ImGui::DragInt("Bond Iterations Per Frame", (int*)&m_settings.stressSolverSettings.bondIterationsPerFrame, 100, 0, 500000);
+ changed |= ImGui::DragFloat("Material Hardness", &m_settings.stressSolverSettings.hardness, 10.0f, 0.01f, 100000.0f, "%.2f");
+ changed |= ImGui::DragFloat("Stress Linear Factor", &m_settings.stressSolverSettings.stressLinearFactor, 0.01f, 0.0f, 100.0f, "%.2f");
+ changed |= ImGui::DragFloat("Stress Angular Factor", &m_settings.stressSolverSettings.stressAngularFactor, 0.01f, 0.0f, 100.0f, "%.2f");
+ changed |= ImGui::SliderInt("Graph Reduction Level", (int*)&m_settings.stressSolverSettings.graphReductionLevel, 0, 32);
+ if (changed)
+ {
+ refreshStressSolverSettings();
+ }
+
+ ImGui::Checkbox("Stress Damage Enabled", &m_settings.stressDamageEnabled);
+
+ if (ImGui::Button("Recalculate Stress"))
+ {
+ resetStress();
+ }
+ }
+}
+
+void BlastFamily::drawStatsUI()
+{
+ ImGui::PushStyleColor(ImGuiCol_Text, ImColor(10, 255, 10, 255));
+ if (m_stressSolver)
+ {
+ const ExtStressSolver& stressSolver = m_stressSolver->getSolver();
+ const float errorLinear = stressSolver.getStressErrorLinear();
+ const float errorAngular = stressSolver.getStressErrorAngular();
+
+ ImGui::Text("Stress Bond Count: %d", stressSolver.getBondCount());
+ ImGui::Text("Stress Frame Iter: %d", stressSolver.getIterationsPerFrame());
+ ImGui::Text("Stress Frames: %d", stressSolver.getFrameCount());
+ ImGui::Text("Stress Error Lin / Ang: %.4f / %.4f", errorLinear, errorAngular);
+ ImGui::Text("Stress Solve Time: %.3f ms", m_stressSolveTime * 1000);
+
+ // plot errors
+ {
+ static float scale = 1.0f;
+ scale = stressSolver.getFrameCount() <= 1 ? 1.0f : scale;
+ scale = std::max<float>(scale, errorLinear);
+ scale = std::max<float>(scale, errorAngular);
+
+ static PlotLinesInstance<> linearErrorPlot;
+ linearErrorPlot.plot("Stress Linear Error", errorLinear, "error/frame", 0.0f, 1.0f * scale);
+ static PlotLinesInstance<> angularErrorPlot;
+ angularErrorPlot.plot("Stress Angular Error", errorAngular, "error/frame", 0.0f, 1.0f * scale);
+ }
+ }
+ else
+ {
+ ImGui::Text("No Stress Solver");
+ }
+ ImGui::PopStyleColor();
+}
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Stress Solver
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void BlastFamily::setSettings(const Settings& settings)
+{
+ bool reloadStressSolverNeeded = (m_settings.stressSolverEnabled != settings.stressSolverEnabled);
+
+ m_settings = settings;
+ refreshStressSolverSettings();
+ refreshDamageAcceleratorSettings();
+
+ if (reloadStressSolverNeeded)
+ {
+ reloadStressSolver();
+ }
+
+ m_pxFamily->setMaterial(&m_settings.material);
+}
+
+void BlastFamily::refreshDamageAcceleratorSettings()
+{
+ m_pxFamily->getPxAsset().setAccelerator(m_settings.damageAcceleratorEnabled ? m_blastAsset.getAccelerator() : nullptr);
+}
+
+void BlastFamily::refreshStressSolverSettings()
+{
+ if (m_stressSolver)
+ {
+ m_stressSolver->getSolver().setSettings(m_settings.stressSolverSettings);
+ }
+}
+
+void BlastFamily::resetStress()
+{
+ if (m_stressSolver)
+ {
+ m_stressSolver->getSolver().reset();
+ }
+}
+
+void BlastFamily::reloadStressSolver()
+{
+ if (m_stressSolver)
+ {
+ m_stressSolver->release();
+ m_stressSolver = nullptr;
+ }
+
+ if (m_settings.stressSolverEnabled)
+ {
+ m_stressSolver = ExtPxStressSolver::create(*m_pxFamily, m_settings.stressSolverSettings);
+ m_pxFamily->userData = m_stressSolver;
+ }
+}
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// debug render
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+const DirectX::XMFLOAT4 BOND_NORMAL_COLOR(0.0f, 0.8f, 1.0f, 1.0f);
+const DirectX::XMFLOAT4 BOND_INVISIBLE_COLOR(0.65f, 0.16f, 0.16f, 1.0f);
+const DirectX::XMFLOAT4 BOND_IMPULSE_LINEAR_COLOR(0.0f, 1.0f, 0.0f, 1.0f);
+const DirectX::XMFLOAT4 BOND_IMPULSE_ANGULAR_COLOR(1.0f, 0.0f, 0.0f, 1.0f);
+const DirectX::XMFLOAT4 JOINT_COLOR(0.5f, 0.6f, 7.0f, 1.0f);
+
+
+inline void pushCentroid(std::vector<PxDebugLine>& lines, PxVec3 pos, PxU32 color, const float& area, const PxVec3& normal)
+{
+ // draw square of area 'area' rotated by normal
+ {
+ // build world rotation
+ PxVec3 n0(0, 0, 1);
+ PxVec3 n1 = normal;
+ PxVec3 axis = n0.cross(n1);
+ float d = n0.dot(n1);
+ PxQuat q(axis.x, axis.y, axis.z, 1.f + d);
+ q.normalize();
+ float e = PxSqrt(1.0f / 2.0f);
+ float r = PxSqrt(area);
+
+ // transform all 4 square points
+ PxTransform t(pos, q);
+ PxVec3 p0 = t.transform(PxVec3(-e, e, 0) * r);
+ PxVec3 p1 = t.transform(PxVec3( e, e, 0) * r);
+ PxVec3 p2 = t.transform(PxVec3( e, -e, 0) * r);
+ PxVec3 p3 = t.transform(PxVec3(-e, -e, 0) * r);
+
+ // push square edges
+ lines.push_back(PxDebugLine(p0, p1, color));
+ lines.push_back(PxDebugLine(p3, p2, color));
+ lines.push_back(PxDebugLine(p1, p2, color));
+ lines.push_back(PxDebugLine(p0, p3, color));
+ }
+
+ // draw normal
+ lines.push_back(PxDebugLine(pos, pos + normal * 0.5f, XMFLOAT4ToU32Color(BOND_NORMAL_COLOR)));
+}
+
+inline DirectX::XMFLOAT4 bondHealthColor(float healthFraction)
+{
+ const DirectX::XMFLOAT4 BOND_HEALTHY_COLOR(0.0f, 1.0f, 0.0f, 1.0f);
+ const DirectX::XMFLOAT4 BOND_MID_COLOR(1.0f, 1.0f, 0.0f, 1.0f);
+ const DirectX::XMFLOAT4 BOND_BROKEN_COLOR(1.0f, 0.0f, 0.0f, 1.0f);
+
+ return healthFraction < 0.5 ? XMFLOAT4Lerp(BOND_BROKEN_COLOR, BOND_MID_COLOR, 2.0f * healthFraction) : XMFLOAT4Lerp(BOND_MID_COLOR, BOND_HEALTHY_COLOR, 2.0f * healthFraction - 1.0f);
+}
+
+void BlastFamily::fillDebugRender(DebugRenderBuffer& debugRenderBuffer, DebugRenderMode mode, float renderScale)
+{
+ const NvBlastChunk* chunks = m_tkFamily->getAsset()->getChunks();
+ const NvBlastBond* bonds = m_tkFamily->getAsset()->getBonds();
+ const NvBlastSupportGraph graph = m_tkFamily->getAsset()->getGraph();
+ const float bondHealthMax = m_blastAsset.getBondHealthMax();
+ const uint32_t chunkCount = m_tkFamily->getAsset()->getChunkCount();
+
+ for (const ExtPxActor* pxActor : m_actors)
+ {
+ TkActor& actor = pxActor->getTkActor();
+ uint32_t lineStartIndex = (uint32_t)debugRenderBuffer.m_lines.size();
+
+ uint32_t nodeCount = actor.getGraphNodeCount();
+ if (nodeCount == 0) // subsupport chunks don't have graph nodes
+ continue;
+
+ std::vector<uint32_t> nodes(nodeCount);
+ actor.getGraphNodeIndices(nodes.data(), static_cast<uint32_t>(nodes.size()));
+
+ if (DEBUG_RENDER_HEALTH_GRAPH <= mode && mode <= DEBUG_RENDER_HEALTH_GRAPH_CENTROIDS)
+ {
+ const float* bondHealths = actor.getBondHealths();
+
+ const ExtPxChunk* pxChunks = m_blastAsset.getPxAsset()->getChunks();
+
+ for (uint32_t node0 : nodes)
+ {
+ const uint32_t chunkIndex0 = graph.chunkIndices[node0];
+ const NvBlastChunk& blastChunk0 = chunks[chunkIndex0];
+ const ExtPxChunk& assetChunk0 = pxChunks[chunkIndex0];
+
+ for (uint32_t adjacencyIndex = graph.adjacencyPartition[node0]; adjacencyIndex < graph.adjacencyPartition[node0 + 1]; adjacencyIndex++)
+ {
+ uint32_t node1 = graph.adjacentNodeIndices[adjacencyIndex];
+ const uint32_t chunkIndex1 = graph.chunkIndices[node1];
+ const NvBlastChunk& blastChunk1 = chunks[chunkIndex1];
+ const ExtPxChunk& assetChunk1 = pxChunks[chunkIndex1];
+ if (node0 > node1)
+ continue;
+
+ bool invisibleBond = chunkIndex0 >= chunkCount || chunkIndex1 >= chunkCount || assetChunk0.subchunkCount == 0 || assetChunk1.subchunkCount == 0;
+
+ // health
+ uint32_t bondIndex = graph.adjacentBondIndices[adjacencyIndex];
+ float healthVal = PxClamp(bondHealths[bondIndex] / bondHealthMax, 0.0f, 1.0f);
+
+ DirectX::XMFLOAT4 color = bondHealthColor(healthVal);
+
+ const NvBlastBond& solverBond = bonds[bondIndex];
+ const PxVec3& centroid = reinterpret_cast<const PxVec3&>(solverBond.centroid);
+
+ // centroid
+ if (mode == DEBUG_RENDER_HEALTH_GRAPH_CENTROIDS || mode == DEBUG_RENDER_CENTROIDS)
+ {
+ const PxVec3& normal = reinterpret_cast<const PxVec3&>(solverBond.normal);
+ pushCentroid(debugRenderBuffer.m_lines, centroid, XMFLOAT4ToU32Color(invisibleBond ? BOND_INVISIBLE_COLOR : color), solverBond.area, normal.getNormalized());
+ }
+
+ // chunk connection (bond)
+ if ((mode == DEBUG_RENDER_HEALTH_GRAPH || mode == DEBUG_RENDER_HEALTH_GRAPH_CENTROIDS) && !invisibleBond)
+ {
+ const PxVec3& c0 = reinterpret_cast<const PxVec3&>(blastChunk0.centroid);
+ const PxVec3& c1 = reinterpret_cast<const PxVec3&>(blastChunk1.centroid);
+ debugRenderBuffer.m_lines.push_back(PxDebugLine(c0, c1, XMFLOAT4ToU32Color(color)));
+ }
+ }
+ }
+ }
+
+ // stress
+ if (DEBUG_RENDER_STRESS_GRAPH <= mode && mode <= DEBUG_RENDER_STRESS_GRAPH_BONDS_IMPULSES)
+ {
+ if (m_stressSolver)
+ {
+ const auto buffer = m_stressSolver->getSolver().fillDebugRender(nodes.data(), (uint32_t)nodes.size(), (ExtStressSolver::DebugRenderMode)(mode - DEBUG_RENDER_STRESS_GRAPH), renderScale);
+ if (buffer.lineCount)
+ {
+ const auto lines = reinterpret_cast<const PxDebugLine*>(buffer.lines);
+ debugRenderBuffer.m_lines.insert(debugRenderBuffer.m_lines.end(), lines, lines + buffer.lineCount);
+ }
+ }
+ }
+
+ // AABB tree
+ if (mode == DEBUG_RENDER_AABB_TREE_CENTROIDS || mode == DEBUG_RENDER_AABB_TREE_SEGMENTS)
+ {
+ if (m_settings.damageAcceleratorEnabled && m_blastAsset.getAccelerator() && nodeCount > graph.nodeCount / 2)
+ {
+ const auto buffer = m_blastAsset.getAccelerator()->fillDebugRender(m_debugRenderDepth, mode == DEBUG_RENDER_AABB_TREE_SEGMENTS);
+ if (buffer.lineCount)
+ {
+ const auto lines = reinterpret_cast<const PxDebugLine*>(buffer.lines);
+ debugRenderBuffer.m_lines.insert(debugRenderBuffer.m_lines.end(), lines, lines + buffer.lineCount);
+ }
+ }
+ }
+
+ // transform all added lines from local to global
+ PxTransform localToGlobal = pxActor->getPhysXActor().getGlobalPose();
+ for (uint32_t i = lineStartIndex; i < debugRenderBuffer.m_lines.size(); i++)
+ {
+ PxDebugLine& line = debugRenderBuffer.m_lines[i];
+ line.pos0 = localToGlobal.transform(line.pos0);
+ line.pos1 = localToGlobal.transform(line.pos1);
+ }
+ }
+
+ // joints debug render
+ if (mode == DEBUG_RENDER_JOINTS)
+ {
+ for (const ExtPxActor* pxActor : m_actors)
+ {
+ TkActor& actor = pxActor->getTkActor();
+ const uint32_t jointCount = actor.getJointCount();
+ if (jointCount > 0)
+ {
+ std::vector<TkJoint*> joints(jointCount);
+ actor.getJoints(joints.data(), jointCount);
+ for (auto joint : joints)
+ {
+ PxJoint* pxJoint = reinterpret_cast<PxJoint*>(joint->userData);
+ if (pxJoint)
+ {
+ PxRigidActor *actor0, *actor1;
+ pxJoint->getActors(actor0, actor1);
+ auto lp0 = pxJoint->getLocalPose(PxJointActorIndex::eACTOR0);
+ auto lp1 = pxJoint->getLocalPose(PxJointActorIndex::eACTOR1);
+ PxVec3 p0 = actor0 ? actor0->getGlobalPose().transform(lp0).p : lp0.p;
+ PxVec3 p1 = actor1 ? actor1->getGlobalPose().transform(lp1).p : lp1.p;
+ debugRenderBuffer.m_lines.push_back(PxDebugLine(p0, p1, XMFLOAT4ToU32Color(JOINT_COLOR)));
+ }
+ }
+ }
+ }
+ }
+}
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// action!!!
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+class BlastOverlapCallback : public PxOverlapCallback
+{
+public:
+ BlastOverlapCallback(ExtPxManager& pxManager, std::set<ExtPxActor*>& actorBuffer)
+ : m_pxManager(pxManager), m_actorBuffer(actorBuffer), PxOverlapCallback(m_hitBuffer, sizeof(m_hitBuffer) / sizeof(m_hitBuffer[0])) {}
+
+ PxAgain processTouches(const PxOverlapHit* buffer, PxU32 nbHits)
+ {
+ for (PxU32 i = 0; i < nbHits; ++i)
+ {
+ PxRigidDynamic* rigidDynamic = buffer[i].actor->is<PxRigidDynamic>();
+ if (rigidDynamic)
+ {
+ ExtPxActor* actor = m_pxManager.getActorFromPhysXActor(*rigidDynamic);
+ if (actor != nullptr)
+ {
+ m_actorBuffer.insert(actor);
+ }
+ }
+ }
+ return true;
+ }
+
+private:
+ ExtPxManager& m_pxManager;
+ std::set<ExtPxActor*>& m_actorBuffer;
+ PxOverlapHit m_hitBuffer[1000];
+};
+
+bool BlastFamily::overlap(const PxGeometry& geometry, const PxTransform& pose, std::function<void(ExtPxActor*, BlastFamily&)> hitCall)
+{
+ std::set<ExtPxActor*> actorsToDamage;
+#if 1
+ BlastOverlapCallback overlapCallback(m_pxManager, actorsToDamage);
+ m_physXController.getPhysXScene().overlap(geometry, pose, overlapCallback);
+#else
+ for (std::map<NvBlastActor*, PhysXController::Actor*>::iterator it = m_actorsMap.begin(); it != m_actorsMap.end(); it++)
+ {
+ actorsToDamage.insert(it->first);
+ }
+#endif
+
+ for (auto actor : actorsToDamage)
+ {
+ hitCall(actor, *this);
+ }
+
+ return !actorsToDamage.empty();
+}
+
diff --git a/samples/SampleBase/blast/BlastFamily.h b/samples/SampleBase/blast/BlastFamily.h
index 815771a..4932b6f 100644..100755
--- a/samples/SampleBase/blast/BlastFamily.h
+++ b/samples/SampleBase/blast/BlastFamily.h
@@ -1,232 +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) 2008-2018 NVIDIA Corporation. All rights reserved.
-
-
-#ifndef BLAST_FAMILY_H
-#define BLAST_FAMILY_H
-
-#include "BlastAsset.h"
-#include "NvBlastExtPxListener.h"
-#include "NvBlastExtPxStressSolver.h"
-#include "NvBlastExtDamageShaders.h"
-#include <functional>
-#include <set>
-
-
-class DebugRenderBuffer;
-
-namespace Nv
-{
-namespace Blast
-{
-class TkFamily;
-class ExtPxManager;
-}
-}
-
-namespace physx
-{
-class PxGeometry;
-class PxTransform;
-}
-
-
-
-/**
-BlastFamily class represents 1 spawned BlastAsset, contains and manipulates all physx/blast actors spawned by fracturing it.
-Abstract class, internal actor management functions are implementation dependent and so pure virtual.
-*/
-class BlastFamily
-{
-public:
-
- //////// public API ////////
-
- bool overlap(const PxGeometry& geometry, const PxTransform& pose, std::function<void(ExtPxActor*, BlastFamily&)> hitCall);
-
- void updatePreSplit(float dt);
- void updateAfterSplit(float dt);
-
- void drawUI();
- void drawStatsUI();
-
-
- enum DebugRenderMode
- {
- DEBUG_RENDER_DISABLED,
- DEBUG_RENDER_HEALTH_GRAPH,
- DEBUG_RENDER_CENTROIDS,
- DEBUG_RENDER_HEALTH_GRAPH_CENTROIDS,
- DEBUG_RENDER_JOINTS,
- DEBUG_RENDER_AABB_TREE_CENTROIDS,
- DEBUG_RENDER_AABB_TREE_SEGMENTS,
- DEBUG_RENDER_STRESS_GRAPH,
- DEBUG_RENDER_STRESS_GRAPH_NODES_IMPULSES,
- DEBUG_RENDER_STRESS_GRAPH_BONDS_IMPULSES,
-
- // count
- DEBUG_RENDER_MODES_COUNT
- };
-
- void fillDebugRender(DebugRenderBuffer& debugRenderBuffer, DebugRenderMode mode, float renderScale);
-
-
- //////// public getters ////////
-
- const ExtPxFamily* getFamily() const
- {
- return m_pxFamily;
- }
-
- const NvBlastExtMaterial& getMaterial() const
- {
- return m_settings.material;
- }
-
- uint32_t getActorCount() const;
-
- uint32_t getTotalVisibleChunkCount() const
- {
- return m_totalVisibleChunkCount;
- }
-
- size_t getFamilySize() const
- {
- return m_familySize;
- }
-
- const BlastAsset& getBlastAsset()
- {
- return m_blastAsset;
- }
-
- void resetStress();
-
- void refreshStressSolverSettings();
- void refreshDamageAcceleratorSettings();
-
- void reloadStressSolver();
-
-
- //////// settings ////////
-
- struct Settings
- {
- bool stressSolverEnabled;
- ExtStressSolverSettings stressSolverSettings;
- bool stressDamageEnabled;
- bool damageAcceleratorEnabled;
- NvBlastExtMaterial material;
- };
-
- void setSettings(const Settings& settings);
-
- const Settings& getSettings() const
- {
- return m_settings;
- }
-
-
- //////// dtor ////////
-
- virtual ~BlastFamily();
-
-protected:
-
- //////// ctor ////////
-
- BlastFamily(PhysXController& physXController, ExtPxManager& pxManager, const BlastAsset& blastAsset);
-
- void initialize(const BlastAsset::ActorDesc& desc);
-
-
- //////// internal virtual callbacks ////////
-
- virtual void onActorCreated(const ExtPxActor& actor) = 0;
- virtual void onActorUpdate(const ExtPxActor& actor) = 0;
- virtual void onActorDestroyed(const ExtPxActor& actor) = 0;
- virtual void onActorHealthUpdate(const ExtPxActor& pxActor) {};
-
- virtual void onUpdate() {}
-
-
- //////// protected data ////////
-
- PhysXController& m_physXController;
- ExtPxManager& m_pxManager;
- const BlastAsset& m_blastAsset;
-
-private:
-
- //////// physics listener ////////
-
- class PxManagerListener : public ExtPxListener
- {
- public:
- PxManagerListener(BlastFamily* family) : m_family(family) {}
-
- virtual void onActorCreated(ExtPxFamily& family, ExtPxActor& actor)
- {
- m_family->processActorCreated(family, actor);
-
- }
-
- virtual void onActorDestroyed(ExtPxFamily& family, ExtPxActor& actor)
- {
- m_family->processActorDestroyed(family, actor);
- }
- private:
- BlastFamily* m_family;
- };
-
- friend class PxManagerListener;
-
- //////// private methods ////////
-
- void processActorCreated(ExtPxFamily&, ExtPxActor& actor);
- void processActorDestroyed(ExtPxFamily&, ExtPxActor& actor);
-
-
- //////// private data ////////
-
- TkFamily* m_tkFamily;
- ExtPxFamily* m_pxFamily;
- PxManagerListener m_listener;
- Settings m_settings;
- PxTransform m_initialTransform;
- bool m_spawned;
- size_t m_familySize;
- uint32_t m_totalVisibleChunkCount;
- ExtPxStressSolver* m_stressSolver;
- double m_stressSolveTime;
- std::set<ExtPxActor*> m_actors;
- std::set<const ExtPxActor*> m_actorsToUpdateHealth;
- int m_debugRenderDepth;
-};
-
-
+// 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-2018 NVIDIA Corporation. All rights reserved.
+
+
+#ifndef BLAST_FAMILY_H
+#define BLAST_FAMILY_H
+
+#include "BlastAsset.h"
+#include "NvBlastExtPxListener.h"
+#include "NvBlastExtPxStressSolver.h"
+#include "NvBlastExtDamageShaders.h"
+#include <functional>
+#include <set>
+
+
+class DebugRenderBuffer;
+
+namespace Nv
+{
+namespace Blast
+{
+class TkFamily;
+class ExtPxManager;
+}
+}
+
+namespace physx
+{
+class PxGeometry;
+class PxTransform;
+}
+
+
+
+/**
+BlastFamily class represents 1 spawned BlastAsset, contains and manipulates all physx/blast actors spawned by fracturing it.
+Abstract class, internal actor management functions are implementation dependent and so pure virtual.
+*/
+class BlastFamily
+{
+public:
+
+ //////// public API ////////
+
+ bool overlap(const PxGeometry& geometry, const PxTransform& pose, std::function<void(ExtPxActor*, BlastFamily&)> hitCall);
+
+ void updatePreSplit(float dt);
+ void updateAfterSplit(float dt);
+
+ void drawUI();
+ void drawStatsUI();
+
+
+ enum DebugRenderMode
+ {
+ DEBUG_RENDER_DISABLED,
+ DEBUG_RENDER_HEALTH_GRAPH,
+ DEBUG_RENDER_CENTROIDS,
+ DEBUG_RENDER_HEALTH_GRAPH_CENTROIDS,
+ DEBUG_RENDER_JOINTS,
+ DEBUG_RENDER_AABB_TREE_CENTROIDS,
+ DEBUG_RENDER_AABB_TREE_SEGMENTS,
+ DEBUG_RENDER_STRESS_GRAPH,
+ DEBUG_RENDER_STRESS_GRAPH_NODES_IMPULSES,
+ DEBUG_RENDER_STRESS_GRAPH_BONDS_IMPULSES,
+
+ // count
+ DEBUG_RENDER_MODES_COUNT
+ };
+
+ void fillDebugRender(DebugRenderBuffer& debugRenderBuffer, DebugRenderMode mode, float renderScale);
+
+
+ //////// public getters ////////
+
+ const ExtPxFamily* getFamily() const
+ {
+ return m_pxFamily;
+ }
+
+ const NvBlastExtMaterial& getMaterial() const
+ {
+ return m_settings.material;
+ }
+
+ uint32_t getActorCount() const;
+
+ uint32_t getTotalVisibleChunkCount() const
+ {
+ return m_totalVisibleChunkCount;
+ }
+
+ size_t getFamilySize() const
+ {
+ return m_familySize;
+ }
+
+ const BlastAsset& getBlastAsset()
+ {
+ return m_blastAsset;
+ }
+
+ void resetStress();
+
+ void refreshStressSolverSettings();
+ void refreshDamageAcceleratorSettings();
+
+ void reloadStressSolver();
+
+
+ //////// settings ////////
+
+ struct Settings
+ {
+ bool stressSolverEnabled;
+ ExtStressSolverSettings stressSolverSettings;
+ bool stressDamageEnabled;
+ bool damageAcceleratorEnabled;
+ NvBlastExtMaterial material;
+ };
+
+ void setSettings(const Settings& settings);
+
+ const Settings& getSettings() const
+ {
+ return m_settings;
+ }
+
+
+ //////// dtor ////////
+
+ virtual ~BlastFamily();
+
+protected:
+
+ //////// ctor ////////
+
+ BlastFamily(PhysXController& physXController, ExtPxManager& pxManager, const BlastAsset& blastAsset);
+
+ void initialize(const BlastAsset::ActorDesc& desc);
+
+
+ //////// internal virtual callbacks ////////
+
+ virtual void onActorCreated(const ExtPxActor& actor) = 0;
+ virtual void onActorUpdate(const ExtPxActor& actor) = 0;
+ virtual void onActorDestroyed(const ExtPxActor& actor) = 0;
+ virtual void onActorHealthUpdate(const ExtPxActor& pxActor) {};
+
+ virtual void onUpdate() {}
+
+
+ //////// protected data ////////
+
+ PhysXController& m_physXController;
+ ExtPxManager& m_pxManager;
+ const BlastAsset& m_blastAsset;
+
+private:
+
+ //////// physics listener ////////
+
+ class PxManagerListener : public ExtPxListener
+ {
+ public:
+ PxManagerListener(BlastFamily* family) : m_family(family) {}
+
+ virtual void onActorCreated(ExtPxFamily& family, ExtPxActor& actor)
+ {
+ m_family->processActorCreated(family, actor);
+
+ }
+
+ virtual void onActorDestroyed(ExtPxFamily& family, ExtPxActor& actor)
+ {
+ m_family->processActorDestroyed(family, actor);
+ }
+ private:
+ BlastFamily* m_family;
+ };
+
+ friend class PxManagerListener;
+
+ //////// private methods ////////
+
+ void processActorCreated(ExtPxFamily&, ExtPxActor& actor);
+ void processActorDestroyed(ExtPxFamily&, ExtPxActor& actor);
+
+
+ //////// private data ////////
+
+ TkFamily* m_tkFamily;
+ ExtPxFamily* m_pxFamily;
+ PxManagerListener m_listener;
+ Settings m_settings;
+ PxTransform m_initialTransform;
+ bool m_spawned;
+ size_t m_familySize;
+ uint32_t m_totalVisibleChunkCount;
+ ExtPxStressSolver* m_stressSolver;
+ double m_stressSolveTime;
+ std::set<ExtPxActor*> m_actors;
+ std::set<const ExtPxActor*> m_actorsToUpdateHealth;
+ int m_debugRenderDepth;
+};
+
+
#endif //BLAST_FAMILY_H \ No newline at end of file
diff --git a/samples/SampleBase/blast/BlastFamilyBoxes.cpp b/samples/SampleBase/blast/BlastFamilyBoxes.cpp
index 4ba91fa..59a15f4 100644..100755
--- a/samples/SampleBase/blast/BlastFamilyBoxes.cpp
+++ b/samples/SampleBase/blast/BlastFamilyBoxes.cpp
@@ -1,109 +1,109 @@
-// 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-2018 NVIDIA Corporation. All rights reserved.
-
-
-#include "BlastFamilyBoxes.h"
-#include "NvBlastExtPxAsset.h"
-#include "NvBlastExtPxActor.h"
-#include "BlastAssetBoxes.h"
-#include "Renderer.h"
-#include "PhysXController.h"
-#include "RenderUtils.h"
-#include "PxRigidDynamic.h"
-
-using namespace physx;
-
-
-BlastFamilyBoxes::BlastFamilyBoxes(PhysXController& physXController, ExtPxManager& pxManager, Renderer& renderer, const BlastAssetBoxes& blastAsset, const BlastAsset::ActorDesc& desc)
- : BlastFamily(physXController, pxManager, blastAsset), m_renderer(renderer)
-{
- // prepare renderables
- IRenderMesh* boxRenderMesh = renderer.getPrimitiveRenderMesh(PrimitiveRenderMeshType::Box);
- RenderMaterial* primitiveRenderMaterial = physXController.getPrimitiveRenderMaterial();
-
- const ExtPxAsset* pxAsset = m_blastAsset.getPxAsset();
- const uint32_t chunkCount = pxAsset->getChunkCount();
- const ExtPxChunk* chunks = pxAsset->getChunks();
- const ExtPxSubchunk* subChunks = pxAsset->getSubchunks();
- m_chunkRenderables.resize(chunkCount);
- for (uint32_t i = 0; i < chunkCount; i++)
- {
- Renderable* renderable = renderer.createRenderable(*boxRenderMesh, *primitiveRenderMaterial);
- renderable->setHidden(true);
- renderable->setScale(subChunks[chunks[i].firstSubchunkIndex].geometry.scale.scale);
- m_chunkRenderables[i] = renderable;
- }
-
- // initialize in position
- initialize(desc);
-}
-
-BlastFamilyBoxes::~BlastFamilyBoxes()
-{
- for (uint32_t i = 0; i < m_chunkRenderables.size(); i++)
- {
- m_renderer.removeRenderable(m_chunkRenderables[i]);
- }
-}
-
-void BlastFamilyBoxes::onActorCreated(const ExtPxActor& actor)
-{
- DirectX::XMFLOAT4 color = getRandomPastelColor();
-
- const uint32_t* chunkIndices = actor.getChunkIndices();
- uint32_t chunkCount = actor.getChunkCount();
- for (uint32_t i = 0; i < chunkCount; i++)
- {
- const uint32_t chunkIndex = chunkIndices[i];
- m_chunkRenderables[chunkIndex]->setHidden(false);
- m_chunkRenderables[chunkIndex]->setColor(color);
- }
-}
-
-void BlastFamilyBoxes::onActorUpdate(const ExtPxActor& actor)
-{
- const ExtPxChunk* chunks = m_blastAsset.getPxAsset()->getChunks();
- const ExtPxSubchunk* subChunks = m_blastAsset.getPxAsset()->getSubchunks();
- const uint32_t* chunkIndices = actor.getChunkIndices();
- uint32_t chunkCount = actor.getChunkCount();
- for (uint32_t i = 0; i < chunkCount; i++)
- {
- const uint32_t chunkIndex = chunkIndices[i];
- m_chunkRenderables[chunkIndex]->setTransform(actor.getPhysXActor().getGlobalPose() * subChunks[chunks[chunkIndex].firstSubchunkIndex].transform);
- }
-}
-
-void BlastFamilyBoxes::onActorDestroyed(const ExtPxActor& actor)
-{
- const uint32_t* chunkIndices = actor.getChunkIndices();
- uint32_t chunkCount = actor.getChunkCount();
- for (uint32_t i = 0; i < chunkCount; i++)
- {
- m_chunkRenderables[chunkIndices[i]]->setHidden(true);
- }
-
-}
+// 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-2018 NVIDIA Corporation. All rights reserved.
+
+
+#include "BlastFamilyBoxes.h"
+#include "NvBlastExtPxAsset.h"
+#include "NvBlastExtPxActor.h"
+#include "BlastAssetBoxes.h"
+#include "Renderer.h"
+#include "PhysXController.h"
+#include "RenderUtils.h"
+#include "PxRigidDynamic.h"
+
+using namespace physx;
+
+
+BlastFamilyBoxes::BlastFamilyBoxes(PhysXController& physXController, ExtPxManager& pxManager, Renderer& renderer, const BlastAssetBoxes& blastAsset, const BlastAsset::ActorDesc& desc)
+ : BlastFamily(physXController, pxManager, blastAsset), m_renderer(renderer)
+{
+ // prepare renderables
+ IRenderMesh* boxRenderMesh = renderer.getPrimitiveRenderMesh(PrimitiveRenderMeshType::Box);
+ RenderMaterial* primitiveRenderMaterial = physXController.getPrimitiveRenderMaterial();
+
+ const ExtPxAsset* pxAsset = m_blastAsset.getPxAsset();
+ const uint32_t chunkCount = pxAsset->getChunkCount();
+ const ExtPxChunk* chunks = pxAsset->getChunks();
+ const ExtPxSubchunk* subChunks = pxAsset->getSubchunks();
+ m_chunkRenderables.resize(chunkCount);
+ for (uint32_t i = 0; i < chunkCount; i++)
+ {
+ Renderable* renderable = renderer.createRenderable(*boxRenderMesh, *primitiveRenderMaterial);
+ renderable->setHidden(true);
+ renderable->setScale(subChunks[chunks[i].firstSubchunkIndex].geometry.scale.scale);
+ m_chunkRenderables[i] = renderable;
+ }
+
+ // initialize in position
+ initialize(desc);
+}
+
+BlastFamilyBoxes::~BlastFamilyBoxes()
+{
+ for (uint32_t i = 0; i < m_chunkRenderables.size(); i++)
+ {
+ m_renderer.removeRenderable(m_chunkRenderables[i]);
+ }
+}
+
+void BlastFamilyBoxes::onActorCreated(const ExtPxActor& actor)
+{
+ DirectX::XMFLOAT4 color = getRandomPastelColor();
+
+ const uint32_t* chunkIndices = actor.getChunkIndices();
+ uint32_t chunkCount = actor.getChunkCount();
+ for (uint32_t i = 0; i < chunkCount; i++)
+ {
+ const uint32_t chunkIndex = chunkIndices[i];
+ m_chunkRenderables[chunkIndex]->setHidden(false);
+ m_chunkRenderables[chunkIndex]->setColor(color);
+ }
+}
+
+void BlastFamilyBoxes::onActorUpdate(const ExtPxActor& actor)
+{
+ const ExtPxChunk* chunks = m_blastAsset.getPxAsset()->getChunks();
+ const ExtPxSubchunk* subChunks = m_blastAsset.getPxAsset()->getSubchunks();
+ const uint32_t* chunkIndices = actor.getChunkIndices();
+ uint32_t chunkCount = actor.getChunkCount();
+ for (uint32_t i = 0; i < chunkCount; i++)
+ {
+ const uint32_t chunkIndex = chunkIndices[i];
+ m_chunkRenderables[chunkIndex]->setTransform(actor.getPhysXActor().getGlobalPose() * subChunks[chunks[chunkIndex].firstSubchunkIndex].transform);
+ }
+}
+
+void BlastFamilyBoxes::onActorDestroyed(const ExtPxActor& actor)
+{
+ const uint32_t* chunkIndices = actor.getChunkIndices();
+ uint32_t chunkCount = actor.getChunkCount();
+ for (uint32_t i = 0; i < chunkCount; i++)
+ {
+ m_chunkRenderables[chunkIndices[i]]->setHidden(true);
+ }
+
+}
diff --git a/samples/SampleBase/blast/BlastFamilyBoxes.h b/samples/SampleBase/blast/BlastFamilyBoxes.h
index a6464b2..71df42c 100644..100755
--- a/samples/SampleBase/blast/BlastFamilyBoxes.h
+++ b/samples/SampleBase/blast/BlastFamilyBoxes.h
@@ -1,55 +1,55 @@
-// 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-2018 NVIDIA Corporation. All rights reserved.
-
-
-#ifndef BLAST_FAMILY_BOXES
-#define BLAST_FAMILY_BOXES
-
-#include "BlastFamily.h"
-
-class BlastAssetBoxes;
-class Renderable;
-
-
-class BlastFamilyBoxes : public BlastFamily
-{
-public:
- BlastFamilyBoxes(PhysXController& physXController, ExtPxManager& pxManager, Renderer& renderer, const BlastAssetBoxes& blastAsset, const BlastAsset::ActorDesc& desc);
- virtual ~BlastFamilyBoxes();
-
-protected:
- virtual void onActorCreated(const ExtPxActor& actor);
- virtual void onActorUpdate(const ExtPxActor& actor);
- virtual void onActorDestroyed(const ExtPxActor& actor);
-
-private:
- Renderer& m_renderer;
- std::vector<Renderable*> m_chunkRenderables;
-};
-
-
+// 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-2018 NVIDIA Corporation. All rights reserved.
+
+
+#ifndef BLAST_FAMILY_BOXES
+#define BLAST_FAMILY_BOXES
+
+#include "BlastFamily.h"
+
+class BlastAssetBoxes;
+class Renderable;
+
+
+class BlastFamilyBoxes : public BlastFamily
+{
+public:
+ BlastFamilyBoxes(PhysXController& physXController, ExtPxManager& pxManager, Renderer& renderer, const BlastAssetBoxes& blastAsset, const BlastAsset::ActorDesc& desc);
+ virtual ~BlastFamilyBoxes();
+
+protected:
+ virtual void onActorCreated(const ExtPxActor& actor);
+ virtual void onActorUpdate(const ExtPxActor& actor);
+ virtual void onActorDestroyed(const ExtPxActor& actor);
+
+private:
+ Renderer& m_renderer;
+ std::vector<Renderable*> m_chunkRenderables;
+};
+
+
#endif //BLAST_FAMILY_BOXES \ No newline at end of file
diff --git a/samples/SampleBase/blast/BlastFamilyModelSimple.cpp b/samples/SampleBase/blast/BlastFamilyModelSimple.cpp
index 167ff36..61feec8 100644..100755
--- a/samples/SampleBase/blast/BlastFamilyModelSimple.cpp
+++ b/samples/SampleBase/blast/BlastFamilyModelSimple.cpp
@@ -1,354 +1,354 @@
-// 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-2018 NVIDIA Corporation. All rights reserved.
-
-
-#include "BlastFamilyModelSimple.h"
-#include "RenderUtils.h"
-#include "DeviceManager.h"
-#include "Renderer.h"
-#include "NvBlastExtPxAsset.h"
-#include "NvBlastExtPxActor.h"
-#include "NvBlastTkActor.h"
-#include "NvBlastTkAsset.h"
-#include "PxRigidDynamic.h"
-
-using namespace physx;
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// SimpleRenderMesh
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-class SimpleRenderMesh : public IRenderMesh
-{
-public:
- SimpleRenderMesh(const SimpleMesh* mesh) : m_mesh(mesh)
- {
- m_device = GetDeviceManager()->GetDevice();
-
- m_inputDesc.push_back({ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 });
- m_inputDesc.push_back({ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 });
- m_inputDesc.push_back({ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 });
- m_inputDesc.push_back({ "TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 });
-
- m_numVertices = static_cast<uint32_t>(mesh->vertices.size());
- m_numFaces = static_cast<uint32_t>(mesh->indices.size());
-
- // VB
- {
- D3D11_SUBRESOURCE_DATA vertexBufferData;
- ZeroMemory(&vertexBufferData, sizeof(vertexBufferData));
- vertexBufferData.pSysMem = mesh->vertices.data();
-
- D3D11_BUFFER_DESC bufferDesc;
- memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC));
- bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
- bufferDesc.ByteWidth = sizeof(SimpleMesh::Vertex) * m_numVertices;
- bufferDesc.CPUAccessFlags = 0;
- bufferDesc.MiscFlags = 0;
- bufferDesc.Usage = D3D11_USAGE_IMMUTABLE;
-
- V(m_device->CreateBuffer(&bufferDesc, &vertexBufferData, &m_vertexBuffer));
- }
-
- // Health Buffer
- {
- // fill with 1.0f initially
- std::vector<float> healths(mesh->vertices.size());
- std::fill(healths.begin(), healths.end(), 1.0f);
-
- D3D11_SUBRESOURCE_DATA vertexBufferData;
- ZeroMemory(&vertexBufferData, sizeof(vertexBufferData));
- vertexBufferData.pSysMem = healths.data();
-
- D3D11_BUFFER_DESC bufferDesc;
- memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC));
- bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
- bufferDesc.ByteWidth = (uint32_t)(sizeof(float) * m_numVertices);
- bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
- bufferDesc.MiscFlags = 0;
- bufferDesc.Usage = D3D11_USAGE_DYNAMIC;
-
- V(m_device->CreateBuffer(&bufferDesc, &vertexBufferData, &m_healthBuffer));
- }
-
- // IB
- if (m_numFaces)
- {
- D3D11_SUBRESOURCE_DATA indexBufferData;
-
- ZeroMemory(&indexBufferData, sizeof(indexBufferData));
- indexBufferData.pSysMem = mesh->indices.data();
-
- D3D11_BUFFER_DESC bufferDesc;
-
- memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC));
- bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
- bufferDesc.ByteWidth = sizeof(uint32_t) * m_numFaces;
- bufferDesc.CPUAccessFlags = 0;
- bufferDesc.MiscFlags = 0;
- bufferDesc.Usage = D3D11_USAGE_IMMUTABLE;
-
- V(m_device->CreateBuffer(&bufferDesc, &indexBufferData, &m_indexBuffer));
- }
- }
-
- ~SimpleRenderMesh()
- {
- SAFE_RELEASE(m_healthBuffer);
- SAFE_RELEASE(m_vertexBuffer);
- SAFE_RELEASE(m_indexBuffer);
- }
-
-
- void render(ID3D11DeviceContext& context) const
- {
- context.IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
-
- UINT strides[2] = { sizeof(SimpleMesh::Vertex), sizeof(uint32_t) };
- UINT offsets[2] = { 0 };
- ID3D11Buffer* buffers[2] = { m_vertexBuffer, m_healthBuffer };
- context.IASetVertexBuffers(0, 2, buffers, strides, offsets);
-
-
- context.IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R32_UINT, 0);
-
- if (m_indexBuffer)
- context.DrawIndexed(m_numFaces, 0, 0);
- else
- context.Draw(m_numVertices, 0);
- }
-
- const std::vector<D3D11_INPUT_ELEMENT_DESC>& getInputElementDesc() const { return m_inputDesc; }
-
- const SimpleMesh* getMesh() { return m_mesh; }
-
- void updateHealths(const std::vector<float>& healths)
- {
- ID3D11DeviceContext* context;
- m_device->GetImmediateContext(&context);
-
- // update buffer
- {
- D3D11_MAPPED_SUBRESOURCE mappedRead;
- V(context->Map(m_healthBuffer, 0, D3D11_MAP_WRITE_DISCARD, NULL, &mappedRead));
- memcpy(mappedRead.pData, healths.data(), sizeof(float) * healths.size());
- context->Unmap(m_healthBuffer, 0);
- }
-
- }
-
-
-private:
-
- ID3D11Device* m_device;
-
- ID3D11Buffer* m_vertexBuffer;
- ID3D11Buffer* m_healthBuffer;
- ID3D11Buffer* m_indexBuffer;
- uint32_t m_numFaces;
- uint32_t m_numVertices;
-
- std::vector<D3D11_INPUT_ELEMENT_DESC> m_inputDesc;
-
- const SimpleMesh* m_mesh;
-};
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// BlastFamilyModelSimple
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-BlastFamilyModelSimple::BlastFamilyModelSimple(PhysXController& physXController, ExtPxManager& pxManager, Renderer& renderer, const BlastAssetModelSimple& blastAsset, const BlastAsset::ActorDesc& desc)
- : BlastFamily(physXController, pxManager, blastAsset), m_renderer(renderer)
-{
- // materials
- auto materials = blastAsset.getRenderMaterials();
-
- // model
- const BlastModel& model = blastAsset.getModel();
-
- // create render mesh for every BlastModel::Chunk::Mesh and renderable with it
- const std::vector<BlastModel::Chunk>& modelChunks = model.chunks;
- m_chunks.resize(modelChunks.size());
- for (uint32_t chunkIndex = 0; chunkIndex < modelChunks.size(); chunkIndex++)
- {
- const std::vector<BlastModel::Chunk::Mesh>& meshes = modelChunks[chunkIndex].meshes;
- std::vector<SimpleRenderMesh*>& renderMeshes = m_chunks[chunkIndex].renderMeshes;
- std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables;
- renderMeshes.resize(meshes.size());
- renderables.resize(meshes.size());
- for (uint32_t i = 0; i < meshes.size(); i++)
- {
- renderMeshes[i] = new SimpleRenderMesh(&meshes[i].mesh);
-
- uint32_t materialIndex = model.chunks[chunkIndex].meshes[i].materialIndex;
- Renderable* renderable = renderer.createRenderable(*renderMeshes[i], *materials[materialIndex]);
- renderable->setHidden(true);
- renderables[i] = renderable;
-
- }
- }
-
- // initialize in position
- initialize(desc);
-}
-
-BlastFamilyModelSimple::~BlastFamilyModelSimple()
-{
- // release all chunks
- for (uint32_t chunkIndex = 0; chunkIndex < m_chunks.size(); chunkIndex++)
- {
- std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables;
- for (uint32_t i = 0; i < m_chunks[chunkIndex].renderables.size(); i++)
- {
- m_renderer.removeRenderable(m_chunks[chunkIndex].renderables[i]);
- SAFE_DELETE(m_chunks[chunkIndex].renderMeshes[i]);
- }
- }
-}
-
-void BlastFamilyModelSimple::onActorCreated(const ExtPxActor& actor)
-{
- // separate color for every material
- std::vector<DirectX::XMFLOAT4> colors;
-
- const uint32_t* chunkIndices = actor.getChunkIndices();
- uint32_t chunkCount = actor.getChunkCount();
- for (uint32_t i = 0; i < chunkCount; i++)
- {
- uint32_t chunkIndex = chunkIndices[i];
- std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables;
- for (uint32_t r = 0; r < renderables.size(); r++)
- {
- if (colors.size() <= r)
- colors.push_back(getRandomPastelColor());
-
- renderables[r]->setHidden(false);
- renderables[r]->setColor(colors[r]);
- }
- }
-}
-
-void BlastFamilyModelSimple::onActorUpdate(const ExtPxActor& actor)
-{
- const ExtPxChunk* chunks = m_blastAsset.getPxAsset()->getChunks();
- const ExtPxSubchunk* subChunks = m_blastAsset.getPxAsset()->getSubchunks();
- const uint32_t* chunkIndices = actor.getChunkIndices();
- uint32_t chunkCount = actor.getChunkCount();
- for (uint32_t i = 0; i < chunkCount; i++)
- {
- uint32_t chunkIndex = chunkIndices[i];
- std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables;
- for (Renderable* r : renderables)
- {
- r->setTransform(actor.getPhysXActor().getGlobalPose() * subChunks[chunks[chunkIndex].firstSubchunkIndex].transform);
- }
- }
-}
-
-void BlastFamilyModelSimple::onActorDestroyed(const ExtPxActor& actor)
-{
- const uint32_t* chunkIndices = actor.getChunkIndices();
- uint32_t chunkCount = actor.getChunkCount();
- for (uint32_t i = 0; i < chunkCount; i++)
- {
- uint32_t chunkIndex = chunkIndices[i];
- std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables;
- for (Renderable* r : renderables)
- {
- r->setHidden(true);
- }
- }
-}
-
-void BlastFamilyModelSimple::onActorHealthUpdate(const ExtPxActor& actor)
-{
- TkActor& tkActor = actor.getTkActor();
- const TkAsset* tkAsset = tkActor.getAsset();
-
- const float* bondHealths = tkActor.getBondHealths();
- uint32_t nodeCount = tkActor.getGraphNodeCount();
- if (nodeCount == 0) // subsupport chunks don't have graph nodes
- return;
-
- std::vector<uint32_t> nodes(tkActor.getGraphNodeCount());
- tkActor.getGraphNodeIndices(nodes.data(), static_cast<uint32_t>(nodes.size()));
-
- const NvBlastChunk* chunks = tkAsset->getChunks();
- const NvBlastBond* bonds = tkAsset->getBonds();
-
- const NvBlastSupportGraph graph = tkAsset->getGraph();
- const float bondHealthMax = m_blastAsset.getBondHealthMax();
-
- std::vector<float> healthBuffer;
-
- for (uint32_t node0 : nodes)
- {
- uint32_t chunkIndex = graph.chunkIndices[node0];
-
- if (chunkIndex >= m_chunks.size())
- continue;
-
- std::vector<SimpleRenderMesh*>& meshes = m_chunks[chunkIndex].renderMeshes;
- const auto& renderables = m_chunks[chunkIndex].renderables;
- for (uint32_t i = 0; i < meshes.size(); ++i)
- {
- if(renderables[i]->isHidden())
- continue;
-
- SimpleRenderMesh* renderMesh = meshes[i];
-
- const SimpleMesh* mesh = renderMesh->getMesh();
- healthBuffer.resize(mesh->vertices.size());
-
- for (uint32_t vertexIndex = 0; vertexIndex < mesh->vertices.size(); vertexIndex++)
- {
- PxVec3 position = mesh->vertices[vertexIndex].position;
- float health = 0.0f;
- float healthDenom = 0.0f;
-
- for (uint32_t adjacencyIndex = graph.adjacencyPartition[node0]; adjacencyIndex < graph.adjacencyPartition[node0 + 1]; adjacencyIndex++)
- {
- uint32_t node1 = graph.adjacentNodeIndices[adjacencyIndex];
- uint32_t bondIndex = graph.adjacentBondIndices[adjacencyIndex];
- float bondHealth = PxClamp(bondHealths[bondIndex] / bondHealthMax, 0.0f, 1.0f);
- const NvBlastBond& solverBond = bonds[bondIndex];
- const PxVec3& centroid = reinterpret_cast<const PxVec3&>(solverBond.centroid);
-
- float factor = 1.0f / (centroid - position).magnitudeSquared();
-
- health += bondHealth * factor;
- healthDenom += factor;
- }
-
- healthBuffer[vertexIndex] = healthDenom > 0.0f ? health / healthDenom : 1.0f;
- }
-
- renderMesh->updateHealths(healthBuffer);
- }
- }
-}
+// 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-2018 NVIDIA Corporation. All rights reserved.
+
+
+#include "BlastFamilyModelSimple.h"
+#include "RenderUtils.h"
+#include "DeviceManager.h"
+#include "Renderer.h"
+#include "NvBlastExtPxAsset.h"
+#include "NvBlastExtPxActor.h"
+#include "NvBlastTkActor.h"
+#include "NvBlastTkAsset.h"
+#include "PxRigidDynamic.h"
+
+using namespace physx;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// SimpleRenderMesh
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+class SimpleRenderMesh : public IRenderMesh
+{
+public:
+ SimpleRenderMesh(const SimpleMesh* mesh) : m_mesh(mesh)
+ {
+ m_device = GetDeviceManager()->GetDevice();
+
+ m_inputDesc.push_back({ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 });
+ m_inputDesc.push_back({ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 });
+ m_inputDesc.push_back({ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 });
+ m_inputDesc.push_back({ "TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 });
+
+ m_numVertices = static_cast<uint32_t>(mesh->vertices.size());
+ m_numFaces = static_cast<uint32_t>(mesh->indices.size());
+
+ // VB
+ {
+ D3D11_SUBRESOURCE_DATA vertexBufferData;
+ ZeroMemory(&vertexBufferData, sizeof(vertexBufferData));
+ vertexBufferData.pSysMem = mesh->vertices.data();
+
+ D3D11_BUFFER_DESC bufferDesc;
+ memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC));
+ bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
+ bufferDesc.ByteWidth = sizeof(SimpleMesh::Vertex) * m_numVertices;
+ bufferDesc.CPUAccessFlags = 0;
+ bufferDesc.MiscFlags = 0;
+ bufferDesc.Usage = D3D11_USAGE_IMMUTABLE;
+
+ V(m_device->CreateBuffer(&bufferDesc, &vertexBufferData, &m_vertexBuffer));
+ }
+
+ // Health Buffer
+ {
+ // fill with 1.0f initially
+ std::vector<float> healths(mesh->vertices.size());
+ std::fill(healths.begin(), healths.end(), 1.0f);
+
+ D3D11_SUBRESOURCE_DATA vertexBufferData;
+ ZeroMemory(&vertexBufferData, sizeof(vertexBufferData));
+ vertexBufferData.pSysMem = healths.data();
+
+ D3D11_BUFFER_DESC bufferDesc;
+ memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC));
+ bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
+ bufferDesc.ByteWidth = (uint32_t)(sizeof(float) * m_numVertices);
+ bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
+ bufferDesc.MiscFlags = 0;
+ bufferDesc.Usage = D3D11_USAGE_DYNAMIC;
+
+ V(m_device->CreateBuffer(&bufferDesc, &vertexBufferData, &m_healthBuffer));
+ }
+
+ // IB
+ if (m_numFaces)
+ {
+ D3D11_SUBRESOURCE_DATA indexBufferData;
+
+ ZeroMemory(&indexBufferData, sizeof(indexBufferData));
+ indexBufferData.pSysMem = mesh->indices.data();
+
+ D3D11_BUFFER_DESC bufferDesc;
+
+ memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC));
+ bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
+ bufferDesc.ByteWidth = sizeof(uint32_t) * m_numFaces;
+ bufferDesc.CPUAccessFlags = 0;
+ bufferDesc.MiscFlags = 0;
+ bufferDesc.Usage = D3D11_USAGE_IMMUTABLE;
+
+ V(m_device->CreateBuffer(&bufferDesc, &indexBufferData, &m_indexBuffer));
+ }
+ }
+
+ ~SimpleRenderMesh()
+ {
+ SAFE_RELEASE(m_healthBuffer);
+ SAFE_RELEASE(m_vertexBuffer);
+ SAFE_RELEASE(m_indexBuffer);
+ }
+
+
+ void render(ID3D11DeviceContext& context) const
+ {
+ context.IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
+
+ UINT strides[2] = { sizeof(SimpleMesh::Vertex), sizeof(uint32_t) };
+ UINT offsets[2] = { 0 };
+ ID3D11Buffer* buffers[2] = { m_vertexBuffer, m_healthBuffer };
+ context.IASetVertexBuffers(0, 2, buffers, strides, offsets);
+
+
+ context.IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R32_UINT, 0);
+
+ if (m_indexBuffer)
+ context.DrawIndexed(m_numFaces, 0, 0);
+ else
+ context.Draw(m_numVertices, 0);
+ }
+
+ const std::vector<D3D11_INPUT_ELEMENT_DESC>& getInputElementDesc() const { return m_inputDesc; }
+
+ const SimpleMesh* getMesh() { return m_mesh; }
+
+ void updateHealths(const std::vector<float>& healths)
+ {
+ ID3D11DeviceContext* context;
+ m_device->GetImmediateContext(&context);
+
+ // update buffer
+ {
+ D3D11_MAPPED_SUBRESOURCE mappedRead;
+ V(context->Map(m_healthBuffer, 0, D3D11_MAP_WRITE_DISCARD, NULL, &mappedRead));
+ memcpy(mappedRead.pData, healths.data(), sizeof(float) * healths.size());
+ context->Unmap(m_healthBuffer, 0);
+ }
+
+ }
+
+
+private:
+
+ ID3D11Device* m_device;
+
+ ID3D11Buffer* m_vertexBuffer;
+ ID3D11Buffer* m_healthBuffer;
+ ID3D11Buffer* m_indexBuffer;
+ uint32_t m_numFaces;
+ uint32_t m_numVertices;
+
+ std::vector<D3D11_INPUT_ELEMENT_DESC> m_inputDesc;
+
+ const SimpleMesh* m_mesh;
+};
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// BlastFamilyModelSimple
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+BlastFamilyModelSimple::BlastFamilyModelSimple(PhysXController& physXController, ExtPxManager& pxManager, Renderer& renderer, const BlastAssetModelSimple& blastAsset, const BlastAsset::ActorDesc& desc)
+ : BlastFamily(physXController, pxManager, blastAsset), m_renderer(renderer)
+{
+ // materials
+ auto materials = blastAsset.getRenderMaterials();
+
+ // model
+ const BlastModel& model = blastAsset.getModel();
+
+ // create render mesh for every BlastModel::Chunk::Mesh and renderable with it
+ const std::vector<BlastModel::Chunk>& modelChunks = model.chunks;
+ m_chunks.resize(modelChunks.size());
+ for (uint32_t chunkIndex = 0; chunkIndex < modelChunks.size(); chunkIndex++)
+ {
+ const std::vector<BlastModel::Chunk::Mesh>& meshes = modelChunks[chunkIndex].meshes;
+ std::vector<SimpleRenderMesh*>& renderMeshes = m_chunks[chunkIndex].renderMeshes;
+ std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables;
+ renderMeshes.resize(meshes.size());
+ renderables.resize(meshes.size());
+ for (uint32_t i = 0; i < meshes.size(); i++)
+ {
+ renderMeshes[i] = new SimpleRenderMesh(&meshes[i].mesh);
+
+ uint32_t materialIndex = model.chunks[chunkIndex].meshes[i].materialIndex;
+ Renderable* renderable = renderer.createRenderable(*renderMeshes[i], *materials[materialIndex]);
+ renderable->setHidden(true);
+ renderables[i] = renderable;
+
+ }
+ }
+
+ // initialize in position
+ initialize(desc);
+}
+
+BlastFamilyModelSimple::~BlastFamilyModelSimple()
+{
+ // release all chunks
+ for (uint32_t chunkIndex = 0; chunkIndex < m_chunks.size(); chunkIndex++)
+ {
+ std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables;
+ for (uint32_t i = 0; i < m_chunks[chunkIndex].renderables.size(); i++)
+ {
+ m_renderer.removeRenderable(m_chunks[chunkIndex].renderables[i]);
+ SAFE_DELETE(m_chunks[chunkIndex].renderMeshes[i]);
+ }
+ }
+}
+
+void BlastFamilyModelSimple::onActorCreated(const ExtPxActor& actor)
+{
+ // separate color for every material
+ std::vector<DirectX::XMFLOAT4> colors;
+
+ const uint32_t* chunkIndices = actor.getChunkIndices();
+ uint32_t chunkCount = actor.getChunkCount();
+ for (uint32_t i = 0; i < chunkCount; i++)
+ {
+ uint32_t chunkIndex = chunkIndices[i];
+ std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables;
+ for (uint32_t r = 0; r < renderables.size(); r++)
+ {
+ if (colors.size() <= r)
+ colors.push_back(getRandomPastelColor());
+
+ renderables[r]->setHidden(false);
+ renderables[r]->setColor(colors[r]);
+ }
+ }
+}
+
+void BlastFamilyModelSimple::onActorUpdate(const ExtPxActor& actor)
+{
+ const ExtPxChunk* chunks = m_blastAsset.getPxAsset()->getChunks();
+ const ExtPxSubchunk* subChunks = m_blastAsset.getPxAsset()->getSubchunks();
+ const uint32_t* chunkIndices = actor.getChunkIndices();
+ uint32_t chunkCount = actor.getChunkCount();
+ for (uint32_t i = 0; i < chunkCount; i++)
+ {
+ uint32_t chunkIndex = chunkIndices[i];
+ std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables;
+ for (Renderable* r : renderables)
+ {
+ r->setTransform(actor.getPhysXActor().getGlobalPose() * subChunks[chunks[chunkIndex].firstSubchunkIndex].transform);
+ }
+ }
+}
+
+void BlastFamilyModelSimple::onActorDestroyed(const ExtPxActor& actor)
+{
+ const uint32_t* chunkIndices = actor.getChunkIndices();
+ uint32_t chunkCount = actor.getChunkCount();
+ for (uint32_t i = 0; i < chunkCount; i++)
+ {
+ uint32_t chunkIndex = chunkIndices[i];
+ std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables;
+ for (Renderable* r : renderables)
+ {
+ r->setHidden(true);
+ }
+ }
+}
+
+void BlastFamilyModelSimple::onActorHealthUpdate(const ExtPxActor& actor)
+{
+ TkActor& tkActor = actor.getTkActor();
+ const TkAsset* tkAsset = tkActor.getAsset();
+
+ const float* bondHealths = tkActor.getBondHealths();
+ uint32_t nodeCount = tkActor.getGraphNodeCount();
+ if (nodeCount == 0) // subsupport chunks don't have graph nodes
+ return;
+
+ std::vector<uint32_t> nodes(tkActor.getGraphNodeCount());
+ tkActor.getGraphNodeIndices(nodes.data(), static_cast<uint32_t>(nodes.size()));
+
+ const NvBlastChunk* chunks = tkAsset->getChunks();
+ const NvBlastBond* bonds = tkAsset->getBonds();
+
+ const NvBlastSupportGraph graph = tkAsset->getGraph();
+ const float bondHealthMax = m_blastAsset.getBondHealthMax();
+
+ std::vector<float> healthBuffer;
+
+ for (uint32_t node0 : nodes)
+ {
+ uint32_t chunkIndex = graph.chunkIndices[node0];
+
+ if (chunkIndex >= m_chunks.size())
+ continue;
+
+ std::vector<SimpleRenderMesh*>& meshes = m_chunks[chunkIndex].renderMeshes;
+ const auto& renderables = m_chunks[chunkIndex].renderables;
+ for (uint32_t i = 0; i < meshes.size(); ++i)
+ {
+ if(renderables[i]->isHidden())
+ continue;
+
+ SimpleRenderMesh* renderMesh = meshes[i];
+
+ const SimpleMesh* mesh = renderMesh->getMesh();
+ healthBuffer.resize(mesh->vertices.size());
+
+ for (uint32_t vertexIndex = 0; vertexIndex < mesh->vertices.size(); vertexIndex++)
+ {
+ PxVec3 position = mesh->vertices[vertexIndex].position;
+ float health = 0.0f;
+ float healthDenom = 0.0f;
+
+ for (uint32_t adjacencyIndex = graph.adjacencyPartition[node0]; adjacencyIndex < graph.adjacencyPartition[node0 + 1]; adjacencyIndex++)
+ {
+ uint32_t node1 = graph.adjacentNodeIndices[adjacencyIndex];
+ uint32_t bondIndex = graph.adjacentBondIndices[adjacencyIndex];
+ float bondHealth = PxClamp(bondHealths[bondIndex] / bondHealthMax, 0.0f, 1.0f);
+ const NvBlastBond& solverBond = bonds[bondIndex];
+ const PxVec3& centroid = reinterpret_cast<const PxVec3&>(solverBond.centroid);
+
+ float factor = 1.0f / (centroid - position).magnitudeSquared();
+
+ health += bondHealth * factor;
+ healthDenom += factor;
+ }
+
+ healthBuffer[vertexIndex] = healthDenom > 0.0f ? health / healthDenom : 1.0f;
+ }
+
+ renderMesh->updateHealths(healthBuffer);
+ }
+ }
+}
diff --git a/samples/SampleBase/blast/BlastFamilyModelSimple.h b/samples/SampleBase/blast/BlastFamilyModelSimple.h
index 310b264..af2f154 100644..100755
--- a/samples/SampleBase/blast/BlastFamilyModelSimple.h
+++ b/samples/SampleBase/blast/BlastFamilyModelSimple.h
@@ -1,70 +1,70 @@
-// 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-2018 NVIDIA Corporation. All rights reserved.
-
-
-#ifndef BLAST_FAMILY_MODEL_SIMPLE_H
-#define BLAST_FAMILY_MODEL_SIMPLE_H
-
-#include "BlastFamily.h"
-#include "BlastAssetModelSimple.h"
-
-class SimpleRenderMesh;
-class Renderable;
-class Renderer;
-
-class BlastFamilyModelSimple : public BlastFamily
-{
-public:
- //////// ctor ////////
-
- BlastFamilyModelSimple(PhysXController& physXController, ExtPxManager& pxManager, Renderer& renderer, const BlastAssetModelSimple& blastAsset, const BlastAsset::ActorDesc& desc);
- virtual ~BlastFamilyModelSimple();
-
-protected:
- //////// abstract implementation ////////
-
- virtual void onActorCreated(const ExtPxActor& actor);
- virtual void onActorUpdate(const ExtPxActor& actor);
- virtual void onActorDestroyed(const ExtPxActor& actor);
- virtual void onActorHealthUpdate(const ExtPxActor& pxActor);
-
-private:
- //////// internal data ////////
-
- Renderer& m_renderer;
-
- struct Chunk
- {
- std::vector<SimpleRenderMesh*> renderMeshes;
- std::vector<Renderable*> renderables;
- };
-
- std::vector<Chunk> m_chunks;
-};
-
-
+// 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-2018 NVIDIA Corporation. All rights reserved.
+
+
+#ifndef BLAST_FAMILY_MODEL_SIMPLE_H
+#define BLAST_FAMILY_MODEL_SIMPLE_H
+
+#include "BlastFamily.h"
+#include "BlastAssetModelSimple.h"
+
+class SimpleRenderMesh;
+class Renderable;
+class Renderer;
+
+class BlastFamilyModelSimple : public BlastFamily
+{
+public:
+ //////// ctor ////////
+
+ BlastFamilyModelSimple(PhysXController& physXController, ExtPxManager& pxManager, Renderer& renderer, const BlastAssetModelSimple& blastAsset, const BlastAsset::ActorDesc& desc);
+ virtual ~BlastFamilyModelSimple();
+
+protected:
+ //////// abstract implementation ////////
+
+ virtual void onActorCreated(const ExtPxActor& actor);
+ virtual void onActorUpdate(const ExtPxActor& actor);
+ virtual void onActorDestroyed(const ExtPxActor& actor);
+ virtual void onActorHealthUpdate(const ExtPxActor& pxActor);
+
+private:
+ //////// internal data ////////
+
+ Renderer& m_renderer;
+
+ struct Chunk
+ {
+ std::vector<SimpleRenderMesh*> renderMeshes;
+ std::vector<Renderable*> renderables;
+ };
+
+ std::vector<Chunk> m_chunks;
+};
+
+
#endif //BLAST_FAMILY_MODEL_SIMPLE_H \ No newline at end of file
diff --git a/samples/SampleBase/blast/BlastFamilyModelSkinned.cpp b/samples/SampleBase/blast/BlastFamilyModelSkinned.cpp
index 8783097..668c32e 100644..100755
--- a/samples/SampleBase/blast/BlastFamilyModelSkinned.cpp
+++ b/samples/SampleBase/blast/BlastFamilyModelSkinned.cpp
@@ -1,185 +1,185 @@
-// 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-2018 NVIDIA Corporation. All rights reserved.
-
-
-#include "BlastFamilyModelSkinned.h"
-#include "RenderUtils.h"
-#include "Renderer.h"
-#include "SkinnedRenderMesh.h"
-#include "NvBlastExtPxAsset.h"
-#include "NvBlastExtPxActor.h"
-#include "NvBlastTkActor.h"
-#include "PxRigidDynamic.h"
-
-using namespace physx;
-
-BlastFamilyModelSkinned::BlastFamilyModelSkinned(PhysXController& physXController, ExtPxManager& pxManager, Renderer& renderer, const BlastAssetModelSkinned& blastAsset, const BlastAsset::ActorDesc& desc)
- : BlastFamily(physXController, pxManager, blastAsset), m_renderer(renderer), m_visibleActorsDirty(true)
-{
- // materials
- auto materials = blastAsset.getRenderMaterials();
-
- const BlastModel& model = blastAsset.getModel();
-
- // finalize (create) sub model
- auto finalizeSubModelFunction = [&](SubModel* subModel, std::vector<const SimpleMesh*>& subModelMeshes, RenderMaterial& renderMaterial)
- {
- subModel->skinnedRenderMesh = new SkinnedRenderMesh(subModelMeshes);
- subModel->renderable = renderer.createRenderable(*subModel->skinnedRenderMesh, renderMaterial);
- subModel->renderable->setColor(getRandomPastelColor());
- };
-
- // create at least one submodel per every material (if mesh count is too high, more then one sub model per material to be created)
- SubModel* subModel = nullptr;
- std::vector<const SimpleMesh*> subModelMeshes;
- subModelMeshes.reserve(model.chunks.size());
- for (uint32_t materialIndex = 0; materialIndex < model.materials.size(); materialIndex++)
- {
- for (uint32_t chunkIndex = 0; chunkIndex < model.chunks.size(); chunkIndex++)
- {
- const BlastModel::Chunk& chunk = model.chunks[chunkIndex];
- for (const BlastModel::Chunk::Mesh& mesh : chunk.meshes)
- {
- if (mesh.materialIndex == materialIndex)
- {
- // init new submodel?
- if (subModel == nullptr)
- {
- m_subModels.push_back(SubModel());
- subModel = &m_subModels.back();
- subModel->chunkIdToBoneMap.resize(model.chunks.size());
- std::fill(subModel->chunkIdToBoneMap.begin(), subModel->chunkIdToBoneMap.end(), SubModel::INVALID_BONE_ID);
- subModelMeshes.clear();
- }
-
- // add mesh to map and list
- subModel->chunkIdToBoneMap[chunkIndex] = (uint32_t)subModelMeshes.size();
- subModelMeshes.push_back(&(mesh.mesh));
-
- // mesh reached limit?
- if (subModelMeshes.size() == SkinnedRenderMesh::MeshesCountMax)
- {
- finalizeSubModelFunction(subModel, subModelMeshes, *materials[materialIndex]);
- subModel = nullptr;
- }
- }
- }
- }
-
- // finalize subModel for this material
- if (subModel && subModelMeshes.size() > 0)
- {
- finalizeSubModelFunction(subModel, subModelMeshes, *materials[materialIndex]);
- subModel = nullptr;
- }
- }
-
- // reserve for scratch
- m_visibleBones.reserve(model.chunks.size());
- m_visibleBoneTransforms.reserve(model.chunks.size());
-
- // initialize in position
- initialize(desc);
-}
-
-BlastFamilyModelSkinned::~BlastFamilyModelSkinned()
-{
- for (uint32_t subModelIndex = 0; subModelIndex < m_subModels.size(); subModelIndex++)
- {
- m_renderer.removeRenderable(m_subModels[subModelIndex].renderable);
- SAFE_DELETE(m_subModels[subModelIndex].skinnedRenderMesh);
- }
-}
-
-void BlastFamilyModelSkinned::onActorCreated(const ExtPxActor& actor)
-{
- m_visibleActors.insert(&actor);
- m_visibleActorsDirty = true;
-}
-
-void BlastFamilyModelSkinned::onActorUpdate(const ExtPxActor& actor)
-{
-}
-
-void BlastFamilyModelSkinned::onActorDestroyed(const ExtPxActor& actor)
-{
- m_visibleActors.erase(&actor);
- m_visibleActorsDirty = true;
-}
-
-void BlastFamilyModelSkinned::onUpdate()
-{
- // visible actors changed this frame?
- if (m_visibleActorsDirty)
- {
- for (const SubModel& model : m_subModels)
- {
- // pass visible chunks list to render mesh
- m_visibleBones.clear();
- for (const ExtPxActor* actor : m_visibleActors)
- {
- const uint32_t* chunkIndices = actor->getChunkIndices();
- uint32_t chunkCount = actor->getChunkCount();
- for (uint32_t i = 0; i < chunkCount; ++i)
- {
- uint32_t chunkIndex = chunkIndices[i];
- uint32_t boneIndex = model.chunkIdToBoneMap[chunkIndex];
- if (boneIndex != SubModel::INVALID_BONE_ID)
- {
- m_visibleBones.push_back(boneIndex);
- }
- }
- }
- model.skinnedRenderMesh->updateVisibleMeshes(m_visibleBones);
- }
-
- m_visibleActorsDirty = false;
- }
-
- // update and pass chunk transforms
- const ExtPxChunk* chunks = m_blastAsset.getPxAsset()->getChunks();
- const ExtPxSubchunk* subChunks = m_blastAsset.getPxAsset()->getSubchunks();
- for (const SubModel& model : m_subModels)
- {
- m_visibleBoneTransforms.clear();
- for (const ExtPxActor* actor : m_visibleActors)
- {
- const uint32_t* chunkIndices = actor->getChunkIndices();
- uint32_t chunkCount = actor->getChunkCount();
- for (uint32_t i = 0; i < chunkCount; ++i)
- {
- uint32_t chunkIndex = chunkIndices[i];
- uint32_t boneIndex = model.chunkIdToBoneMap[chunkIndex];
- if (boneIndex != SubModel::INVALID_BONE_ID)
- {
- m_visibleBoneTransforms.push_back(PxMat44(actor->getPhysXActor().getGlobalPose() * subChunks[chunks[chunkIndex].firstSubchunkIndex].transform));
- }
- }
- }
- model.skinnedRenderMesh->updateVisibleMeshTransforms(m_visibleBoneTransforms);
- }
-}
+// 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-2018 NVIDIA Corporation. All rights reserved.
+
+
+#include "BlastFamilyModelSkinned.h"
+#include "RenderUtils.h"
+#include "Renderer.h"
+#include "SkinnedRenderMesh.h"
+#include "NvBlastExtPxAsset.h"
+#include "NvBlastExtPxActor.h"
+#include "NvBlastTkActor.h"
+#include "PxRigidDynamic.h"
+
+using namespace physx;
+
+BlastFamilyModelSkinned::BlastFamilyModelSkinned(PhysXController& physXController, ExtPxManager& pxManager, Renderer& renderer, const BlastAssetModelSkinned& blastAsset, const BlastAsset::ActorDesc& desc)
+ : BlastFamily(physXController, pxManager, blastAsset), m_renderer(renderer), m_visibleActorsDirty(true)
+{
+ // materials
+ auto materials = blastAsset.getRenderMaterials();
+
+ const BlastModel& model = blastAsset.getModel();
+
+ // finalize (create) sub model
+ auto finalizeSubModelFunction = [&](SubModel* subModel, std::vector<const SimpleMesh*>& subModelMeshes, RenderMaterial& renderMaterial)
+ {
+ subModel->skinnedRenderMesh = new SkinnedRenderMesh(subModelMeshes);
+ subModel->renderable = renderer.createRenderable(*subModel->skinnedRenderMesh, renderMaterial);
+ subModel->renderable->setColor(getRandomPastelColor());
+ };
+
+ // create at least one submodel per every material (if mesh count is too high, more then one sub model per material to be created)
+ SubModel* subModel = nullptr;
+ std::vector<const SimpleMesh*> subModelMeshes;
+ subModelMeshes.reserve(model.chunks.size());
+ for (uint32_t materialIndex = 0; materialIndex < model.materials.size(); materialIndex++)
+ {
+ for (uint32_t chunkIndex = 0; chunkIndex < model.chunks.size(); chunkIndex++)
+ {
+ const BlastModel::Chunk& chunk = model.chunks[chunkIndex];
+ for (const BlastModel::Chunk::Mesh& mesh : chunk.meshes)
+ {
+ if (mesh.materialIndex == materialIndex)
+ {
+ // init new submodel?
+ if (subModel == nullptr)
+ {
+ m_subModels.push_back(SubModel());
+ subModel = &m_subModels.back();
+ subModel->chunkIdToBoneMap.resize(model.chunks.size());
+ std::fill(subModel->chunkIdToBoneMap.begin(), subModel->chunkIdToBoneMap.end(), SubModel::INVALID_BONE_ID);
+ subModelMeshes.clear();
+ }
+
+ // add mesh to map and list
+ subModel->chunkIdToBoneMap[chunkIndex] = (uint32_t)subModelMeshes.size();
+ subModelMeshes.push_back(&(mesh.mesh));
+
+ // mesh reached limit?
+ if (subModelMeshes.size() == SkinnedRenderMesh::MeshesCountMax)
+ {
+ finalizeSubModelFunction(subModel, subModelMeshes, *materials[materialIndex]);
+ subModel = nullptr;
+ }
+ }
+ }
+ }
+
+ // finalize subModel for this material
+ if (subModel && subModelMeshes.size() > 0)
+ {
+ finalizeSubModelFunction(subModel, subModelMeshes, *materials[materialIndex]);
+ subModel = nullptr;
+ }
+ }
+
+ // reserve for scratch
+ m_visibleBones.reserve(model.chunks.size());
+ m_visibleBoneTransforms.reserve(model.chunks.size());
+
+ // initialize in position
+ initialize(desc);
+}
+
+BlastFamilyModelSkinned::~BlastFamilyModelSkinned()
+{
+ for (uint32_t subModelIndex = 0; subModelIndex < m_subModels.size(); subModelIndex++)
+ {
+ m_renderer.removeRenderable(m_subModels[subModelIndex].renderable);
+ SAFE_DELETE(m_subModels[subModelIndex].skinnedRenderMesh);
+ }
+}
+
+void BlastFamilyModelSkinned::onActorCreated(const ExtPxActor& actor)
+{
+ m_visibleActors.insert(&actor);
+ m_visibleActorsDirty = true;
+}
+
+void BlastFamilyModelSkinned::onActorUpdate(const ExtPxActor& actor)
+{
+}
+
+void BlastFamilyModelSkinned::onActorDestroyed(const ExtPxActor& actor)
+{
+ m_visibleActors.erase(&actor);
+ m_visibleActorsDirty = true;
+}
+
+void BlastFamilyModelSkinned::onUpdate()
+{
+ // visible actors changed this frame?
+ if (m_visibleActorsDirty)
+ {
+ for (const SubModel& model : m_subModels)
+ {
+ // pass visible chunks list to render mesh
+ m_visibleBones.clear();
+ for (const ExtPxActor* actor : m_visibleActors)
+ {
+ const uint32_t* chunkIndices = actor->getChunkIndices();
+ uint32_t chunkCount = actor->getChunkCount();
+ for (uint32_t i = 0; i < chunkCount; ++i)
+ {
+ uint32_t chunkIndex = chunkIndices[i];
+ uint32_t boneIndex = model.chunkIdToBoneMap[chunkIndex];
+ if (boneIndex != SubModel::INVALID_BONE_ID)
+ {
+ m_visibleBones.push_back(boneIndex);
+ }
+ }
+ }
+ model.skinnedRenderMesh->updateVisibleMeshes(m_visibleBones);
+ }
+
+ m_visibleActorsDirty = false;
+ }
+
+ // update and pass chunk transforms
+ const ExtPxChunk* chunks = m_blastAsset.getPxAsset()->getChunks();
+ const ExtPxSubchunk* subChunks = m_blastAsset.getPxAsset()->getSubchunks();
+ for (const SubModel& model : m_subModels)
+ {
+ m_visibleBoneTransforms.clear();
+ for (const ExtPxActor* actor : m_visibleActors)
+ {
+ const uint32_t* chunkIndices = actor->getChunkIndices();
+ uint32_t chunkCount = actor->getChunkCount();
+ for (uint32_t i = 0; i < chunkCount; ++i)
+ {
+ uint32_t chunkIndex = chunkIndices[i];
+ uint32_t boneIndex = model.chunkIdToBoneMap[chunkIndex];
+ if (boneIndex != SubModel::INVALID_BONE_ID)
+ {
+ m_visibleBoneTransforms.push_back(PxMat44(actor->getPhysXActor().getGlobalPose() * subChunks[chunks[chunkIndex].firstSubchunkIndex].transform));
+ }
+ }
+ }
+ model.skinnedRenderMesh->updateVisibleMeshTransforms(m_visibleBoneTransforms);
+ }
+}
diff --git a/samples/SampleBase/blast/BlastFamilyModelSkinned.h b/samples/SampleBase/blast/BlastFamilyModelSkinned.h
index a606f68..397e041 100644..100755
--- a/samples/SampleBase/blast/BlastFamilyModelSkinned.h
+++ b/samples/SampleBase/blast/BlastFamilyModelSkinned.h
@@ -1,81 +1,81 @@
-// 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-2018 NVIDIA Corporation. All rights reserved.
-
-
-#ifndef BLAST_FAMILY_MODEL_SKINNED_H
-#define BLAST_FAMILY_MODEL_SKINNED_H
-
-#include "BlastFamily.h"
-#include "BlastAssetModelSkinned.h"
-
-class SkinnedRenderMesh;
-class Renderable;
-
-class BlastFamilyModelSkinned : public BlastFamily
-{
-public:
- //////// ctor ////////
-
- BlastFamilyModelSkinned(PhysXController& physXController, ExtPxManager& pxManager, Renderer& renderer, const BlastAssetModelSkinned& blastAsset, const BlastAsset::ActorDesc& desc);
- virtual ~BlastFamilyModelSkinned();
-
-protected:
- //////// abstract implementation ////////
-
- virtual void onActorCreated(const ExtPxActor& actor);
- virtual void onActorUpdate(const ExtPxActor& actor);
- virtual void onActorDestroyed(const ExtPxActor& actor);
-
- virtual void onUpdate();
-
-private:
- //////// internal data ////////
-
- Renderer& m_renderer;
-
- struct SubModel
- {
- static const uint32_t INVALID_BONE_ID = ~(uint32_t)0;
-
- Renderable* renderable = nullptr;
- SkinnedRenderMesh* skinnedRenderMesh = nullptr;
- std::vector<uint32_t> chunkIdToBoneMap;
- };
- std::vector<SubModel> m_subModels;
-
- std::set<const ExtPxActor*> m_visibleActors;
- bool m_visibleActorsDirty;
-
- //////// scratch buffers ////////
-
- std::vector<uint32_t> m_visibleBones;
- std::vector<PxMat44> m_visibleBoneTransforms;
-
-};
-
-
+// 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-2018 NVIDIA Corporation. All rights reserved.
+
+
+#ifndef BLAST_FAMILY_MODEL_SKINNED_H
+#define BLAST_FAMILY_MODEL_SKINNED_H
+
+#include "BlastFamily.h"
+#include "BlastAssetModelSkinned.h"
+
+class SkinnedRenderMesh;
+class Renderable;
+
+class BlastFamilyModelSkinned : public BlastFamily
+{
+public:
+ //////// ctor ////////
+
+ BlastFamilyModelSkinned(PhysXController& physXController, ExtPxManager& pxManager, Renderer& renderer, const BlastAssetModelSkinned& blastAsset, const BlastAsset::ActorDesc& desc);
+ virtual ~BlastFamilyModelSkinned();
+
+protected:
+ //////// abstract implementation ////////
+
+ virtual void onActorCreated(const ExtPxActor& actor);
+ virtual void onActorUpdate(const ExtPxActor& actor);
+ virtual void onActorDestroyed(const ExtPxActor& actor);
+
+ virtual void onUpdate();
+
+private:
+ //////// internal data ////////
+
+ Renderer& m_renderer;
+
+ struct SubModel
+ {
+ static const uint32_t INVALID_BONE_ID = ~(uint32_t)0;
+
+ Renderable* renderable = nullptr;
+ SkinnedRenderMesh* skinnedRenderMesh = nullptr;
+ std::vector<uint32_t> chunkIdToBoneMap;
+ };
+ std::vector<SubModel> m_subModels;
+
+ std::set<const ExtPxActor*> m_visibleActors;
+ bool m_visibleActorsDirty;
+
+ //////// scratch buffers ////////
+
+ std::vector<uint32_t> m_visibleBones;
+ std::vector<PxMat44> m_visibleBoneTransforms;
+
+};
+
+
#endif //BLAST_FAMILY_MODEL_SKINNED_H \ No newline at end of file
diff --git a/samples/SampleBase/blast/BlastModel.cpp b/samples/SampleBase/blast/BlastModel.cpp
index 9871d29..e23749c 100644..100755
--- a/samples/SampleBase/blast/BlastModel.cpp
+++ b/samples/SampleBase/blast/BlastModel.cpp
@@ -1,252 +1,252 @@
-// 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-2018 NVIDIA Corporation. All rights reserved.
-
-
-#include "BlastModel.h"
-
-#define TINYOBJLOADER_IMPLEMENTATION
-#include "tiny_obj_loader.h"
-#include "NvBlastExtExporter.h"
-#include "NvBlastGlobals.h"
-
-using namespace physx;
-
-BlastModelPtr BlastModel::loadFromFbxFile(const char* path)
-{
- std::shared_ptr<BlastModel> model = std::shared_ptr<BlastModel>(new BlastModel());
-
-
- std::shared_ptr<Nv::Blast::IFbxFileReader> rdr(NvBlastExtExporterCreateFbxFileReader(), [](Nv::Blast::IFbxFileReader* p) {p->release(); });
- rdr->loadFromFile(path);
- if (rdr->getBoneCount() == 0)
- {
- return nullptr;
- }
-
- model->chunks.resize(rdr->getBoneCount());
-
- model->materials.push_back(BlastModel::Material());
-
-
- /**
- Produce buffers of appropriate for AssetViewer format
- */
- uint32_t* infl;
- rdr->getBoneInfluences(infl);
-
- std::vector<int32_t> indRemap(rdr->getVerticesCount(), -1);
- for (uint32_t i = 0; i < rdr->getBoneCount(); ++i)
- {
- std::fill(indRemap.begin(), indRemap.end(), -1);
- SimpleMesh cmesh;
- const uint32_t vertexCount = rdr->getVerticesCount();
- const auto normalsArray = rdr->getNormalsArray();
- const auto positionArray = rdr->getPositionArray();
- const auto uvArray = rdr->getUvArray();
-
- for (uint32_t j = 0; j < vertexCount; ++j)
- {
- if (i == infl[j])
- {
- indRemap[j] = (int32_t)cmesh.vertices.size();
- cmesh.vertices.push_back(SimpleMesh::Vertex());
- cmesh.vertices.back().normal = normalsArray[j];
- cmesh.vertices.back().position = positionArray[j];
- cmesh.vertices.back().uv = uvArray[j];
- }
- }
- const uint32_t indicesCount = rdr->getIndicesCount();
- const auto indexArray = rdr->getIndexArray();
- for (uint32_t j = 0; j < indicesCount; j += 3)
- {
- //Reverse the winding order
- for (int tv : { 2, 1, 0})
- {
- uint32_t oldIndex = indexArray[j + tv];
- int32_t newIndex = indRemap[oldIndex];
- if (newIndex >= 0)
- {
- cmesh.indices.push_back(newIndex);
- }
- }
- }
-
- model->chunks[i].meshes.push_back(Chunk::Mesh());
- model->chunks[i].meshes.back().materialIndex = 0;
- model->chunks[i].meshes.back().mesh = std::move(cmesh);
- }
- NVBLAST_FREE(infl);
- return model;
-}
-
-
-void loadMeshes(std::vector<BlastModel::Chunk::Mesh>& meshes, tinyobj::mesh_t mesh)
-{
- // Check if all faces are triangles
- bool allTriangles = true;
- for (uint32_t i = 0; i < mesh.num_vertices.size(); ++i)
- {
- if (mesh.num_vertices[i] != 3)
- {
- allTriangles = false;
- break;
- }
- }
- if (!allTriangles) return;
-
- std::map<int32_t, uint32_t> matIdToMesh;
- for (int32_t mt : mesh.material_ids)
- {
- auto it = matIdToMesh.find(mt);
- if (it == matIdToMesh.end())
- {
- meshes.push_back(BlastModel::Chunk::Mesh());
- matIdToMesh[mt] = uint32_t(meshes.size()) - 1;
- }
- }
-
- std::vector<SimpleMesh::Vertex> oldVertices(mesh.positions.size() / 3);
- std::vector<uint32_t> oldIndexToNew;
-
- for (uint32_t i = 0; i < oldVertices.size(); ++i)
- {
- oldVertices[i].position.x = mesh.positions[i * 3];
- oldVertices[i].position.y = mesh.positions[i * 3 + 1];
- oldVertices[i].position.z = mesh.positions[i * 3 + 2];
-
- oldVertices[i].normal.x = mesh.normals[i * 3];
- oldVertices[i].normal.y = mesh.normals[i * 3 + 1];
- oldVertices[i].normal.z = mesh.normals[i * 3 + 2];
-
- oldVertices[i].uv.x = mesh.texcoords[i * 2];
- oldVertices[i].uv.y = mesh.texcoords[i * 2 + 1];
- }
-
- for (auto matmapping : matIdToMesh)
- {
- int32_t mid = matmapping.first;
- auto sampleMesh = &meshes[matmapping.second];
- sampleMesh->materialIndex = (mid >= 0)? mid : 0;
- oldIndexToNew.assign(oldVertices.size(), -1);
-
- PxVec3 emin(FLT_MAX, FLT_MAX, FLT_MAX);
- PxVec3 emax(FLT_MIN, FLT_MIN, FLT_MIN);
-
-
- for (uint32_t i = 0; i < mesh.indices.size() / 3; i++)
- {
- if (mesh.material_ids[i] != mid) continue;
- for (int32_t vi = 2; vi >= 0; --vi)
- {
- int32_t idx = mesh.indices[i * 3 + vi];
- if (oldIndexToNew[idx] == -1)
- {
- oldIndexToNew[idx] = (uint32_t)sampleMesh->mesh.vertices.size();
- sampleMesh->mesh.vertices.push_back(oldVertices[idx]);
-
- emin = emin.minimum(sampleMesh->mesh.vertices.back().position);
- emax = emax.maximum(sampleMesh->mesh.vertices.back().position);
- }
- sampleMesh->mesh.indices.push_back(oldIndexToNew[idx]);
-
- // assign extents
- sampleMesh->mesh.extents = (emax - emin) * 0.5f;
-
- // get the center
- sampleMesh->mesh.center = emin + sampleMesh->mesh.extents;
- }
- }
- }
-}
-
-
-BlastModelPtr BlastModel::loadFromFileTinyLoader(const char* path)
-{
- std::shared_ptr<BlastModel> model = std::shared_ptr<BlastModel>(new BlastModel());
-
- std::vector<tinyobj::shape_t> shapes;
- std::vector<tinyobj::material_t> mats;
- std::string err;
- std::string mtlPath;
- for (size_t i = strnlen(path, 255) - 1; i >= 0; --i)
- {
- if (path[i] == '\\')
- {
- mtlPath.resize(i + 2, 0);
- strncpy(&mtlPath[0], path, i + 1);
- break;
- }
- }
-
-
- bool ret = tinyobj::LoadObj(shapes, mats, err, path, mtlPath.data());
-
- // can't load?
- if (!ret)
- return false;
-
- // one submodel per material
- uint32_t materialsCount = (uint32_t)mats.size();
- model->materials.resize(materialsCount);
-
- // fill submodel materials
- for (uint32_t i = 0; i < materialsCount; i++)
- {
- tinyobj::material_t *pMaterial = &mats[i];
-
- if (!pMaterial->diffuse_texname.empty())
- {
- model->materials[i].diffuseTexture = pMaterial->diffuse_texname;
- }
- }
-
- // estimate
- model->chunks.reserve(shapes.size() / materialsCount + 1);
-
- if (shapes.size() > 0)
- {
- uint32_t meshIndex = 0;
- for (uint32_t m = 0; m < shapes.size(); m++)
- {
- tinyobj::shape_t& pMesh = shapes[m];
- int32_t materialIndex = 0; // This is actually not set
- uint32_t chunkIndex;
- int32_t sc = sscanf(pMesh.name.data(), "%d_%d", &chunkIndex, &materialIndex);
- if (sc == 0)
- {
- return nullptr;
- }
- if (model->chunks.size() <= chunkIndex)
- {
- model->chunks.resize(chunkIndex + 1);
- }
- loadMeshes(model->chunks.back().meshes, pMesh.mesh);
- }
- }
-
- return model;
-}
+// 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-2018 NVIDIA Corporation. All rights reserved.
+
+
+#include "BlastModel.h"
+
+#define TINYOBJLOADER_IMPLEMENTATION
+#include "tiny_obj_loader.h"
+#include "NvBlastExtExporter.h"
+#include "NvBlastGlobals.h"
+
+using namespace physx;
+
+BlastModelPtr BlastModel::loadFromFbxFile(const char* path)
+{
+ std::shared_ptr<BlastModel> model = std::shared_ptr<BlastModel>(new BlastModel());
+
+
+ std::shared_ptr<Nv::Blast::IFbxFileReader> rdr(NvBlastExtExporterCreateFbxFileReader(), [](Nv::Blast::IFbxFileReader* p) {p->release(); });
+ rdr->loadFromFile(path);
+ if (rdr->getBoneCount() == 0)
+ {
+ return nullptr;
+ }
+
+ model->chunks.resize(rdr->getBoneCount());
+
+ model->materials.push_back(BlastModel::Material());
+
+
+ /**
+ Produce buffers of appropriate for AssetViewer format
+ */
+ uint32_t* infl;
+ rdr->getBoneInfluences(infl);
+
+ std::vector<int32_t> indRemap(rdr->getVerticesCount(), -1);
+ for (uint32_t i = 0; i < rdr->getBoneCount(); ++i)
+ {
+ std::fill(indRemap.begin(), indRemap.end(), -1);
+ SimpleMesh cmesh;
+ const uint32_t vertexCount = rdr->getVerticesCount();
+ const auto normalsArray = rdr->getNormalsArray();
+ const auto positionArray = rdr->getPositionArray();
+ const auto uvArray = rdr->getUvArray();
+
+ for (uint32_t j = 0; j < vertexCount; ++j)
+ {
+ if (i == infl[j])
+ {
+ indRemap[j] = (int32_t)cmesh.vertices.size();
+ cmesh.vertices.push_back(SimpleMesh::Vertex());
+ cmesh.vertices.back().normal = normalsArray[j];
+ cmesh.vertices.back().position = positionArray[j];
+ cmesh.vertices.back().uv = uvArray[j];
+ }
+ }
+ const uint32_t indicesCount = rdr->getIndicesCount();
+ const auto indexArray = rdr->getIndexArray();
+ for (uint32_t j = 0; j < indicesCount; j += 3)
+ {
+ //Reverse the winding order
+ for (int tv : { 2, 1, 0})
+ {
+ uint32_t oldIndex = indexArray[j + tv];
+ int32_t newIndex = indRemap[oldIndex];
+ if (newIndex >= 0)
+ {
+ cmesh.indices.push_back(newIndex);
+ }
+ }
+ }
+
+ model->chunks[i].meshes.push_back(Chunk::Mesh());
+ model->chunks[i].meshes.back().materialIndex = 0;
+ model->chunks[i].meshes.back().mesh = std::move(cmesh);
+ }
+ NVBLAST_FREE(infl);
+ return model;
+}
+
+
+void loadMeshes(std::vector<BlastModel::Chunk::Mesh>& meshes, tinyobj::mesh_t mesh)
+{
+ // Check if all faces are triangles
+ bool allTriangles = true;
+ for (uint32_t i = 0; i < mesh.num_vertices.size(); ++i)
+ {
+ if (mesh.num_vertices[i] != 3)
+ {
+ allTriangles = false;
+ break;
+ }
+ }
+ if (!allTriangles) return;
+
+ std::map<int32_t, uint32_t> matIdToMesh;
+ for (int32_t mt : mesh.material_ids)
+ {
+ auto it = matIdToMesh.find(mt);
+ if (it == matIdToMesh.end())
+ {
+ meshes.push_back(BlastModel::Chunk::Mesh());
+ matIdToMesh[mt] = uint32_t(meshes.size()) - 1;
+ }
+ }
+
+ std::vector<SimpleMesh::Vertex> oldVertices(mesh.positions.size() / 3);
+ std::vector<uint32_t> oldIndexToNew;
+
+ for (uint32_t i = 0; i < oldVertices.size(); ++i)
+ {
+ oldVertices[i].position.x = mesh.positions[i * 3];
+ oldVertices[i].position.y = mesh.positions[i * 3 + 1];
+ oldVertices[i].position.z = mesh.positions[i * 3 + 2];
+
+ oldVertices[i].normal.x = mesh.normals[i * 3];
+ oldVertices[i].normal.y = mesh.normals[i * 3 + 1];
+ oldVertices[i].normal.z = mesh.normals[i * 3 + 2];
+
+ oldVertices[i].uv.x = mesh.texcoords[i * 2];
+ oldVertices[i].uv.y = mesh.texcoords[i * 2 + 1];
+ }
+
+ for (auto matmapping : matIdToMesh)
+ {
+ int32_t mid = matmapping.first;
+ auto sampleMesh = &meshes[matmapping.second];
+ sampleMesh->materialIndex = (mid >= 0)? mid : 0;
+ oldIndexToNew.assign(oldVertices.size(), -1);
+
+ PxVec3 emin(FLT_MAX, FLT_MAX, FLT_MAX);
+ PxVec3 emax(FLT_MIN, FLT_MIN, FLT_MIN);
+
+
+ for (uint32_t i = 0; i < mesh.indices.size() / 3; i++)
+ {
+ if (mesh.material_ids[i] != mid) continue;
+ for (int32_t vi = 2; vi >= 0; --vi)
+ {
+ int32_t idx = mesh.indices[i * 3 + vi];
+ if (oldIndexToNew[idx] == -1)
+ {
+ oldIndexToNew[idx] = (uint32_t)sampleMesh->mesh.vertices.size();
+ sampleMesh->mesh.vertices.push_back(oldVertices[idx]);
+
+ emin = emin.minimum(sampleMesh->mesh.vertices.back().position);
+ emax = emax.maximum(sampleMesh->mesh.vertices.back().position);
+ }
+ sampleMesh->mesh.indices.push_back(oldIndexToNew[idx]);
+
+ // assign extents
+ sampleMesh->mesh.extents = (emax - emin) * 0.5f;
+
+ // get the center
+ sampleMesh->mesh.center = emin + sampleMesh->mesh.extents;
+ }
+ }
+ }
+}
+
+
+BlastModelPtr BlastModel::loadFromFileTinyLoader(const char* path)
+{
+ std::shared_ptr<BlastModel> model = std::shared_ptr<BlastModel>(new BlastModel());
+
+ std::vector<tinyobj::shape_t> shapes;
+ std::vector<tinyobj::material_t> mats;
+ std::string err;
+ std::string mtlPath;
+ for (size_t i = strnlen(path, 255) - 1; i >= 0; --i)
+ {
+ if (path[i] == '\\')
+ {
+ mtlPath.resize(i + 2, 0);
+ strncpy(&mtlPath[0], path, i + 1);
+ break;
+ }
+ }
+
+
+ bool ret = tinyobj::LoadObj(shapes, mats, err, path, mtlPath.data());
+
+ // can't load?
+ if (!ret)
+ return false;
+
+ // one submodel per material
+ uint32_t materialsCount = (uint32_t)mats.size();
+ model->materials.resize(materialsCount);
+
+ // fill submodel materials
+ for (uint32_t i = 0; i < materialsCount; i++)
+ {
+ tinyobj::material_t *pMaterial = &mats[i];
+
+ if (!pMaterial->diffuse_texname.empty())
+ {
+ model->materials[i].diffuseTexture = pMaterial->diffuse_texname;
+ }
+ }
+
+ // estimate
+ model->chunks.reserve(shapes.size() / materialsCount + 1);
+
+ if (shapes.size() > 0)
+ {
+ uint32_t meshIndex = 0;
+ for (uint32_t m = 0; m < shapes.size(); m++)
+ {
+ tinyobj::shape_t& pMesh = shapes[m];
+ int32_t materialIndex = 0; // This is actually not set
+ uint32_t chunkIndex;
+ int32_t sc = sscanf(pMesh.name.data(), "%d_%d", &chunkIndex, &materialIndex);
+ if (sc == 0)
+ {
+ return nullptr;
+ }
+ if (model->chunks.size() <= chunkIndex)
+ {
+ model->chunks.resize(chunkIndex + 1);
+ }
+ loadMeshes(model->chunks.back().meshes, pMesh.mesh);
+ }
+ }
+
+ return model;
+}
diff --git a/samples/SampleBase/blast/BlastModel.h b/samples/SampleBase/blast/BlastModel.h
index 115f716..f0e0a66 100644..100755
--- a/samples/SampleBase/blast/BlastModel.h
+++ b/samples/SampleBase/blast/BlastModel.h
@@ -1,74 +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 BLAST_MODEL_H
-#define BLAST_MODEL_H
-
-#include "Mesh.h"
-#include <vector>
-#include <memory>
-
-
-class BlastModel;
-typedef std::shared_ptr<const BlastModel> BlastModelPtr;
-
-/**
-BlastModel struct represents graphic model.
-Now only loading from .obj file is supported.
-Can have >=0 materials
-Every chunk can have multiple meshes (1 for every material)
-*/
-class BlastModel
-{
-public:
- struct Material
- {
- std::string diffuseTexture;
- };
-
- struct Chunk
- {
- struct Mesh
- {
- uint32_t materialIndex;
- SimpleMesh mesh;
- };
-
- std::vector<Mesh> meshes;
- };
-
- std::vector<Material> materials;
- std::vector<Chunk> chunks;
-
- static BlastModelPtr loadFromFileTinyLoader(const char* path);
- static BlastModelPtr loadFromFbxFile(const char* path);
-private:
- BlastModel() {}
-};
-
+// 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 BLAST_MODEL_H
+#define BLAST_MODEL_H
+
+#include "Mesh.h"
+#include <vector>
+#include <memory>
+
+
+class BlastModel;
+typedef std::shared_ptr<const BlastModel> BlastModelPtr;
+
+/**
+BlastModel struct represents graphic model.
+Now only loading from .obj file is supported.
+Can have >=0 materials
+Every chunk can have multiple meshes (1 for every material)
+*/
+class BlastModel
+{
+public:
+ struct Material
+ {
+ std::string diffuseTexture;
+ };
+
+ struct Chunk
+ {
+ struct Mesh
+ {
+ uint32_t materialIndex;
+ SimpleMesh mesh;
+ };
+
+ std::vector<Mesh> meshes;
+ };
+
+ std::vector<Material> materials;
+ std::vector<Chunk> chunks;
+
+ static BlastModelPtr loadFromFileTinyLoader(const char* path);
+ static BlastModelPtr loadFromFbxFile(const char* path);
+private:
+ BlastModel() {}
+};
+
#endif // ifndef BLAST_MODEL_H \ No newline at end of file
diff --git a/samples/SampleBase/blast/BlastReplay.cpp b/samples/SampleBase/blast/BlastReplay.cpp
index b41f373..e1afc63 100644..100755
--- a/samples/SampleBase/blast/BlastReplay.cpp
+++ b/samples/SampleBase/blast/BlastReplay.cpp
@@ -1,178 +1,178 @@
-// 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-2018 NVIDIA Corporation. All rights reserved.
-
-
-#include "BlastReplay.h"
-#include "NvBlastTk.h"
-#include "NvBlastExtPxManager.h"
-#include "NvBlastExtPxFamily.h"
-#include "SampleProfiler.h"
-
-
-using namespace std::chrono;
-
-BlastReplay::BlastReplay() : m_sync(nullptr)
-{
- m_sync = ExtSync::create();
- reset();
-}
-
-BlastReplay::~BlastReplay()
-{
- m_sync->release();
- clearBuffer();
-}
-
-void BlastReplay::addFamily(TkFamily* family)
-{
- family->addListener(*m_sync);
-}
-
-void BlastReplay::removeFamily(TkFamily* family)
-{
- family->removeListener(*m_sync);
-}
-
-void BlastReplay::startRecording(ExtPxManager& manager, bool syncFamily, bool syncPhysics)
-{
- if (isRecording())
- return;
-
- m_sync->releaseSyncBuffer();
-
- if (syncFamily || syncPhysics)
- {
- std::vector<ExtPxFamily*> families(manager.getFamilyCount());
- manager.getFamilies(families.data(), (uint32_t)families.size());
- for (ExtPxFamily* family : families)
- {
- if (syncPhysics)
- {
- m_sync->syncFamily(*family);
- }
- else if (syncFamily)
- {
- m_sync->syncFamily(family->getTkFamily());
- }
- }
- }
-
- m_isRecording = true;
-}
-
-void BlastReplay::stopRecording()
-{
- if (!isRecording())
- return;
-
- const ExtSyncEvent*const* buffer;
- uint32_t size;
- m_sync->acquireSyncBuffer(buffer, size);
-
- clearBuffer();
- m_buffer.resize(size);
- for (uint32_t i = 0; i < size; ++i)
- {
- m_buffer[i] = buffer[i]->clone();
- }
-
- // TODO: sort by ts ? make sure?
- //m_buffer.sort
-
- m_sync->releaseSyncBuffer();
-
- m_isRecording = false;
-}
-
-void BlastReplay::startPlayback(ExtPxManager& manager, TkGroup* group)
-{
- if (isPlaying() || !hasRecord())
- return;
-
- m_isPlaying = true;
- m_startTime = steady_clock::now();
- m_nextEventIndex = 0;
- m_firstEventTs = m_buffer[0]->timestamp;
- m_pxManager = &manager;
- m_group = group;
-}
-
-void BlastReplay::stopPlayback()
-{
- if (!isPlaying())
- return;
-
- m_isPlaying = false;
- m_pxManager = nullptr;
- m_group = nullptr;
-}
-
-void BlastReplay::update()
-{
- if (isPlaying())
- {
- PROFILER_SCOPED_FUNCTION();
-
- auto now = steady_clock::now();
- auto mil = duration_cast<milliseconds>((now - m_startTime));
- bool stop = true;
- while (m_nextEventIndex < m_buffer.size())
- {
- const ExtSyncEvent* e = m_buffer[m_nextEventIndex];
- auto t = e->timestamp - m_firstEventTs;
- if (t < (uint64_t)mil.count())
- {
- m_sync->applySyncBuffer(m_pxManager->getFramework(), &e, 1, m_group, m_pxManager);
- m_nextEventIndex++;
- }
- else
- {
- stop = false;
- break;
- }
- }
-
- if (stop)
- stopPlayback();
- }
-}
-
-void BlastReplay::reset()
-{
- m_isPlaying = false;
- m_isRecording = false;
- m_sync->releaseSyncBuffer();
-}
-
-void BlastReplay::clearBuffer()
-{
- for (auto e : m_buffer)
- {
- e->release();
- }
- m_buffer.clear();
-}
+// 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-2018 NVIDIA Corporation. All rights reserved.
+
+
+#include "BlastReplay.h"
+#include "NvBlastTk.h"
+#include "NvBlastExtPxManager.h"
+#include "NvBlastExtPxFamily.h"
+#include "SampleProfiler.h"
+
+
+using namespace std::chrono;
+
+BlastReplay::BlastReplay() : m_sync(nullptr)
+{
+ m_sync = ExtSync::create();
+ reset();
+}
+
+BlastReplay::~BlastReplay()
+{
+ m_sync->release();
+ clearBuffer();
+}
+
+void BlastReplay::addFamily(TkFamily* family)
+{
+ family->addListener(*m_sync);
+}
+
+void BlastReplay::removeFamily(TkFamily* family)
+{
+ family->removeListener(*m_sync);
+}
+
+void BlastReplay::startRecording(ExtPxManager& manager, bool syncFamily, bool syncPhysics)
+{
+ if (isRecording())
+ return;
+
+ m_sync->releaseSyncBuffer();
+
+ if (syncFamily || syncPhysics)
+ {
+ std::vector<ExtPxFamily*> families(manager.getFamilyCount());
+ manager.getFamilies(families.data(), (uint32_t)families.size());
+ for (ExtPxFamily* family : families)
+ {
+ if (syncPhysics)
+ {
+ m_sync->syncFamily(*family);
+ }
+ else if (syncFamily)
+ {
+ m_sync->syncFamily(family->getTkFamily());
+ }
+ }
+ }
+
+ m_isRecording = true;
+}
+
+void BlastReplay::stopRecording()
+{
+ if (!isRecording())
+ return;
+
+ const ExtSyncEvent*const* buffer;
+ uint32_t size;
+ m_sync->acquireSyncBuffer(buffer, size);
+
+ clearBuffer();
+ m_buffer.resize(size);
+ for (uint32_t i = 0; i < size; ++i)
+ {
+ m_buffer[i] = buffer[i]->clone();
+ }
+
+ // TODO: sort by ts ? make sure?
+ //m_buffer.sort
+
+ m_sync->releaseSyncBuffer();
+
+ m_isRecording = false;
+}
+
+void BlastReplay::startPlayback(ExtPxManager& manager, TkGroup* group)
+{
+ if (isPlaying() || !hasRecord())
+ return;
+
+ m_isPlaying = true;
+ m_startTime = steady_clock::now();
+ m_nextEventIndex = 0;
+ m_firstEventTs = m_buffer[0]->timestamp;
+ m_pxManager = &manager;
+ m_group = group;
+}
+
+void BlastReplay::stopPlayback()
+{
+ if (!isPlaying())
+ return;
+
+ m_isPlaying = false;
+ m_pxManager = nullptr;
+ m_group = nullptr;
+}
+
+void BlastReplay::update()
+{
+ if (isPlaying())
+ {
+ PROFILER_SCOPED_FUNCTION();
+
+ auto now = steady_clock::now();
+ auto mil = duration_cast<milliseconds>((now - m_startTime));
+ bool stop = true;
+ while (m_nextEventIndex < m_buffer.size())
+ {
+ const ExtSyncEvent* e = m_buffer[m_nextEventIndex];
+ auto t = e->timestamp - m_firstEventTs;
+ if (t < (uint64_t)mil.count())
+ {
+ m_sync->applySyncBuffer(m_pxManager->getFramework(), &e, 1, m_group, m_pxManager);
+ m_nextEventIndex++;
+ }
+ else
+ {
+ stop = false;
+ break;
+ }
+ }
+
+ if (stop)
+ stopPlayback();
+ }
+}
+
+void BlastReplay::reset()
+{
+ m_isPlaying = false;
+ m_isRecording = false;
+ m_sync->releaseSyncBuffer();
+}
+
+void BlastReplay::clearBuffer()
+{
+ for (auto e : m_buffer)
+ {
+ e->release();
+ }
+ m_buffer.clear();
+}
diff --git a/samples/SampleBase/blast/BlastReplay.h b/samples/SampleBase/blast/BlastReplay.h
index 0d00ce1..fb3c708 100644..100755
--- a/samples/SampleBase/blast/BlastReplay.h
+++ b/samples/SampleBase/blast/BlastReplay.h
@@ -1,93 +1,93 @@
-// 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 BLAST_REPLAY_H
-#define BLAST_REPLAY_H
-
-#include "NvBlastExtSync.h"
-#include <chrono>
-
-using namespace Nv::Blast;
-
-class BlastReplay
-{
-public:
- BlastReplay();
- ~BlastReplay();
-
- bool isRecording() const
- {
- return m_isRecording;
- }
-
- bool isPlaying() const
- {
- return m_isPlaying;
- }
-
- bool hasRecord() const
- {
- return m_buffer.size() > 0;
- }
-
- size_t getEventCount() const
- {
- return isRecording() ? m_sync->getSyncBufferSize() : m_buffer.size();
- }
-
- uint32_t getCurrentEventIndex() const
- {
- return m_nextEventIndex;
- }
-
- void addFamily(TkFamily* family);
- void removeFamily(TkFamily* family);
-
- void startRecording(ExtPxManager& manager, bool syncFamily, bool syncPhysics);
- void stopRecording();
- void startPlayback(ExtPxManager& manager, TkGroup* group);
- void stopPlayback();
- void update();
- void reset();
-
-private:
- void clearBuffer();
-
- ExtPxManager* m_pxManager;
- TkGroup* m_group;
- std::chrono::steady_clock::time_point m_startTime;
- uint64_t m_firstEventTs;
- uint32_t m_nextEventIndex;
- bool m_isRecording;
- bool m_isPlaying;
- ExtSync* m_sync;
- std::vector<ExtSyncEvent*> m_buffer;
-};
-
-
+// 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 BLAST_REPLAY_H
+#define BLAST_REPLAY_H
+
+#include "NvBlastExtSync.h"
+#include <chrono>
+
+using namespace Nv::Blast;
+
+class BlastReplay
+{
+public:
+ BlastReplay();
+ ~BlastReplay();
+
+ bool isRecording() const
+ {
+ return m_isRecording;
+ }
+
+ bool isPlaying() const
+ {
+ return m_isPlaying;
+ }
+
+ bool hasRecord() const
+ {
+ return m_buffer.size() > 0;
+ }
+
+ size_t getEventCount() const
+ {
+ return isRecording() ? m_sync->getSyncBufferSize() : m_buffer.size();
+ }
+
+ uint32_t getCurrentEventIndex() const
+ {
+ return m_nextEventIndex;
+ }
+
+ void addFamily(TkFamily* family);
+ void removeFamily(TkFamily* family);
+
+ void startRecording(ExtPxManager& manager, bool syncFamily, bool syncPhysics);
+ void stopRecording();
+ void startPlayback(ExtPxManager& manager, TkGroup* group);
+ void stopPlayback();
+ void update();
+ void reset();
+
+private:
+ void clearBuffer();
+
+ ExtPxManager* m_pxManager;
+ TkGroup* m_group;
+ std::chrono::steady_clock::time_point m_startTime;
+ uint64_t m_firstEventTs;
+ uint32_t m_nextEventIndex;
+ bool m_isRecording;
+ bool m_isPlaying;
+ ExtSync* m_sync;
+ std::vector<ExtSyncEvent*> m_buffer;
+};
+
+
#endif // ifndef BLAST_REPLAY_H \ No newline at end of file