aboutsummaryrefslogtreecommitdiff
path: root/tools/ArtistTools/source/BlastPlugin/SampleBase
diff options
context:
space:
mode:
authorAnton Novoselov <[email protected]>2017-08-01 12:53:38 +0300
committerAnton Novoselov <[email protected]>2017-08-01 12:53:38 +0300
commit236f03c0b9a4982328ed1201978f7f69d192d9b2 (patch)
treee486f2fa39dba203563895541e92c60ed3e25759 /tools/ArtistTools/source/BlastPlugin/SampleBase
parentAdded screens to welcome page (diff)
downloadblast-236f03c0b9a4982328ed1201978f7f69d192d9b2.tar.xz
blast-236f03c0b9a4982328ed1201978f7f69d192d9b2.zip
Blast 1.1 release (windows / linux)
see docs/release_notes.txt for details
Diffstat (limited to 'tools/ArtistTools/source/BlastPlugin/SampleBase')
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/Sample.h40
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAsset.cpp114
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAsset.h52
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetBoxes.cpp42
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetBoxes.h36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModel.cpp235
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModel.h40
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSimple.cpp74
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSimple.h47
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSkinned.cpp42
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSkinned.h38
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastController.cpp359
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastController.h69
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamily.cpp248
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamily.h93
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyBoxes.cpp35
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyBoxes.h36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSimple.cpp489
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSimple.h63
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSkinned.cpp36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSkinned.h36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFractureTool.cpp104
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFractureTool.h40
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastModel.cpp175
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastModel.h42
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastReplay.cpp36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastReplay.h36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/core/Application.cpp36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/core/Application.h36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/core/DeviceManager.cpp13
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/core/SampleController.cpp40
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/core/SampleController.h41
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/core/SampleManager.cpp2865
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/core/SampleManager.h221
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/physx/PhysXController.cpp327
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/physx/PhysXController.h87
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ConvexRenderMesh.cpp36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ConvexRenderMesh.h36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/CustomRenderMesh.cpp36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/CustomRenderMesh.h36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/DebugRenderBuffer.h36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Mesh.cpp35
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Mesh.h37
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/PrimitiveRenderMesh.cpp35
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/PrimitiveRenderMesh.h36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderMaterial.cpp156
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderMaterial.h73
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderUtils.h59
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderable.cpp96
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderable.h58
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderer.cpp140
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderer.h59
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererHBAO.cpp35
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererHBAO.h36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererShadow.cpp67
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererShadow.h41
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ResourceManager.cpp85
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ResourceManager.h40
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ShaderUtils.h36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/SkinnedRenderMesh.cpp35
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/SkinnedRenderMesh.h36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/scene/SampleAssetListParser.cpp48
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/scene/SampleAssetListParser.h36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/scene/SceneController.cpp573
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/scene/SceneController.h52
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/ui/CommonUIController.cpp36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/ui/CommonUIController.h36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/ui/DamageToolController.cpp426
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/ui/DamageToolController.h110
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/ui/EditionToolController.cpp69
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/ui/EditionToolController.h36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/ui/ExplodeToolController.cpp256
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/ui/ExplodeToolController.h100
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/ui/GizmoToolController.cpp1165
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/ui/GizmoToolController.h65
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/ui/SelectionToolController.cpp271
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/ui/SelectionToolController.h62
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/utils/PxInputDataFromPxFileBuf.h36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/utils/SampleProfiler.cpp35
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/utils/SampleProfiler.h36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/utils/SampleTime.h36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/utils/UIHelpers.h36
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/utils/Utils.cpp28
-rw-r--r--tools/ArtistTools/source/BlastPlugin/SampleBase/utils/Utils.h28
84 files changed, 8555 insertions, 2719 deletions
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/Sample.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/Sample.h
index c9fa503..2499deb 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/Sample.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/Sample.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef SAMPLE_H
#define SAMPLE_H
@@ -21,7 +39,7 @@ struct AssetList
struct BoxAsset
{
BoxAsset() : staticHeight(-std::numeric_limits<float>().infinity()),
- jointAllBonds(false), extents(20, 20, 20)
+ jointAllBonds(false), extents(20, 20, 20), bondFlags(7)
{}
struct Level
@@ -38,6 +56,7 @@ struct AssetList
float staticHeight;
bool jointAllBonds;
std::vector<Level> levels;
+ uint32_t bondFlags;
};
struct ModelAsset
@@ -48,6 +67,7 @@ struct AssetList
std::string id;
std::string file;
std::string name;
+ std::string fullpath;
physx::PxTransform transform;
bool isSkinned;
};
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAsset.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAsset.cpp
index 01f8fd6..c39d927 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAsset.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAsset.cpp
@@ -1,25 +1,117 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "BlastAsset.h"
#include "NvBlastExtPxAsset.h"
#include "NvBlastTkAsset.h"
#include <map>
+#include <algorithm>
+// Add By Lixu Begin
+#include "BlastSceneTree.h"
+#include "SampleManager.h"
+// Add By Lixu End
+
BlastAsset::BlastAsset(Renderer& renderer)
- : m_renderer(renderer)
+ : m_renderer(renderer), m_bondHealthMax(1.0f), m_supportChunkHealthMax(1.0f)
{
}
-void BlastAsset::validate()
+void BlastAsset::initialize()
{
+// Add By Lixu Begin
+ BPPBlast& blast = BlastProject::ins().getParams().blast;
+ BPPChunkArray& chunks = blast.chunks;
+ BPPBondArray& bonds = blast.bonds;
+
+ std::vector<float> BondHealths;
+ SampleManager* pSampleManager = SampleManager::ins();
+ std::map<BlastAsset*, AssetList::ModelAsset>& AssetDescMap = pSampleManager->getAssetDescMap();
+ std::map<BlastAsset*, AssetList::ModelAsset>::iterator itASM = AssetDescMap.find(this);
+ AssetList::ModelAsset m;
+ if (itASM != AssetDescMap.end())
+ {
+ m = itASM->second;
+ }
+
+ int assetID = BlastProject::ins().getAssetIDByName(m.name.c_str());
+ for (int bc = 0; bc < bonds.arraySizes[0]; bc++)
+ {
+ BPPBond& bond = bonds.buf[bc];
+ if (bond.asset == assetID)
+ {
+ BondHealths.push_back(bond.support.bondStrength);
+ }
+ }
+
+ const TkAsset& tkAsset = m_pxAsset->getTkAsset();
+ uint32_t bondCount = tkAsset.getBondCount();
+
+ const float* pBondHealths = nullptr;
+ if (bondCount == BondHealths.size())
+ {
+ pBondHealths = BondHealths.data();
+ }
+
+ const NvBlastActorDesc& defaultActorDesc = m_pxAsset->getDefaultActorDesc();
+ NvBlastActorDesc newActorDesc = defaultActorDesc;
+ newActorDesc.initialBondHealths = pBondHealths;
+// Add By Lixu End
+
+ // calc max healths
+ const NvBlastActorDesc& actorDesc = newActorDesc;
+ 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;
+ }
}
size_t BlastAsset::getBlastAssetSize() const
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAsset.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAsset.h
index b2e2f38..5502c5c 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAsset.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAsset.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef BLAST_ASSET_H
#define BLAST_ASSET_H
@@ -16,6 +34,7 @@
#include "PxTransform.h"
#include "NvBlastTypes.h"
+
using namespace physx;
class Renderer;
@@ -77,11 +96,22 @@ public:
size_t getBlastAssetSize() const;
std::vector<uint32_t> getChunkIndexesByDepth(uint32_t depth) const;
+
+ float getBondHealthMax() const
+ {
+ return m_bondHealthMax;
+ }
+
+ float getSupportChunkHealthMax() const
+ {
+ return m_bondHealthMax;
+ }
+
+ void initialize();
protected:
//////// internal operations ////////
- void validate();
//////// input data ////////
@@ -92,6 +122,8 @@ protected:
//////// internal data ////////
ExtPxAsset* m_pxAsset;
+ float m_bondHealthMax;
+ float m_supportChunkHealthMax;
};
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetBoxes.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetBoxes.cpp
index dfa0138..4bd9766 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetBoxes.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetBoxes.cpp
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "BlastAssetBoxes.h"
#include "BlastFamilyBoxes.h"
@@ -23,9 +41,9 @@ BlastAssetBoxes::BlastAssetBoxes(TkFramework& framework, PxPhysics& physics, PxC
// asset desc / tk asset
ExtPxAssetDesc assetDesc;
- assetDesc.chunkDescs = &m_generatorAsset.solverChunks[0];
+ assetDesc.chunkDescs = m_generatorAsset.solverChunks.data();
assetDesc.chunkCount = (uint32_t)m_generatorAsset.solverChunks.size();
- assetDesc.bondDescs = m_generatorAsset.solverBonds.size() > 0 ? &m_generatorAsset.solverBonds[0] : nullptr;
+ 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);
@@ -67,7 +85,7 @@ BlastAssetBoxes::BlastAssetBoxes(TkFramework& framework, PxPhysics& physics, PxC
assetDesc.pxChunks = pxChunks.data();
m_pxAsset = ExtPxAsset::create(assetDesc, framework);
- validate();
+ initialize();
}
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetBoxes.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetBoxes.h
index 518e93d..d4f8dd2 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetBoxes.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetBoxes.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef BLAST_ASSET_BOXES_H
#define BLAST_ASSET_BOXES_H
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModel.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModel.cpp
index 756b520..2c39824 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModel.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModel.cpp
@@ -1,69 +1,236 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "GlobalSettings.h"
+#include <QtCore/QFile>
#include "BlastAssetModel.h"
#include "Renderer.h"
#include "BlastController.h"
#include "Utils.h"
-#include "PsFileBuffer.h"
+#include "ResourceManager.h"
#include "NvBlastExtPxAsset.h"
-#include <QtCore/QFile>
#include <sstream>
+#include <fstream>
+#include "NvBlastExtExporterFbxReader.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"
-
-BlastAssetModel::BlastAssetModel(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, Renderer& renderer, const char* modelName, const char* modelPath)
+BlastAssetModel::BlastAssetModel(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName, const char* modelPath)
: BlastAsset(renderer)
{
- // Add By Lixu Begin
if (modelPath == NULL)
{
GlobalSettings& globalSettings = GlobalSettings::Inst();
modelPath = globalSettings.m_projectFileDir.c_str();
assert(globalSettings.m_projectFileDir.length() > 0);
}
- // Physics Asset
- std::string blastFileName = std::string(modelName) + ".bpxa";
- // Add By Lixu Begin
- std::string path = GlobalSettings::MakeFileName(modelPath, blastFileName.c_str());
- if (QFile::exists(path.c_str()))
- {
- PsFileBuffer fileBuf(path.c_str(), PxFileBuf::OPEN_READ_ONLY);
- m_pxAsset = ExtPxAsset::deserialize(fileBuf, framework, physics);
- ASSERT_PRINT(m_pxAsset != nullptr, "can't load bpxa file");
- }
- else
- {
- ASSERT_PRINT(false, "wrong blastFilename");
- }
+
+ const float unitConversion = 1.f;
+
+ const NvcVec3 inputScale = { unitConversion, unitConversion, unitConversion };
+
+ std::string path;
// load obj file
- std::string objFileName = std::string(modelName) + ".obj";
- // Add By Lixu Begin
- path = GlobalSettings::MakeFileName(modelPath, objFileName.c_str());
+ std::ostringstream objFileName;
+ objFileName << modelName << ".obj";
+
+ path = GlobalSettings::MakeFileName(modelPath, objFileName.str().c_str());
if (QFile::exists(path.c_str()))
{
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";
+ path = GlobalSettings::MakeFileName(modelPath, objFileName.str().c_str());
+ if (QFile::exists(path.c_str()))
+ {
+ m_model = BlastModel::loadFromFbxFile(path.c_str());
+ if (!m_model)
+ {
+ ASSERT_PRINT(false, "fbx load failed");
+ }
+
+ }
+ else
+ {
+ ASSERT_PRINT(false, "mesh file not found");
}
}
- else
+
+ for (auto& chunk : m_model->chunks)
{
- ASSERT_PRINT(false, "wrong objFileName");
+ 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;
+ }
+ }
}
- validate();
+ // Physics Asset
+
+ // Read file into buffer
+ std::ostringstream blastFileName;
+ blastFileName << modelName << ".blast";
+ path = GlobalSettings::MakeFileName(modelPath, blastFileName.str().c_str());
+ if (QFile::exists(path.c_str()))
+ {
+ 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";
+ path = GlobalSettings::MakeFileName(modelPath, objFileName.str().c_str());
+ if (QFile::exists(path.c_str()))
+ {
+ FbxFileReader rdr;
+ rdr.loadFromFile(path);
+ if (rdr.isCollisionLoaded() == 0)
+ {
+ ASSERT_PRINT(false, "fbx doesn't contain collision geometry");
+ }
+ std::vector<std::vector<CollisionHull> > hulls;
+ rdr.getCollision(hulls);
+
+ /**
+ Create physics meshes;
+ */
+ Nv::Blast::ConvexMeshBuilder collisionBuilder(&cooking, &physics.getPhysicsInsertionCallback());
+ physicsChunks.resize(hulls.size());
+ physicsSubchunks.resize(hulls.size());
+
+ for (uint32_t i = 0; i < hulls.size(); ++i)
+ {
+ for (uint32_t sbHulls = 0; sbHulls < hulls[i].size(); ++sbHulls)
+ {
+ PxConvexMeshGeometry temp = physx::PxConvexMeshGeometry(collisionBuilder.buildConvexMesh(hulls[i][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 < hulls.size(); ++i)
+ {
+ physicsChunks[i].isStatic = false;
+ physicsChunks[i].subchunkCount = (uint32_t)physicsSubchunks[i].size();
+ physicsChunks[i].subchunks = physicsSubchunks[i].data();
+ }
+ }
+ m_pxAsset = ExtPxAsset::create(tkAsset, physicsChunks.data(), (uint32_t)physicsChunks.size());
+ ASSERT_PRINT(m_pxAsset != nullptr, "can't create asset");
+ }
+ }
+ }
}
+BlastAssetModel::BlastAssetModel(ExtPxAsset* pExtPxAsset, BlastModel* pBlastModel, Renderer& renderer)
+ : BlastAsset(renderer)
+{
+ m_pxAsset = pExtPxAsset;
+ ASSERT_PRINT(m_pxAsset != nullptr, "m_pxAsset is nullptr");
+
+ m_model = pBlastModel;
+ ASSERT_PRINT(m_model != nullptr, "m_model is nullptr");
+}
BlastAssetModel::~BlastAssetModel()
{
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModel.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModel.h
index 334c8aa..9e13674 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModel.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModel.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef BLAST_ASSET_MODEL_H
#define BLAST_ASSET_MODEL_H
@@ -26,6 +44,7 @@ namespace Nv
namespace Blast
{
class TkFramework;
+class ExtSerialization;
}
}
@@ -35,7 +54,8 @@ class BlastAssetModel : public BlastAsset
public:
//////// ctor ////////
- BlastAssetModel(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, Renderer& renderer, const char* modelName, const char* modelPath = NULL);
+ BlastAssetModel(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName, const char* modelPath = NULL);
+ BlastAssetModel(ExtPxAsset* pExtPxAsset, BlastModel* pBlastModel, Renderer& renderer);
virtual ~BlastAssetModel();
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSimple.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSimple.cpp
index 56c7441..c3db31d 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSimple.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSimple.cpp
@@ -1,12 +1,29 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
#include "BlastAssetModelSimple.h"
@@ -19,37 +36,38 @@
// BlastAssetModelSimple
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-BlastAssetModelSimple::BlastAssetModelSimple(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, Renderer& renderer, const char* modelName)
- : BlastAssetModel(framework, physics, cooking, renderer, modelName)
+BlastAssetModelSimple::BlastAssetModelSimple(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName)
+ : BlastAssetModel(framework, physics, cooking, serialization, renderer, modelName)
{
- // prepare materials
-// Add By Lixu Begin
- for (const BlastModel::Material& material : getModel().materials)
- {
- if (material.diffuseTexture.empty())
- m_renderMaterials.push_back(RenderMaterial::getDefaultRenderMaterial());
- else
- m_renderMaterials.push_back(new RenderMaterial(material.name.c_str(), renderer.getResourceManager(), "model_simple_textured_ex", material.diffuseTexture.c_str()));
- }
-// Add By Lixu End
- validate();
+ _init(renderer);
}
+BlastAssetModelSimple::BlastAssetModelSimple(ExtPxAsset* pExtPxAsset, BlastModel* pBlastModel, Renderer& renderer)
+ : BlastAssetModel(pExtPxAsset, pBlastModel, renderer)
+{
+ _init(renderer);
+}
BlastAssetModelSimple::~BlastAssetModelSimple()
{
- // release materials
- for (RenderMaterial* r : m_renderMaterials)
+ m_renderMaterialNames.clear();
+}
+
+void BlastAssetModelSimple::_init(Renderer& renderer)
+{
+ for (const BlastModel::Material& material : getModel().materials)
{
- if (r == RenderMaterial::getDefaultRenderMaterial())
+ std::string name = material.name;
+ if (name != "" && !BlastProject::ins().isGraphicsMaterialNameExist(name.c_str()))
{
- continue;
+ BlastProject::ins().addGraphicsMaterial(name.c_str());
+ BlastProject::ins().reloadDiffuseTexture(name.c_str(), material.diffuseTexture.c_str());
+ BlastProject::ins().reloadDiffuseColor(name.c_str(), material.r, material.g, material.b, material.a);
}
- SAFE_DELETE(r);
+ m_renderMaterialNames.push_back(name);
}
}
-
BlastFamilyPtr BlastAssetModelSimple::createFamily(PhysXController& physXConroller, ExtPxManager& pxManager, const ActorDesc& desc)
{
return BlastFamilyPtr(new BlastFamilyModelSimple(physXConroller, pxManager, m_renderer, *this, desc));
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSimple.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSimple.h
index 7e61616..ca3d995 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSimple.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSimple.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef BLAST_ASSET_MODEL_SIMPLE_H
#define BLAST_ASSET_MODEL_SIMPLE_H
@@ -14,14 +32,14 @@
#include "BlastAssetModel.h"
-class RenderMaterial;
class BlastAssetModelSimple : public BlastAssetModel
{
public:
//////// ctor ////////
- BlastAssetModelSimple(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, Renderer& renderer, const char* modelName);
+ BlastAssetModelSimple(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName);
+ BlastAssetModelSimple(ExtPxAsset* pExtPxAsset, BlastModel* pBlastModel, Renderer& renderer);
virtual ~BlastAssetModelSimple();
@@ -32,16 +50,17 @@ public:
//////// data getters ////////
- const std::vector<RenderMaterial*>& getRenderMaterials() const
+ const std::vector<std::string>& getRenderMaterials() const
{
- return m_renderMaterials;
+ return m_renderMaterialNames;
}
private:
//////// private internal data ////////
+ void _init(Renderer& renderer);
- std::vector<RenderMaterial*> m_renderMaterials;
+ std::vector<std::string> m_renderMaterialNames;
};
#endif //BLAST_ASSET_MODEL_SIMPLE_H \ No newline at end of file
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSkinned.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSkinned.cpp
index 5cf3a0d..747c2f4 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSkinned.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSkinned.cpp
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "BlastAssetModelSkinned.h"
#include "BlastFamilyModelSkinned.h"
@@ -14,8 +32,8 @@
#include "Renderer.h"
-BlastAssetModelSkinned::BlastAssetModelSkinned(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, Renderer& renderer, const char* modelName)
- : BlastAssetModel(framework, physics, cooking, renderer, modelName)
+BlastAssetModelSkinned::BlastAssetModelSkinned(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName)
+ : BlastAssetModel(framework, physics, cooking, serialization, renderer, modelName)
{
// Add By Lixu Begin
int index = 0;
@@ -30,7 +48,7 @@ BlastAssetModelSkinned::BlastAssetModelSkinned(TkFramework& framework, PxPhysics
m_renderMaterials.push_back(new RenderMaterial(modelName, renderer.getResourceManager(), "model_skinned_textured", material.diffuseTexture.c_str()));
}
// Add By Lixu End
- validate();
+ initialize();
}
BlastAssetModelSkinned::~BlastAssetModelSkinned()
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSkinned.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSkinned.h
index 149c8e8..e9c6784 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSkinned.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSkinned.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef BLAST_ASSET_MODEL_SKINNED_H
#define BLAST_ASSET_MODEL_SKINNED_H
@@ -20,7 +38,7 @@ class BlastAssetModelSkinned : public BlastAssetModel
public:
//////// ctor ////////
- BlastAssetModelSkinned(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, Renderer& renderer, const char* modelName);
+ BlastAssetModelSkinned(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName);
virtual ~BlastAssetModelSkinned();
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastController.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastController.cpp
index 9cf4d3b..8df665e 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastController.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastController.cpp
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "BlastController.h"
#include "BlastFamily.h"
@@ -18,10 +36,16 @@
#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 "NvBlastExtSerialization.h"
+#include "NvBlastExtTkSerialization.h"
+#include "NvBlastExtPxSerialization.h"
#include "NvBlastTkFramework.h"
@@ -43,65 +67,6 @@
#include "BlastSceneTree.h"
// Add By Lixu End
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// AllocatorCallback
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-class BlastAllocatorCallback : public PxAllocatorCallback
-{
-public:
- virtual void* allocate(size_t size, const char* typeName, const char* filename, int line) override
- {
- NV_UNUSED(typeName);
- NV_UNUSED(filename);
- NV_UNUSED(line);
- return malloc(size);
- }
-
- virtual void deallocate(void* ptr) override
- {
- free(ptr);
- }
-};
-BlastAllocatorCallback g_allocatorCallback;
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// ErrorCallback
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-class BlastErrorCallback : public PxErrorCallback
-{
-public:
- virtual void reportError(PxErrorCode::Enum code, const char* msg, const char* file, int line) override
- {
- std::stringstream str;
- str << "NvBlastTk ";
- bool critical = false;
- switch (code)
- {
- case PxErrorCode::eNO_ERROR: critical = false; break;
- case PxErrorCode::eDEBUG_INFO: str << "[Debug Info]"; critical = false; break;
- case PxErrorCode::eDEBUG_WARNING: str << "[Debug Warning]"; critical = false; break;
- case PxErrorCode::eINVALID_PARAMETER: str << "[Invalid Parameter]"; critical = true; break;
- case PxErrorCode::eINVALID_OPERATION: str << "[Invalid Operation]"; critical = true; break;
- case PxErrorCode::eOUT_OF_MEMORY: str << "[Out of] Memory"; critical = true; break;
- case PxErrorCode::eINTERNAL_ERROR: str << "[Internal Error]"; critical = true; break;
- case PxErrorCode::eABORT: str << "[Abort]"; critical = true; break;
- case PxErrorCode::ePERF_WARNING: str << "[Perf Warning]"; critical = false; break;
- default: PX_ALWAYS_ASSERT();
- }
- str << file << "(" << line << "): " << msg << "\n";
-
- std::string message = str.str();
- shdfnd::printString(message.c_str());
- PX_ASSERT_WITH_MESSAGE(!critical, message.c_str());
- }
-};
-BlastErrorCallback g_errorCallback;
-
-
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Joint creation
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -120,10 +85,9 @@ static physx::PxJoint* createPxJointCallback(ExtPxActor* actor0, const physx::Px
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_impactDamageToStressEnabled(false), m_rigidBodyLimitEnabled(true), m_rigidBodyLimit(40000), m_blastAssetsSize(0), debugRenderScale(0.01f),
+m_taskManager(nullptr), m_extGroupTaskManager(nullptr)
{
- m_extImpactDamageManagerSettings.fragility = 500.0f;
-
m_impactDamageToStressFactor = 0.01f;
m_draggingToStressFactor = 100.0f;
}
@@ -141,17 +105,14 @@ void BlastController::reinitialize()
void BlastController::onSampleStart()
{
- TkFrameworkDesc desc;
- desc.allocatorCallback = &g_allocatorCallback;
- desc.errorCallback = &g_errorCallback;
- m_tkFramework = NvBlastTkFrameworkCreate(desc);
+ m_tkFramework = NvBlastTkFrameworkCreate();
m_replay = new BlastReplay();
- m_taskManager = PxTaskManager::createTaskManager(g_errorCallback, getPhysXController().getCPUDispatcher(), 0);
+ m_taskManager = PxTaskManager::createTaskManager(NvBlastGetPxErrorCallback(), getPhysXController().getCPUDispatcher(), 0);
TkGroupDesc gdesc;
- gdesc.pxTaskManager = m_taskManager;
+ gdesc.workerCount = m_taskManager->getCpuDispatcher()->getWorkerCount();
m_tkGroup = m_tkFramework->createGroup(gdesc);
m_extPxManager = ExtPxManager::create(getPhysXController().getPhysics(), *m_tkFramework, createPxJointCallback);
@@ -159,12 +120,24 @@ void BlastController::onSampleStart()
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();
@@ -177,20 +150,54 @@ void BlastController::onSampleStop()
m_tkFramework->release();
- m_taskManager->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;
+ }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 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;
- getPhysXController().getPhysXScene().setSimulationEventCallback(m_impactDamageEnabled ? m_eventCallback : nullptr);
- refreshImpactDamageSettings();
+ m_impactDamageUpdatePending = true;
}
}
@@ -206,8 +213,8 @@ bool BlastController::stressDamage(ExtPxActor *actor, physx::PxVec3 position, ph
void* userData = actor->getFamily().userData;
if (userData)
{
- ExtStressSolver* solver = reinterpret_cast<ExtStressSolver*>(userData);
- solver->applyImpulse(*actor, position, force * m_impactDamageToStressFactor);
+ ExtPxStressSolver* solver = reinterpret_cast<ExtPxStressSolver*>(userData);
+ solver->getSolver().addForce(*actor->getTkActor().getActorLL(), position, force * m_impactDamageToStressFactor);
return true;
}
}
@@ -222,6 +229,78 @@ void BlastController::refreshImpactDamageSettings()
m_extImpactDamageManager->setSettings(m_extImpactDamageManagerSettings);
}
+// Add By Lixu Begin
+BlastFamily* BlastController::getFamilyByPxActor(const PxActor& actor)
+{
+ for (BlastFamilyPtr family : m_families)
+ {
+ if (family->find(actor))
+ {
+ return family;
+ }
+ }
+ return nullptr;
+}
+
+std::vector<PxActor*> BlastController::getActor(BlastAsset* asset, int chunkId)
+{
+ std::vector<PxActor*> actors;
+ for (BlastFamilyPtr family : m_families)
+ {
+ if (&(family->getBlastAsset()) == asset)
+ {
+ PxActor* actor = nullptr;
+ family->getPxActorByChunkIndex(chunkId, &actor);
+ if (actor)
+ actors.push_back(actor);
+ }
+ }
+ return actors;
+}
+
+void BlastController::updateActorRenderableTransform(const PxActor& actor, physx::PxTransform& pos, bool local)
+{
+ BlastFamily* family = getFamilyByPxActor(actor);
+ if (family == nullptr)
+ return;
+
+ family->updateActorRenderableTransform(actor, pos, local);
+}
+
+bool BlastController::isActorVisible(const PxActor& actor)
+{
+ BlastFamily* family = getFamilyByPxActor(actor);
+ if (family == nullptr)
+ return false;
+
+ return family->isActorVisible(actor);
+}
+
+bool BlastController::isAssetFractrued(const PxActor& actor)
+{
+ BlastFamily* family = getFamilyByPxActor(actor);
+ if (family == nullptr)
+ return false;
+
+ const BlastAsset& asset = family->getBlastAsset();
+ if (asset.getChunkIndexesByDepth(1).size() > 0)
+ {
+ return true;
+ }
+
+ return false;
+}
+
+void BlastController::updateModelMeshToProjectParam(const PxActor& actor)
+{
+ BlastFamily* family = getFamilyByPxActor(actor);
+ if (family == nullptr)
+ return;
+
+ const BlastAsset& asset = family->getBlastAsset();
+ SampleManager::ins()->updateModelMeshToProjectParam(const_cast<BlastAsset*>(&asset));
+}
+// Add By Lixu End
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Stress
@@ -239,11 +318,11 @@ void BlastController::updateDraggingStress()
void* userData = pxActor->getFamily().userData;
if (userData)
{
- ExtStressSolver* solver = reinterpret_cast<ExtStressSolver*>(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->applyImpulse(*pxActor, physxController.getDragActorHookLocalPoint(), dragVector.getNormalized() * factor);
+ solver->getSolver().addForce(*pxActor->getTkActor().getActorLL(), physxController.getDragActorHookLocalPoint(), dragVector.getNormalized() * factor);
}
}
}
@@ -300,7 +379,11 @@ void BlastController::Animate(double dt)
updateDraggingStress();
- m_replay->update();
+ fillDebugRender();
+
+ getPhysXController().simualtionSyncEnd();
+
+ updateImpactDamage();
Time blastTime;
for (uint32_t i = 0; i < m_families.size(); ++i)
@@ -311,13 +394,25 @@ void BlastController::Animate(double dt)
}
}
- fillDebugRender();
+ 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();
- m_tkGroup->sync(true);
+
+#endif
+
PROFILER_END();
+ getPhysXController().simulationBegin(dt);
+
TkGroupStats gstats;
m_tkGroup->getStats(gstats);
@@ -365,7 +460,8 @@ void BlastController::Animate(double dt)
if (needUpdateUI)
{
- pBlastSceneTree->updateValues(false);
+ //pBlastSceneTree->updateValues(false);
+ SampleManager::ins()->m_bNeedRefreshTree = true;
}
// Add By Lixu End
}
@@ -379,15 +475,20 @@ void BlastController::drawUI()
{
setImpactDamageEnabled(impactEnabled);
}
-
- if (ImGui::DragFloat("Fragility", &m_extImpactDamageManagerSettings.fragility))
- {
- refreshImpactDamageSettings();
- }
-
- if (ImGui::Checkbox("Impact Damage To Stress Solver", &m_impactDamageToStressEnabled))
{
- refreshImpactDamageSettings();
+ bool refresh = false;
+ refresh |= ImGui::Checkbox("Use Shear Damage", &m_extImpactDamageManagerSettings.shearDamage);
+ refresh |= ImGui::DragFloat("Impulse Threshold (Min)", &m_extImpactDamageManagerSettings.impulseMinThreshold);
+ refresh |= ImGui::DragFloat("Impulse Threshold (Max)", &m_extImpactDamageManagerSettings.impulseMaxThreshold);
+ refresh |= ImGui::DragFloat("Damage (Max)", &m_extImpactDamageManagerSettings.damageMax);
+ refresh |= ImGui::DragFloat("Damage Radius (Max)", &m_extImpactDamageManagerSettings.damageRadiusMax);
+ refresh |= ImGui::DragFloat("Damage Attenuation", &m_extImpactDamageManagerSettings.damageAttenuation, 1.0f, 0.0f, 1.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");
@@ -435,45 +536,8 @@ void BlastController::removeAllFamilies()
m_replay->reset();
}
-// Add By Lixu Begin
-#include "SceneController.h"
-// Add By Lixu End
void BlastController::recalculateAssetsSize()
{
-
-// Add By Lixu Begin
- std::map<BlastAsset*, std::vector<BlastFamily*>>& AssetFamiliesMap = getManager()->getAssetFamiliesMap();
- std::map<BlastAsset*, AssetList::ModelAsset>& AssetDescMap = getManager()->getAssetDescMap();
- std::map<BlastAsset*, std::vector<BlastFamily*>>::iterator it;
- for (it = AssetFamiliesMap.begin(); it != AssetFamiliesMap.end(); it++)
- {
- std::vector<BlastFamily*>& fs = it->second;
- fs.clear();
- }
- AssetFamiliesMap.clear();
- AssetDescMap.clear();
-
- SceneController& sceneController = getManager()->getSceneController();
- int familiesSize = m_families.size();
- for (int i = 0; i < familiesSize; i++)
- {
- BlastFamilyPtr pBlastFamily = m_families[i];
- BlastAsset* pBlastAsset = (BlastAsset*)&pBlastFamily->getBlastAsset();
- AssetFamiliesMap[pBlastAsset].push_back(&*m_families[i]);
- if (AssetDescMap.find(pBlastAsset) == AssetDescMap.end())
- {
- AssetList::ModelAsset desc;
- if (sceneController.GetAssetDesc(pBlastAsset, desc))
- {
- AssetDescMap[pBlastAsset] = desc;
- }
- }
-
- AssetList::ModelAsset& m = AssetDescMap[pBlastAsset];
- pBlastFamily->initTransform(m.transform);
- }
-// Add By Lixu End
-
std::set<const BlastAsset*> uniquedAssets;
m_blastAssetsSize = 0;
for (uint32_t i = 0; i < m_families.size(); ++i)
@@ -486,40 +550,19 @@ void BlastController::recalculateAssetsSize()
}
}
-void BlastController::blast(PxVec3 worldPos, float damageRadius, float explosiveImpulse, std::function<void(ExtPxActor*)> damageFunction)
+bool BlastController::overlap(const PxGeometry& geometry, const PxTransform& pose, std::function<void(ExtPxActor*)> hitCall)
{
PROFILER_SCOPED_FUNCTION();
+ bool anyHit = false;
for (uint32_t i = 0; i < m_families.size(); ++i)
{
if (m_families[i])
{
- m_families[i]->blast(worldPos, damageRadius, explosiveImpulse, damageFunction);
+ anyHit |= m_families[i]->overlap(geometry, pose, hitCall);
}
}
-}
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// context/log
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-void BlastController::blastLog(int type, const char* msg, const char* file, int line)
-{
- std::stringstream str;
- bool critical = false;
- switch (type)
- {
- case NvBlastMessage::Error: str << "[NvBlast ERROR] "; critical = true; break;
- case NvBlastMessage::Warning: str << "[NvBlast WARNING] "; critical = true; break;
- case NvBlastMessage::Info: str << "[NvBlast INFO] "; critical = false; break;
- case NvBlastMessage::Debug: str << "[NvBlast DEBUG] "; critical = false; break;
- }
- str << file << "(" << line << "): " << msg << "\n";
-
- std::string message = str.str();
- shdfnd::printString(message.c_str());
- PX_ASSERT_WITH_MESSAGE(!critical, message.c_str());
+ return anyHit;
}
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastController.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastController.h
index 98f5c24..5e4d269 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastController.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastController.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef BLAST_CONTROLLER_H
#define BLAST_CONTROLLER_H
@@ -31,6 +49,8 @@ namespace Nv
namespace Blast
{
class TkFramework;
+class ExtGroupTaskManager;
+class ExtSerialization;
}
}
@@ -68,7 +88,7 @@ public:
//////// public API ////////
- void blast(PxVec3 worldPos, float damageRadius, float explosiveImpulse, std::function<void(ExtPxActor*)> damageFunction);
+ bool overlap(const PxGeometry& geometry, const PxTransform& pose, std::function<void(ExtPxActor*)> hitCall);
bool stressDamage(ExtPxActor *actor, PxVec3 position, PxVec3 force);
@@ -77,11 +97,6 @@ public:
void removeAllFamilies();
- //////// public static ////////
-
- static void blastLog(int type, const char* msg, const char* file, int line);
-
-
//////// public getters/setters ////////
TkFramework& getTkFramework() const
@@ -142,10 +157,29 @@ public:
{
return m_families;
}
+
+ BlastFamily* getFamilyByPxActor(const PxActor& actor);
+ std::vector<PxActor*> getActor(BlastAsset* asset, int chunkId);
+
+ void updateActorRenderableTransform(const PxActor& actor, physx::PxTransform& pos, bool local = false);
+
+ bool isActorVisible(const PxActor& actor);
+
+ bool isAssetFractrued(const PxActor& actor);
+
+ // only update unfractured mode mesh
+ void updateModelMeshToProjectParam(const PxActor& actor);
// Add By Lixu End
float getLastStressDelta() const;
+ void notifyPhysXControllerRelease();
+
+ ExtSerialization* getExtSerialization() const
+ {
+ return m_extSerialization;
+ }
+
//////// public variables for UI ////////
BlastFamily::DebugRenderMode debugRenderMode;
@@ -190,6 +224,8 @@ private:
void updateDraggingStress();
+ void updateImpactDamage();
+
void refreshImpactDamageSettings();
void fillDebugRender();
@@ -222,11 +258,14 @@ private:
ExtImpactSettings m_extImpactDamageManagerSettings;
EventCallback* m_eventCallback;
ExtStressSolverSettings m_extStressSolverSettings;
+ ExtGroupTaskManager* m_extGroupTaskManager;
+ ExtSerialization* m_extSerialization;
std::vector<BlastFamilyPtr> m_families;
DebugRenderBuffer m_debugRenderBuffer;
bool m_impactDamageEnabled;
+ bool m_impactDamageUpdatePending;
bool m_impactDamageToStressEnabled;
float m_impactDamageToStressFactor;
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamily.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamily.cpp
index f947cbd..b5afc82 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamily.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamily.cpp
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "BlastFamily.h"
#include "SampleProfiler.h"
@@ -28,12 +46,13 @@
#include "PxRigidDynamic.h"
#include "PxScene.h"
#include "PxJoint.h"
+// Add By Lixu Begin
+#include "BlastSceneTree.h"
+// Add By Lixu End
const float RIGIDBODY_DENSITY = 2000.0f;
-const float BlastFamily::BOND_HEALTH_MAX = 1.0f;
-
BlastFamily::BlastFamily(PhysXController& physXController, ExtPxManager& pxManager, const BlastAsset& blastAsset)
: m_physXController(physXController)
, m_pxManager(pxManager)
@@ -41,11 +60,10 @@ BlastFamily::BlastFamily(PhysXController& physXController, ExtPxManager& pxManag
, m_listener(this)
, m_totalVisibleChunkCount(0)
, m_stressSolver(nullptr)
+ , m_spawned(false)
{
m_settings.stressSolverEnabled = false;
m_settings.stressDamageEnabled = false;
-
- m_settings.material = { 3.0f, 0.1f, 0.2f, 1.5f + 1e-5f, 0.95f };;
}
BlastFamily::~BlastFamily()
@@ -62,11 +80,44 @@ BlastFamily::~BlastFamily()
void BlastFamily::initialize(const BlastAsset::ActorDesc& desc)
{
+// Add By Lixu Begin
+ BPPBlast& blast = BlastProject::ins().getParams().blast;
+ BPPBondArray& bonds = blast.bonds;
+ BlastTreeData& blastTreeData = BlastTreeData::ins();
+
+ std::vector<float> BondHealths;
+ BlastAsset* pThis = (BlastAsset*)&m_blastAsset;
+ SampleManager* pSampleManager = SampleManager::ins();
+ std::map<BlastAsset*, AssetList::ModelAsset>& AssetDescMap = pSampleManager->getAssetDescMap();
+ AssetList::ModelAsset m = AssetDescMap[pThis];
+ int assetID = BlastProject::ins().getAssetIDByName(m.name.c_str());
+
+ for (int bc = 0; bc < bonds.arraySizes[0]; bc++)
+ {
+ BPPBond& bond = bonds.buf[bc];
+ if (bond.asset == assetID)
+ {
+ BondHealths.push_back(bond.support.bondStrength);
+ }
+ }
+
+ const ExtPxAsset* pExtPxAsset = m_blastAsset.getPxAsset();
+ const TkAsset& tkAsset = pExtPxAsset->getTkAsset();
+ uint32_t bondCount = tkAsset.getBondCount();
+
+ const float* pBondHealths = nullptr;
+ if (bondCount == BondHealths.size())
+ {
+ pBondHealths = BondHealths.data();
+ }
+
+ const NvBlastActorDesc& defaultActorDesc = m_blastAsset.getPxAsset()->getDefaultActorDesc();
+ NvBlastActorDesc newActorDesc = defaultActorDesc;
+ newActorDesc.initialBondHealths = pBondHealths;
+// Add By Lixu End
+
ExtPxFamilyDesc familyDesc;
- familyDesc.actorDesc.initialBondHealths = nullptr;
- familyDesc.actorDesc.initialSupportChunkHealths = nullptr;
- familyDesc.actorDesc.uniformInitialBondHealth = BOND_HEALTH_MAX;
- familyDesc.actorDesc.uniformInitialLowerSupportChunkHealth = 1.0f;
+ familyDesc.actorDesc = (const NvBlastActorDesc*)&newActorDesc; // 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);
@@ -79,28 +130,27 @@ void BlastFamily::initialize(const BlastAsset::ActorDesc& desc)
m_pxFamily->subscribe(m_listener);
- ExtPxSpawnSettings spawnSettings = {
- &m_physXController.getPhysXScene(),
- m_physXController.getDefaultMaterial(),
- RIGIDBODY_DENSITY
- };
- m_pxFamily->spawn(desc.transform, PxVec3(1.0f), spawnSettings);
+ m_initialTransform = desc.transform;
- reloadStressSolver();
+ updatePreSplit(0);
+ m_VisibleChangedChunks.clear();
}
void BlastFamily::updatePreSplit(float dt)
{
- PROFILER_BEGIN("Stress Solver");
- // update stress
- m_stressSolveTime = 0;
- if (m_stressSolver)
+ if (!m_spawned)
{
- Time t;
- m_stressSolver->update(m_settings.stressDamageEnabled);
- m_stressSolveTime += t.getElapsedSeconds();
+ ExtPxSpawnSettings spawnSettings = {
+ &m_physXController.getPhysXScene(),
+ m_physXController.getDefaultMaterial(),
+ RIGIDBODY_DENSITY
+ };
+
+ m_pxFamily->spawn(m_initialTransform, PxVec3(1.0f), spawnSettings);
+ reloadStressSolver();
+
+ m_spawned = true;
}
- PROFILER_END();
// collect potential actors to health update
m_actorsToUpdateHealth.clear();
@@ -128,6 +178,17 @@ void BlastFamily::updateAfterSplit(float dt)
}
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();
@@ -173,11 +234,9 @@ void BlastFamily::drawUI()
// Blast Material
ImGui::Spacing();
ImGui::Text("Blast Material:");
- ImGui::DragFloat("singleChunkThreshold", &m_settings.material.singleChunkThreshold);
- ImGui::DragFloat("graphChunkThreshold", &m_settings.material.graphChunkThreshold);
- ImGui::DragFloat("bondNormalThreshold", &m_settings.material.bondNormalThreshold);
- ImGui::DragFloat("bondTangentialThreshold", &m_settings.material.bondTangentialThreshold);
- ImGui::DragFloat("damageAttenuation", &m_settings.material.damageAttenuation);
+ 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);
ImGui::Spacing();
@@ -193,8 +252,9 @@ void BlastFamily::drawUI()
bool changed = false;
changed |= ImGui::DragInt("Bond Iterations Per Frame", (int*)&m_settings.stressSolverSettings.bondIterationsPerFrame, 100, 0, 500000);
- changed |= ImGui::DragFloat("Stress Linear Factor", &m_settings.stressSolverSettings.stressLinearFactor, 0.00001f, 0.0f, 10.0f, "%.6f");
- changed |= ImGui::DragFloat("Stress Angular Factor", &m_settings.stressSolverSettings.stressAngularFactor, 0.00001f, 0.0f, 10.0f, "%.6f");
+ 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)
{
@@ -213,22 +273,22 @@ void BlastFamily::drawUI()
void BlastFamily::drawStatsUI()
{
ImGui::PushStyleColor(ImGuiCol_Text, ImColor(10, 255, 10, 255));
- const ExtStressSolver* stressSolver = m_stressSolver;
- if (stressSolver)
+ if (m_stressSolver)
{
- const float errorLinear = stressSolver->getStressErrorLinear();
- const float errorAngular = stressSolver->getStressErrorAngular();
+ 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 Iterations: %d (+%d)", stressSolver->getIterationCount(), stressSolver->getIterationsPerFrame());
- ImGui::Text("Stress Frames: %d", stressSolver->getFrameCount());
+ 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 = stressSolver.getFrameCount() <= 1 ? 1.0f : scale;
scale = std::max<float>(scale, errorLinear);
scale = std::max<float>(scale, errorAngular);
@@ -263,19 +323,24 @@ void BlastFamily::setSettings(const Settings& settings)
}
m_tkFamily->setMaterial(&m_settings.material);
+ initTransform(m_settings.transform);
+ m_initialTransform = m_settings.transform;
}
void BlastFamily::refreshStressSolverSettings()
{
if (m_stressSolver)
{
- m_stressSolver->setSettings(m_settings.stressSolverSettings);
+ m_stressSolver->getSolver().setSettings(m_settings.stressSolverSettings);
}
}
void BlastFamily::resetStress()
{
- m_stressSolver->reset();
+ if (m_stressSolver)
+ {
+ m_stressSolver->getSolver().reset();
+ }
}
void BlastFamily::reloadStressSolver()
@@ -288,7 +353,7 @@ void BlastFamily::reloadStressSolver()
if (m_settings.stressSolverEnabled)
{
- m_stressSolver = ExtStressSolver::create(*m_pxFamily, m_settings.stressSolverSettings);
+ m_stressSolver = ExtPxStressSolver::create(*m_pxFamily, m_settings.stressSolverSettings);
m_pxFamily->userData = m_stressSolver;
}
}
@@ -351,6 +416,8 @@ void BlastFamily::fillDebugRender(DebugRenderBuffer& debugRenderBuffer, DebugRen
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)
{
@@ -361,7 +428,7 @@ void BlastFamily::fillDebugRender(DebugRenderBuffer& debugRenderBuffer, DebugRen
if (nodeCount == 0) // subsupport chunks don't have graph nodes
continue;
- std::vector<uint32_t> nodes(actor.getGraphNodeCount());
+ 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)
@@ -385,11 +452,11 @@ void BlastFamily::fillDebugRender(DebugRenderBuffer& debugRenderBuffer, DebugRen
if (node0 > node1)
continue;
- bool invisibleBond = assetChunk0.subchunkCount == 0 || assetChunk1.subchunkCount == 0;
+ bool invisibleBond = chunkIndex0 >= chunkCount || chunkIndex1 >= chunkCount || assetChunk0.subchunkCount == 0 || assetChunk1.subchunkCount == 0;
// health
uint32_t bondIndex = graph.adjacentBondIndices[adjacencyIndex];
- float healthVal = PxClamp(bondHealths[bondIndex] / BOND_HEALTH_MAX, 0.0f, 1.0f);
+ float healthVal = PxClamp(bondHealths[bondIndex] / bondHealthMax, 0.0f, 1.0f);
DirectX::XMFLOAT4 color = bondHealthColor(healthVal);
@@ -419,7 +486,12 @@ void BlastFamily::fillDebugRender(DebugRenderBuffer& debugRenderBuffer, DebugRen
{
if (m_stressSolver)
{
- m_stressSolver->fillDebugRender(nodes, debugRenderBuffer.m_lines, (ExtStressSolver::DebugRenderMode)(mode - DEBUG_RENDER_STRESS_GRAPH), renderScale);
+ 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);
+ }
}
}
@@ -497,7 +569,7 @@ private:
PxOverlapHit m_hitBuffer[1000];
};
-void BlastFamily::blast(PxVec3 worldPos, float damageRadius, float explosiveImpulse, std::function<void(ExtPxActor*)> damageFunction)
+bool BlastFamily::overlap(const PxGeometry& geometry, const PxTransform& pose, std::function<void(ExtPxActor*)> hitCall)
{
// Add By Lixu Begin
const ExtPxAsset* pExtPxAsset = m_blastAsset.getPxAsset();
@@ -505,14 +577,14 @@ void BlastFamily::blast(PxVec3 worldPos, float damageRadius, float explosiveImpu
uint32_t bondCount = tkAsset.getBondCount();
if (bondCount == 0)
{
- return;
+ return false;
}
// Add By Lixu End
std::set<ExtPxActor*> actorsToDamage;
#if 1
BlastOverlapCallback overlapCallback(m_pxManager, actorsToDamage);
- m_physXController.getPhysXScene().overlap(PxSphereGeometry(damageRadius), PxTransform(worldPos), overlapCallback);
+ m_physXController.getPhysXScene().overlap(geometry, pose, overlapCallback);
#else
for (std::map<NvBlastActor*, PhysXController::Actor*>::iterator it = m_actorsMap.begin(); it != m_actorsMap.end(); it++)
{
@@ -522,67 +594,9 @@ void BlastFamily::blast(PxVec3 worldPos, float damageRadius, float explosiveImpu
for (auto actor : actorsToDamage)
{
- damageFunction(actor);
- }
-
- if (explosiveImpulse > 0.0f)
- {
- explode(worldPos, damageRadius, explosiveImpulse);
- }
-}
-
-
-class ExplodeOverlapCallback : public PxOverlapCallback
-{
-public:
- ExplodeOverlapCallback(PxVec3 worldPos, float radius, float explosiveImpulse)
- : m_worldPos(worldPos)
- , m_radius(radius)
- , m_explosiveImpulse(explosiveImpulse)
- , PxOverlapCallback(m_hitBuffer, sizeof(m_hitBuffer) / sizeof(m_hitBuffer[0])) {}
-
- PxAgain processTouches(const PxOverlapHit* buffer, PxU32 nbHits)
- {
- for (PxU32 i = 0; i < nbHits; ++i)
- {
- PxRigidActor* actor = buffer[i].actor;
- PxRigidDynamic* rigidDynamic = actor->is<PxRigidDynamic>();
- if (rigidDynamic && !(rigidDynamic->getRigidBodyFlags() & PxRigidBodyFlag::eKINEMATIC))
- {
- if (m_actorBuffer.find(rigidDynamic) == m_actorBuffer.end())
- {
- m_actorBuffer.insert(rigidDynamic);
- PxVec3 dr = rigidDynamic->getGlobalPose().transform(rigidDynamic->getCMassLocalPose()).p - m_worldPos;
- float distance = dr.magnitude();
- float factor = PxClamp(1.0f - (distance * distance) / (m_radius * m_radius), 0.0f, 1.0f);
- float impulse = factor * m_explosiveImpulse * RIGIDBODY_DENSITY;
- PxVec3 vel = dr.getNormalized() * impulse / rigidDynamic->getMass();
- rigidDynamic->setLinearVelocity(rigidDynamic->getLinearVelocity() + vel);
- }
- }
- }
- return true;
+ hitCall(actor);
}
-private:
- PxOverlapHit m_hitBuffer[1000];
- float m_explosiveImpulse;
- std::set<PxRigidDynamic*> m_actorBuffer;
- PxVec3 m_worldPos;
- float m_radius;
-};
-
-void BlastFamily::explode(PxVec3 worldPos, float damageRadius, float explosiveImpulse)
-{
- ExplodeOverlapCallback overlapCallback(worldPos, damageRadius, explosiveImpulse);
- m_physXController.getPhysXScene().overlap(PxSphereGeometry(damageRadius), PxTransform(worldPos), overlapCallback);
-
+ return !actorsToDamage.empty();
}
-// Add By Lixu Begin
-bool BlastFamily::find(ExtPxActor* actor)
-{
- std::set<ExtPxActor*>::iterator it = m_actors.find(actor);
- return it != m_actors.end();
-}
-// Add By Lixu End
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamily.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamily.h
index b4611a9..356e0c5 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamily.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamily.h
@@ -1,19 +1,37 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef BLAST_FAMILY_H
#define BLAST_FAMILY_H
#include "BlastAsset.h"
#include "NvBlastExtPxListener.h"
-#include "NvBlastExtStressSolver.h"
+#include "NvBlastExtPxStressSolver.h"
#include "NvBlastExtDamageShaders.h"
#include <functional>
#include <set>
@@ -23,6 +41,11 @@
class DebugRenderBuffer;
// Add By Lixu Begin
class RenderMaterial;
+namespace physx
+{
+ class PxActor;
+}
+using namespace physx;
// Add By Lixu End
namespace Nv
@@ -34,6 +57,13 @@ 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.
@@ -45,8 +75,7 @@ public:
//////// public API ////////
- void blast(PxVec3 worldPos, float damageRadius, float explosiveImpulse, std::function<void(ExtPxActor*)> damageFunction);
- void explode(PxVec3 worldPos, float damageRadius, float explosiveImpulse);
+ bool overlap(const PxGeometry& geometry, const PxTransform& pose, std::function<void(ExtPxActor*)> hitCall);
void updatePreSplit(float dt);
void updateAfterSplit(float dt);
@@ -55,22 +84,29 @@ public:
void drawStatsUI();
// Add By Lixu Begin
- bool find(ExtPxActor* actor);
- virtual void setActorSelected(const ExtPxActor& actor, bool selected) {}
+ virtual bool find(const PxActor& actor) { return false; }
+ virtual void updateActorRenderableTransform(const PxActor& actor, PxTransform& pos, bool local) {}
+ virtual uint32_t getChunkIndexByPxActor(const PxActor& actor) { return -1; }
+ virtual bool getPxActorByChunkIndex(uint32_t chunkIndex, PxActor** ppActor) { return false; }
+ virtual void setActorSelected(const PxActor& actor, bool selected) {}
+ virtual bool isActorSelected(const PxActor& actor) { return false; }
+ virtual void setActorVisible(const PxActor& actor, bool visible) {}
+ virtual bool isActorVisible(const PxActor& actor) { return false; }
virtual std::vector<uint32_t> getSelectedChunks() { return std::vector<uint32_t>(); }
virtual void clearChunksSelected() {}
virtual void setChunkSelected(uint32_t chunk, bool selected) {}
virtual void setChunkSelected(std::vector<uint32_t> depths, bool selected) {}
- virtual bool getChunkSelected(uint32_t chunk) { return false; }
- virtual void setActorScale(const ExtPxActor& actor, PxMat44& scale, bool replace) {}
+ virtual bool isChunkSelected(uint32_t chunk) { return false; }
+ virtual void setActorScale(const PxActor& actor, PxMat44& scale, bool replace) {}
virtual bool isChunkVisible(uint32_t chunkIndex) { return false; }
virtual void setChunkVisible(uint32_t chunkIndex, bool bVisible) {}
virtual void setChunkVisible(std::vector<uint32_t> depths, bool bVisible) {}
- virtual void initTransform(physx::PxTransform t) {}
+ virtual void initTransform(physx::PxTransform t) { m_settings.transform = t; }
std::map<uint32_t, bool>& getVisibleChangedChunks() { return m_VisibleChangedChunks; }
void clearVisibleChangedChunks() { m_VisibleChangedChunks.clear(); }
virtual void getMaterial(RenderMaterial** ppRenderMaterial, bool externalSurface) {}
virtual void setMaterial(RenderMaterial* pRenderMaterial, bool externalSurface) {}
+ virtual void highlightChunks() {}
// Add By Lixu End
enum DebugRenderMode
@@ -122,11 +158,6 @@ public:
void reloadStressSolver();
- //////// consts ////////
-
- static const float BOND_HEALTH_MAX;
-
-
//////// settings ////////
struct Settings
@@ -135,6 +166,7 @@ public:
ExtStressSolverSettings stressSolverSettings;
bool stressDamageEnabled;
NvBlastExtMaterial material;
+ physx::PxTransform transform;
};
void setSettings(const Settings& settings);
@@ -171,7 +203,7 @@ protected:
//////// protected data ////////
PhysXController& m_physXController;
- ExtPxManager& m_pxManager;
+ ExtPxManager& m_pxManager;
const BlastAsset& m_blastAsset;
std::map<uint32_t, bool> m_VisibleChangedChunks;
@@ -209,15 +241,20 @@ private:
//////// private data ////////
TkFamily* m_tkFamily;
- ExtPxFamily* m_pxFamily;
- PxManagerListener m_listener;
+ ExtPxFamily* m_pxFamily;
+ PxManagerListener m_listener;
Settings m_settings;
+ PxTransform m_initialTransform;
+ bool m_spawned;
size_t m_familySize;
uint32_t m_totalVisibleChunkCount;
- ExtStressSolver* m_stressSolver;
+ ExtPxStressSolver* m_stressSolver;
double m_stressSolveTime;
- std::set<ExtPxActor*> m_actors;
- std::set<const ExtPxActor*> m_actorsToUpdateHealth;
+ std::set<const ExtPxActor*> m_actorsToUpdateHealth;
+ // Add By Lixu Begin
+protected:
+ std::set<ExtPxActor*> m_actors;
+ // Add By Lixu End
};
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyBoxes.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyBoxes.cpp
index e8b7b27..7011612 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyBoxes.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyBoxes.cpp
@@ -1,12 +1,29 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
#include "BlastFamilyBoxes.h"
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyBoxes.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyBoxes.h
index 1f70451..b67ec31 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyBoxes.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyBoxes.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef BLAST_FAMILY_BOXES
#define BLAST_FAMILY_BOXES
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSimple.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSimple.cpp
index e692547..01559da 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSimple.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSimple.cpp
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "BlastFamilyModelSimple.h"
#include "RenderUtils.h"
@@ -19,8 +37,119 @@
#include "PxRigidDynamic.h"
#include "MaterialLibraryPanel.h"
+// Add By Lixu Begin
+#include "NvBlastExtPxManager.h"
+#include "SceneController.h"
+#include "PhysXController.h"
+#include "SampleManager.h"
+#include "BlastModel.h"
+#include "PxPhysics.h"
+#include "PxScene.h"
+#include "GizmoToolController.h"
+// Add By Lixu End
+
using namespace physx;
+#include "ViewerOutput.h"
+// print out all shapes for debug purpose. check actor/shape releasing.
+void PrintActors(PhysXController& physXController)
+{
+ PxPhysics& physx = physXController.getPhysics();
+ static int convexNum = 0, shapeNum = 0;
+ int convexNumNew = physx.getNbConvexMeshes();
+ int shapeNumNew = physx.getNbShapes();
+ if (shapeNum != shapeNumNew && shapeNumNew > 0)
+ {
+ // print shapes
+ std::vector<PxShape*> shapes(shapeNumNew);
+ physx.getShapes(shapes.data(), shapeNumNew);
+ shapeNum = shapeNumNew;
+ for (PxU32 u = 0; u < shapeNumNew; ++u)
+ {
+ PxShape& shape = *shapes[u];
+ PxRigidActor* pActor = shape.getActor();
+ const char* pName = pActor ? pActor->getName() : nullptr;
+ char buf[256];
+ if (pName)
+ {
+ sprintf(buf, "Actor %x shape %x %s", pActor, &shape, pName);
+ }
+ else
+ {
+ sprintf(buf, "Actor %x shape %x", pActor, &shape);
+ }
+ viewer_msg(buf);
+ }
+ }
+}
+
+// only modify unfractured mode mesh
+void modifyModelByLocalWay(BlastModel& model, PxTransform& gp_old, PxTransform& gp_new)
+{
+ BlastModel::Chunk& chunk = model.chunks[0];//unfracture model only has one chunk
+
+ std::vector<BlastModel::Chunk::Mesh>& meshes = chunk.meshes;
+ int meshSize = meshes.size();
+
+ if (meshSize == 0)
+ {
+ return;
+ }
+
+ PxTransform gp_newInv = gp_new.getInverse();
+ for (int ms = 0; ms < meshSize; ms++)
+ {
+ BlastModel::Chunk::Mesh& mesh = meshes[ms];
+ SimpleMesh& simpleMesh = mesh.mesh;
+ std::vector<SimpleMesh::Vertex>& vertices = simpleMesh.vertices;
+
+ int NumVertices = vertices.size();
+ for (uint32_t i = 0; i < NumVertices; ++i)
+ {
+ PxTransform v_old(vertices[i].position);
+ PxTransform v_new = gp_newInv * gp_old * v_old;
+ physx::PxVec3 pos = v_new.p;
+
+ SimpleMesh::Vertex& vertex = vertices[i];
+ vertex.position.x = pos.x;
+ vertex.position.y = pos.y;
+ vertex.position.z = pos.z;
+ }
+ }
+}
+
+
+void scaleModel(BlastModel& model, PxMat44& scale)
+{
+ BlastModel::Chunk& chunk = model.chunks[0];//unfracture model only has one chunk
+
+ std::vector<BlastModel::Chunk::Mesh>& meshes = chunk.meshes;
+ int meshSize = meshes.size();
+
+ if (meshSize == 0)
+ {
+ return;
+ }
+
+ for (int ms = 0; ms < meshSize; ms++)
+ {
+ BlastModel::Chunk::Mesh& mesh = meshes[ms];
+ SimpleMesh& simpleMesh = mesh.mesh;
+ std::vector<SimpleMesh::Vertex>& vertices = simpleMesh.vertices;
+
+ int NumVertices = vertices.size();
+ for (uint32_t i = 0; i < NumVertices; ++i)
+ {
+ SimpleMesh::Vertex& vertex = vertices[i];
+ physx::PxVec3 pos = scale.transform(vertices[i].position);
+
+ vertex.position.x = pos.x;
+ vertex.position.y = pos.y;
+ vertex.position.z = pos.z;
+ }
+ }
+}
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SimpleRenderMesh
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -34,7 +163,8 @@ public:
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({ "TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 });
+ m_inputDesc.push_back({ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 36, 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());
@@ -200,10 +330,20 @@ private:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// BlastFamilyModelSimple
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
BlastFamilyModelSimple::BlastFamilyModelSimple(PhysXController& physXController, ExtPxManager& pxManager, Renderer& renderer, const BlastAssetModelSimple& blastAsset, const BlastAsset::ActorDesc& desc)
: BlastFamily(physXController, pxManager, blastAsset), m_renderer(renderer)
{
+ // Add By Lixu Begin
+ SampleManager* pSampleManager = SampleManager::ins();
+ std::map<BlastAsset*, std::vector<BlastFamily*>>& AssetFamiliesMap = pSampleManager->getAssetFamiliesMap();
+ std::map<BlastAsset*, AssetList::ModelAsset>& AssetDescMap = pSampleManager->getAssetDescMap();
+
+ BlastAsset* pBlastAsset = (BlastAsset*)&getBlastAsset();
+ AssetFamiliesMap[pBlastAsset].push_back(this);
+
+ AssetList::ModelAsset& m = AssetDescMap[pBlastAsset];
+ // Add By Lixu End
+
// materials
auto materials = blastAsset.getRenderMaterials();
@@ -223,6 +363,10 @@ BlastFamilyModelSimple::BlastFamilyModelSimple(PhysXController& physXController,
ex_Renderables.clear();
std::vector<Renderable*>& in_Renderables = m_chunks[chunkIndex].in_Renderables;
in_Renderables.clear();
+
+ PxActor* actor = pSampleManager->getPhysXController().createEditPhysXActor(meshes, desc.transform);
+ m_editActorChunkMap.insert(std::make_pair(actor, chunkIndex));
+ m_chunkEditActorMap.insert(std::make_pair(chunkIndex, actor));
// Add By Lixu End
renderMeshes.resize(meshes.size());
renderables.resize(meshes.size());
@@ -231,8 +375,11 @@ BlastFamilyModelSimple::BlastFamilyModelSimple(PhysXController& physXController,
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);
+
+ RenderMaterial* pRenderMaterial = pSampleManager->getRenderMaterial(materials[materialIndex]);
+
+ Renderable* renderable = renderer.createRenderable(*renderMeshes[i], *pRenderMaterial);
+ renderable->setHidden(!_getBPPChunkVisible(chunkIndex));
renderables[i] = renderable;
// Add By Lixu Begin
if (materialIndex == 0)
@@ -247,6 +394,10 @@ BlastFamilyModelSimple::BlastFamilyModelSimple(PhysXController& physXController,
}
}
+// Add By Lixu Begin
+ initTransform(desc.transform);
+// Add By Lixu End
+
// initialize in position
initialize(desc);
}
@@ -254,21 +405,63 @@ BlastFamilyModelSimple::BlastFamilyModelSimple(PhysXController& physXController,
BlastFamilyModelSimple::~BlastFamilyModelSimple()
{
// Add By Lixu Begin
+ // remove from AssetFamiliesMap
+ SampleManager* pSampleManager = SampleManager::ins();
+ std::map<BlastAsset*, std::vector<BlastFamily*>>& AssetFamiliesMap = pSampleManager->getAssetFamiliesMap();
+ BlastAsset* pBlastAsset = (BlastAsset*)&getBlastAsset();
+ std::vector<BlastFamily*>& families = AssetFamiliesMap[pBlastAsset];
+ std::vector<BlastFamily*>::iterator itBF;
+ for (itBF = families.begin(); itBF != families.end(); itBF++)
+ {
+ if ((*itBF) == this)
+ {
+ families.erase(itBF);
+ break;
+ }
+ }
+ if (families.size() == 0)
+ {
+ AssetFamiliesMap.erase(AssetFamiliesMap.find(pBlastAsset));
+ }
+
// disconnect the material and relative renderable
const BlastAssetModelSimple& blastAsset = *(BlastAssetModelSimple*)&m_blastAsset;
- const std::vector<RenderMaterial*>& materials = blastAsset.getRenderMaterials();
+ const std::vector<std::string>& materials = blastAsset.getRenderMaterials();
int materialSize = materials.size();
for (int ms = 0; ms < materialSize; ms++)
{
- RenderMaterial* pRenderMaterial = materials[ms];
+ RenderMaterial* pRenderMaterial = pSampleManager->getRenderMaterial(materials[ms]);
pRenderMaterial->clearRelatedRenderables();
}
- std::map<std::string, RenderMaterial*>& RenderMaterialMap = MaterialLibraryPanel::ins()->getRenderMaterials();
- std::map<std::string, RenderMaterial*>::iterator it;
- for (it = RenderMaterialMap.begin(); it != RenderMaterialMap.end(); it++)
+
+ // remove physx actor for edit mode
+ PxScene& editScene = pSampleManager->getPhysXController().getEditPhysXScene();
+
+ for (std::map<PxActor*, uint32_t>::iterator itr = m_editActorChunkMap.begin(); itr != m_editActorChunkMap.end(); ++itr)
{
- RenderMaterial* pRenderMaterial = it->second;
- pRenderMaterial->clearRelatedRenderables();
+ editScene.removeActor(*(itr->first));
+ PxRigidDynamic* rigidDynamic = (itr->first)->is<PxRigidDynamic>();
+ if (rigidDynamic == nullptr)
+ {
+ itr->first->release();
+ continue;
+ }
+
+ PxU32 shapeCount = rigidDynamic->getNbShapes();
+ std::vector<PxShape*> shapes;
+ shapes.resize(shapeCount);
+ rigidDynamic->getShapes(shapes.data(), shapeCount);
+ for (PxU32 u = 0; u < shapeCount; ++u)
+ {
+ PxShape& shape = *shapes[u];
+ rigidDynamic->detachShape(shape);
+ PxConvexMeshGeometry geometry;
+ shape.getConvexMeshGeometry(geometry);
+ geometry.convexMesh->release();
+ shape.release();
+ }
+
+ rigidDynamic->release();
}
// Add By Lixu End
@@ -282,6 +475,9 @@ BlastFamilyModelSimple::~BlastFamilyModelSimple()
SAFE_DELETE(m_chunks[chunkIndex].renderMeshes[i]);
}
}
+ // Add By Lixu Begin
+ //PrintActors(SampleManager::ins()->getPhysXController());
+ // Add By Lixu End
}
void BlastFamilyModelSimple::onActorCreated(const ExtPxActor& actor)
@@ -299,9 +495,15 @@ void BlastFamilyModelSimple::onActorCreated(const ExtPxActor& actor)
{
if (colors.size() <= r)
colors.push_back(getRandomPastelColor());
-
- renderables[r]->setHidden(false);
- renderables[r]->setColor(colors[r]);
+ if (SampleManager::ins()->IsSimulating())
+ {
+ renderables[r]->setHidden(false);
+ }
+ else
+ {
+ renderables[r]->setHidden(!_getBPPChunkVisible(chunkIndex));
+ }
+// renderables[r]->setColor(colors[r]);
m_VisibleChangedChunks[chunkIndex] = true;
}
@@ -311,6 +513,9 @@ void BlastFamilyModelSimple::onActorCreated(const ExtPxActor& actor)
void BlastFamilyModelSimple::onActorUpdate(const ExtPxActor& actor)
{
// Add By Lixu Begin
+ if (!SampleManager::ins()->IsSimulating())
+ return;
+
uint32_t shapesCount = actor.getPhysXActor().getNbShapes();
PxTransform lp;
if (shapesCount > 0)
@@ -336,6 +541,12 @@ void BlastFamilyModelSimple::onActorUpdate(const ExtPxActor& actor)
r->setTransform(actor.getPhysXActor().getGlobalPose() * lp * subChunks[chunks[chunkIndex].firstSubchunkIndex].transform);
// Add By Lixu End
}
+
+ // Add By Lixu Begin
+ PxActor* editActor = m_chunkEditActorMap[chunkIndex];
+ PxRigidDynamic* rigidDynamic = editActor->is<PxRigidDynamic>();
+ rigidDynamic->setGlobalPose(actor.getPhysXActor().getGlobalPose() * lp * subChunks[chunks[chunkIndex].firstSubchunkIndex].transform);
+ // Add By Lixu End
}
}
@@ -373,6 +584,7 @@ void BlastFamilyModelSimple::onActorHealthUpdate(const ExtPxActor& actor)
const NvBlastBond* bonds = tkAsset->getBonds();
const NvBlastSupportGraph graph = tkAsset->getGraph();
+ const float bondHealthMax = m_blastAsset.getBondHealthMax();
std::vector<float> healthBuffer;
@@ -405,7 +617,7 @@ void BlastFamilyModelSimple::onActorHealthUpdate(const ExtPxActor& actor)
{
uint32_t node1 = graph.adjacentNodeIndices[adjacencyIndex];
uint32_t bondIndex = graph.adjacentBondIndices[adjacencyIndex];
- float bondHealth = PxClamp(bondHealths[bondIndex] / BOND_HEALTH_MAX, 0.0f, 1.0f);
+ float bondHealth = PxClamp(bondHealths[bondIndex] / bondHealthMax, 0.0f, 1.0f);
const NvBlastBond& solverBond = bonds[bondIndex];
const PxVec3& centroid = reinterpret_cast<const PxVec3&>(solverBond.centroid);
@@ -424,30 +636,167 @@ void BlastFamilyModelSimple::onActorHealthUpdate(const ExtPxActor& actor)
}
// Add By Lixu Begin
-void BlastFamilyModelSimple::setActorSelected(const ExtPxActor& actor, bool selected)
+bool BlastFamilyModelSimple::find(const PxActor& actor)
{
- const uint32_t* chunkIndices = actor.getChunkIndices();
- uint32_t chunkCount = actor.getChunkCount();
- for (uint32_t i = 0; i < chunkCount; i++)
+ return -1 != getChunkIndexByPxActor(actor);
+}
+
+void BlastFamilyModelSimple::updateActorRenderableTransform(const PxActor& actor, PxTransform& pos, bool local)
+{
+ uint32_t chunkIndex = getChunkIndexByPxActor(actor);
+ if (-1 == chunkIndex)
+ return;
+
+ std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables;
+ for (Renderable* r : renderables)
{
- uint32_t chunkIndex = chunkIndices[i];
- std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables;
- for (Renderable* r : renderables)
+ if (!local)
+ {
+ r->setTransform(pos);
+
+ // in edit mode, if change root chunk's orientation in edit physx scene, also change root physx actor in blast physx scene
+ if (0 == chunkIndex && !SampleManager::ins()->IsSimulating())
+ {
+ (*m_actors.begin())->getPhysXActor().setGlobalPose(pos);
+ }
+ }
+ else
{
- r->setSelected(selected);
+ if (0 == chunkIndex)
+ {
+ PxActor& blastActor = (*m_actors.begin())->getPhysXActor();
+ PxRigidDynamic* rigidDynamic = blastActor.is<PxRigidDynamic>();
+ if (NULL != rigidDynamic)
+ {
+ PxTransform gp_new = pos;
+ PxTransform gp_old = rigidDynamic->getGlobalPose();
+ rigidDynamic->setGlobalPose(pos);
+ PxScene& pxScene = SampleManager::ins()->getPhysXController().getPhysXScene();
+ modifyPxActorByLocalWay(pxScene, *rigidDynamic, gp_old, gp_new);
+ const BlastModel& model = dynamic_cast<BlastAssetModelSimple*>(const_cast<BlastAsset*>(&m_blastAsset))->getModel();
+ // update model mesh
+ modifyModelByLocalWay(*(const_cast<BlastModel*>(&model)), gp_old, gp_new);
+ // update blast asset instance's transform
+ BPPAssetInstance* assetInstance = SampleManager::ins()->getInstanceByFamily(this);
+ assetInstance->transform.position = nvidia::NvVec3(gp_new.p.x, gp_new.p.y, gp_new.p.z);
+ assetInstance->transform.rotation = nvidia::NvVec4(gp_new.q.x, gp_new.q.y, gp_new.q.z, gp_new.q.w);
+ }
+ }
}
}
}
+uint32_t BlastFamilyModelSimple::getChunkIndexByPxActor(const PxActor& actor)
+{
+ std::map<PxActor*, uint32_t>::iterator itr = m_editActorChunkMap.find(const_cast<PxActor*>(&actor));
+
+ if (itr != m_editActorChunkMap.end())
+ {
+ return itr->second;
+ }
+ else
+ {
+ for (ExtPxActor* extPxActor : m_actors)
+ {
+ if (&(extPxActor->getPhysXActor()) == (&actor)->is<physx::PxRigidDynamic>())
+ {
+ return extPxActor->getChunkIndices()[0];
+ }
+ }
+ }
+ return -1;
+}
+
+bool BlastFamilyModelSimple::getPxActorByChunkIndex(uint32_t chunkIndex, PxActor** ppActor)
+{
+ *ppActor = nullptr;
+ std::map<uint32_t, PxActor*>::iterator it = m_chunkEditActorMap.find(chunkIndex);
+ if (it == m_chunkEditActorMap.end())
+ {
+ return false;
+ }
+
+ *ppActor = it->second;
+ return true;
+}
+
+void BlastFamilyModelSimple::setActorSelected(const PxActor& actor, bool selected)
+{
+ uint32_t chunkIndex = getChunkIndexByPxActor(actor);
+ if (-1 == chunkIndex)
+ return;
+
+ bool selectionDepthTest = BlastProject::ins().getParams().fracture.general.selectionDepthTest;
+
+ std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables;
+ for (Renderable* r : renderables)
+ {
+ r->setSelected(selected);
+
+ if (!selectionDepthTest && selected)
+ {
+ r->setDepthTest(false);
+ }
+ else
+ {
+ r->setDepthTest(true);
+ }
+ }
+}
+
+bool BlastFamilyModelSimple::isActorSelected(const PxActor& actor)
+{
+ uint32_t chunkIndex = getChunkIndexByPxActor(actor);
+ if (-1 == chunkIndex)
+ return false;
+
+ std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables;
+ return renderables[0]->isSelected();
+}
+
+void BlastFamilyModelSimple::setActorVisible(const PxActor& actor, bool visible)
+{
+ uint32_t chunkIndex = getChunkIndexByPxActor(actor);
+ if (-1 == chunkIndex)
+ return;
+
+ std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables;
+ for (Renderable* r : renderables)
+ {
+ r->setHidden(!visible);
+ }
+}
+
+bool BlastFamilyModelSimple::isActorVisible(const PxActor& actor)
+{
+ uint32_t chunkIndex = getChunkIndexByPxActor(actor);
+ if (-1 == chunkIndex)
+ return false;
+
+ std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables;
+ return !renderables[0]->isHidden();
+}
+
void BlastFamilyModelSimple::setChunkSelected(uint32_t chunk, bool selected)
{
if (chunk > m_chunks.size())
return;
+ bool selectionDepthTest = BlastProject::ins().getParams().fracture.general.selectionDepthTest;
+
std::vector<Renderable*>& renderables = m_chunks[chunk].renderables;
for (Renderable* r : renderables)
{
r->setSelected(select);
+
+ if (!selectionDepthTest && selected)
+ {
+ r->setDepthTest(false);
+ }
+ else
+ {
+ r->setDepthTest(true);
+ }
}
}
@@ -472,11 +821,13 @@ void BlastFamilyModelSimple::clearChunksSelected()
for (Renderable* r : renderables)
{
r->setSelected(false);
+ r->setDepthTest(true);
+ r->setHighlight(false);
}
}
}
-bool BlastFamilyModelSimple::getChunkSelected(uint32_t chunk)
+bool BlastFamilyModelSimple::isChunkSelected(uint32_t chunk)
{
if (chunk > m_chunks.size())
return false;
@@ -515,17 +866,31 @@ std::vector<uint32_t> BlastFamilyModelSimple::getSelectedChunks()
return selectedChunks;
}
-void BlastFamilyModelSimple::setActorScale(const ExtPxActor& actor, PxMat44& scale, bool replace)
+void BlastFamilyModelSimple::setActorScale(const PxActor& actor, PxMat44& scale, bool replace)
{
- const uint32_t* chunkIndices = actor.getChunkIndices();
- uint32_t chunkCount = actor.getChunkCount();
- for (uint32_t i = 0; i < chunkCount; i++)
+ uint32_t chunkIndex = getChunkIndexByPxActor(actor);
+ if (-1 == chunkIndex)
+ return;
+ std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables;
+ for (Renderable* r : renderables)
{
- uint32_t chunkIndex = chunkIndices[i];
- std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables;
- for (Renderable* r : renderables)
+ r->setMeshScale(scale, replace);
+ }
+
+ if (0 == chunkIndex)
+ {
+ PxActor& blastActor = (*m_actors.begin())->getPhysXActor();
+ PxRigidDynamic* rigidDynamic = blastActor.is<PxRigidDynamic>();
+ if (NULL != rigidDynamic)
{
- r->setMeshScale(scale, replace);
+ PxScene& pxScene = SampleManager::ins()->getPhysXController().getPhysXScene();
+ scalePxActor(pxScene, *rigidDynamic, scale);
+
+ if (replace)
+ {
+ const BlastModel& model = dynamic_cast<BlastAssetModelSimple*>(const_cast<BlastAsset*>(&m_blastAsset))->getModel();
+ scaleModel(*(const_cast<BlastModel*>(&model)), scale);
+ }
}
}
}
@@ -574,6 +939,7 @@ void BlastFamilyModelSimple::setChunkVisible(std::vector<uint32_t> depths, bool
void BlastFamilyModelSimple::initTransform(physx::PxTransform t)
{
+ BlastFamily::initTransform(t);
int chunkSize = m_chunks.size();
for (int i = 0; i < chunkSize; i++)
{
@@ -583,6 +949,12 @@ void BlastFamilyModelSimple::initTransform(physx::PxTransform t)
r->setTransform(t);
}
}
+
+ for (std::map<PxActor*, uint32_t>::iterator itr = m_editActorChunkMap.begin(); itr != m_editActorChunkMap.end(); ++itr)
+ {
+ PxRigidDynamic* rigidDynamic = itr->first->is<PxRigidDynamic>();
+ rigidDynamic->setGlobalPose(t);
+ }
}
void BlastFamilyModelSimple::getMaterial(RenderMaterial** ppRenderMaterial, bool externalSurface)
@@ -655,4 +1027,39 @@ void BlastFamilyModelSimple::setMaterial(RenderMaterial* pRenderMaterial, bool e
}
}
}
+
+void BlastFamilyModelSimple::highlightChunks()
+{
+ bool selectionDepthTest = BlastProject::ins().getParams().fracture.general.selectionDepthTest;
+
+ for (Chunk chunk : m_chunks)
+ {
+ std::vector<Renderable*>& renderables = chunk.renderables;
+ for (Renderable* r : renderables)
+ {
+ r->setHighlight(true);
+ r->setDepthTest(selectionDepthTest);
+ }
+ }
+}
+
+bool BlastFamilyModelSimple::_getBPPChunkVisible(uint32_t chunkIndex)
+{
+ std::map<BlastAsset*, AssetList::ModelAsset>& assetDescMap = SampleManager::ins()->getAssetDescMap();
+ BlastAsset* blastAsset = (BlastAsset*)&getBlastAsset();
+ AssetList::ModelAsset& m = assetDescMap[blastAsset];
+
+ BlastProject& project = BlastProject::ins();
+ BPPAsset& bppAsset = *(project.getAsset(m.name.c_str()));
+
+ BPPChunk* bppChunk = project.getChunk(bppAsset, chunkIndex);
+ if (bppChunk)
+ {
+ return bppChunk->visible;
+ }
+ else
+ {
+ return true;
+ }
+}
// Add By Lixu End \ No newline at end of file
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSimple.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSimple.h
index ed51133..c86242a 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSimple.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSimple.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef BLAST_FAMILY_MODEL_SIMPLE_H
#define BLAST_FAMILY_MODEL_SIMPLE_H
@@ -17,6 +35,13 @@
class SimpleRenderMesh;
class Renderable;
class Renderer;
+// Add By Lixu Begin
+namespace physx
+{
+ class PxActor;
+}
+using namespace physx;
+// Add By Lixu End
class BlastFamilyModelSimple : public BlastFamily
{
@@ -27,19 +52,27 @@ public:
virtual ~BlastFamilyModelSimple();
// Add By Lixu Begin
- virtual void setActorSelected(const ExtPxActor& actor, bool selected);
+ virtual bool find(const PxActor& actor);
+ virtual void updateActorRenderableTransform(const PxActor& actor, PxTransform& pos, bool local);
+ virtual uint32_t getChunkIndexByPxActor(const PxActor& actor);
+ virtual bool getPxActorByChunkIndex(uint32_t chunkIndex, PxActor** ppActor);
+ virtual void setActorSelected(const PxActor& actor, bool selected);
+ virtual bool isActorSelected(const PxActor& actor);
+ virtual void setActorVisible(const PxActor& actor, bool visible);
+ virtual bool isActorVisible(const PxActor& actor);
virtual void clearChunksSelected();
virtual void setChunkSelected(uint32_t chunk, bool selected);
virtual void setChunkSelected(std::vector<uint32_t> depths, bool selected);
- virtual bool getChunkSelected(uint32_t chunk);
+ virtual bool isChunkSelected(uint32_t chunk);
virtual std::vector<uint32_t> getSelectedChunks();
- virtual void setActorScale(const ExtPxActor& actor, PxMat44& scale, bool replace);
+ virtual void setActorScale(const PxActor& actor, PxMat44& scale, bool replace);
virtual bool isChunkVisible(uint32_t chunkIndex);
virtual void setChunkVisible(uint32_t chunkIndex, bool bVisible);
virtual void setChunkVisible(std::vector<uint32_t> depths, bool bVisible);
virtual void initTransform(physx::PxTransform t);
virtual void getMaterial(RenderMaterial** ppRenderMaterial, bool externalSurface);
virtual void setMaterial(RenderMaterial* pRenderMaterial, bool externalSurface);
+ virtual void highlightChunks();
// Add By Lixu End
protected:
@@ -51,6 +84,10 @@ protected:
virtual void onActorHealthUpdate(const ExtPxActor& pxActor);
private:
+ // Add By Lixu Begin
+ bool _getBPPChunkVisible(uint32_t chunkIndex);
+ // Add By Lixu End
+
//////// internal data ////////
Renderer& m_renderer;
@@ -66,6 +103,8 @@ private:
};
std::vector<Chunk> m_chunks;
+ std::map<PxActor*, uint32_t> m_editActorChunkMap;// only for edit mode
+ std::map<uint32_t, PxActor*> m_chunkEditActorMap;// only for edit mode
};
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSkinned.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSkinned.cpp
index c0731d5..a0319ff 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSkinned.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSkinned.cpp
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "BlastFamilyModelSkinned.h"
#include "RenderUtils.h"
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSkinned.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSkinned.h
index aeb9353..d76b18e 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSkinned.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSkinned.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef BLAST_FAMILY_MODEL_SKINNED_H
#define BLAST_FAMILY_MODEL_SKINNED_H
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFractureTool.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFractureTool.cpp
index aa738b9..5051534 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFractureTool.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFractureTool.cpp
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "BlastFractureTool.h"
#include <BlastAssetModel.h>
@@ -126,8 +144,72 @@ void BlastFractureTool::setSourceAsset(const BlastAsset* pBlastAsset)
for (uint32_t i = 0; i < supportGraph.nodeCount; ++i)
{
const uint32_t chunkIndex = supportGraph.chunkIndices[i];
- isLeafs[chunkIndex] = true;
+ if (chunkIndex < chunkSize)
+ {
+ isLeafs[chunkIndex] = true;
+ }
+ }
+ }
+
+ setSourceMesh(chunkMeshes[0]);
+
+ mChunkData.resize(chunkSize);
+ mChunkData[0].parent = parentIds[0];
+ mChunkData[0].isLeaf = isLeafs[0];
+ mChunkData[0].chunkId = 0;
+ Nv::Blast::Mesh* mesh = nullptr;
+ for (int cs = 1; cs < chunkSize; cs++)
+ {
+ if (chunkMeshes[cs] == nullptr)
+ continue;
+ mChunkData[cs].meshData = new Nv::Blast::Mesh(*chunkMeshes[cs]);
+ mChunkData[cs].parent = parentIds[cs];
+ mChunkData[cs].chunkId = mChunkIdCounter++;
+ mChunkData[cs].isLeaf = isLeafs[cs];
+
+ mesh = mChunkData[cs].meshData;
+ Nv::Blast::Vertex* verticesBuffer = mesh->getVertices();
+ for (uint32_t i = 0; i < mesh->getVerticesCount(); ++i)
+ {
+ verticesBuffer[i].p = (verticesBuffer[i].p - mOffset) * (1.0f / mScaleFactor);
+ }
+ mesh->getBoundingBox().minimum = (mesh->getBoundingBox().minimum - mOffset) * (1.0f / mScaleFactor);
+ mesh->getBoundingBox().maximum = (mesh->getBoundingBox().maximum - mOffset) * (1.0f / mScaleFactor);
+ for (uint32_t i = 0; i < mesh->getFacetCount(); ++i)
+ {
+ mesh->getFacet(i)->userData = chunkMeshes[cs]->getFacet(i)->userData;
+ }
+ }
+}
+
+void BlastFractureTool::setSourceMeshes(std::vector<Nv::Blast::Mesh*>& meshes, std::vector<int32_t>& parentIds)
+{
+ free();
+
+ int chunkSize = meshes.size();
+ if (chunkSize == 0)
+ {
+ return;
+ }
+
+ chunkMeshes.resize(chunkSize, nullptr);
+ for (int cs = 0; cs < chunkSize; cs++)
+ {
+ Nv::Blast::Mesh* pMesh = new Nv::Blast::Mesh(*meshes[cs]);
+ chunkMeshes[cs] = pMesh;
+ }
+
+ std::vector<bool> isLeafs;
+ isLeafs.resize(chunkSize, true);
+ for (int cs = 0; cs < chunkSize; cs++)
+ {
+ int32_t parentId = parentIds[cs];
+ if (parentId == -1)
+ {
+ continue;
}
+
+ isLeafs[parentId] = false;
}
setSourceMesh(chunkMeshes[0]);
@@ -143,7 +225,7 @@ void BlastFractureTool::setSourceAsset(const BlastAsset* pBlastAsset)
continue;
mChunkData[cs].meshData = new Nv::Blast::Mesh(*chunkMeshes[cs]);
mChunkData[cs].parent = parentIds[cs];
- mChunkData[cs].chunkId = cs;
+ mChunkData[cs].chunkId = mChunkIdCounter++;
mChunkData[cs].isLeaf = isLeafs[cs];
mesh = mChunkData[cs].meshData;
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFractureTool.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFractureTool.h
index b50ccf3..42ff78f 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFractureTool.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFractureTool.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef BLAST_FRACTURETOOL_H
#define BLAST_FRACTURETOOL_H
@@ -25,11 +43,13 @@ namespace Nv
class BlastFractureTool : public Nv::Blast::FractureTool
{
public:
- BlastFractureTool(NvBlastLog logCallback = nullptr) : FractureTool(logCallback) {}
+ BlastFractureTool() {}
~BlastFractureTool() { free(); }
void setSourceAsset(const BlastAsset* pBlastAsset);
+ void setSourceMeshes(std::vector<Nv::Blast::Mesh*>& meshes, std::vector<int32_t>& parentIds);
+
Nv::Blast::Mesh* getSourceMesh(int32_t chunkId);
private:
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastModel.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastModel.cpp
index d231a6c..1e45003 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastModel.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastModel.cpp
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "BlastModel.h"
@@ -14,14 +32,101 @@
//#define TINYOBJLOADER_IMPLEMENTATION
// Add By Lixu End
#include "tiny_obj_loader.h"
-
+#include "MathUtil.h"
+#include "NvBlastExtExporterFbxReader.h"
using namespace physx;
+void computeTangentByPositionAndTexcoord(
+ physx::PxVec3 p0, physx::PxVec3 p1, physx::PxVec3 p2,
+ physx::PxVec2 r0, physx::PxVec2 r1, physx::PxVec2 r2,
+ physx::PxVec3& tangent)
+{
+ float x1 = p1.x - p0.x;
+ float x2 = p2.x - p0.x;
+ float y1 = p1.y - p0.y;
+ float y2 = p2.y - p0.y;
+ float z1 = p1.z - p0.z;
+ float z2 = p2.z - p0.z;
+
+ float s1 = r1.x - r0.x;
+ float s2 = r2.x - r0.x;
+ float t1 = r1.y - r0.y;
+ float t2 = r2.y - r0.y;
+
+ float r = 1.0f / (s1 * t2 - s2 * t1);
+
+ tangent = PxVec3((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, (t2 * z1 - t1 * z2) * r);
+}
+
+BlastModelPtr BlastModel::loadFromFbxFile(const char* path)
+{
+// Add By Lixu Begin
+ BlastModel* model = new BlastModel();
+ model->bbMin = PxVec3(FLT_MAX, FLT_MAX, FLT_MAX);
+ model->bbMax = PxVec3(FLT_MIN, FLT_MIN, FLT_MIN);
+// Add By Lixu End
+
+ FbxFileReader rdr;
+ 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
+ */
+ std::vector<uint32_t> infl;
+ rdr.getBoneInfluences(infl);
+ for (uint32_t i = 0; i < rdr.getBoneCount(); ++i)
+ {
+ std::vector<int32_t> indRemap(rdr.getPositionArray().size(), -1);
+ std::vector<uint32_t> indices;
+ SimpleMesh cmesh;
+ for (uint32_t j = 0; j < rdr.getPositionArray().size(); ++j)
+ {
+ if (i == infl[j])
+ {
+ indRemap[j] = (int32_t)cmesh.vertices.size();
+ cmesh.vertices.push_back(SimpleMesh::Vertex());
+ cmesh.vertices.back().normal = rdr.getNormalsArray()[j];
+ cmesh.vertices.back().position = rdr.getPositionArray()[j];
+ cmesh.vertices.back().uv = rdr.getUvArray()[j];
+ }
+ }
+ for (uint32_t j = 0; j < rdr.getIndexArray().size(); j += 3)
+ {
+ if (i == infl[rdr.getIndexArray()[j]])
+ {
+ int32_t lind = rdr.getIndexArray()[j + 2];
+ cmesh.indices.push_back(indRemap[lind]);
+ lind = rdr.getIndexArray()[j + 1];
+ cmesh.indices.push_back(indRemap[lind]);
+ lind = rdr.getIndexArray()[j];
+ cmesh.indices.push_back(indRemap[lind]);
+ }
+ }
+
+ model->chunks[i].meshes.push_back(Chunk::Mesh());
+ model->chunks[i].meshes.back().materialIndex = 0;
+ model->chunks[i].meshes.back().mesh = cmesh;
+ }
+ return model;
+}
+
+
BlastModelPtr BlastModel::loadFromFileTinyLoader(const char* path)
{
// Add By Lixu Begin
BlastModel* model = new BlastModel();
+ model->bbMin = PxVec3(FLT_MAX, FLT_MAX, FLT_MAX);
+ model->bbMax = PxVec3(FLT_MIN, FLT_MIN, FLT_MIN);
// Add By Lixu End
std::vector<tinyobj::shape_t> shapes;
@@ -30,14 +135,14 @@ BlastModelPtr BlastModel::loadFromFileTinyLoader(const char* path)
std::string mtlPath;
for (size_t i = strnlen(path, 255) - 1; i >= 0; --i)
{
- if (path[i] == '\\')
+ if (path[i] == '\\' || path[i] == '/')
{
mtlPath.resize(i + 2, 0);
strncpy(&mtlPath[0], path, i + 1);
break;
}
}
-
+
bool ret = tinyobj::LoadObj(shapes, mats, err, path, mtlPath.data());
@@ -54,11 +159,24 @@ BlastModelPtr BlastModel::loadFromFileTinyLoader(const char* path)
{
tinyobj::material_t *pMaterial = &mats[i];
- if (!pMaterial->diffuse_texname.empty())
+ // Add By Lixu Begin
+ if (strcmp(pMaterial->name.c_str(), "neverMat123XABCnever") == 0)
+ {
+ model->materials[i].name.clear();
+ }
+ else
{
-// Add By Lixu Begin
model->materials[i].name = pMaterial->name;
-// Add By Lixu End
+ }
+ // Add By Lixu End
+
+ model->materials[i].r = pMaterial->diffuse[0];
+ model->materials[i].g = pMaterial->diffuse[1];
+ model->materials[i].b = pMaterial->diffuse[2];
+ model->materials[i].a = 1.0;
+
+ if (!pMaterial->diffuse_texname.empty())
+ {
model->materials[i].diffuseTexture = pMaterial->diffuse_texname;
}
}
@@ -154,12 +272,39 @@ BlastModelPtr BlastModel::loadFromFileTinyLoader(const char* path)
}
}
+ // compute tangent
+ if (pMesh.mesh.indices.size() > 0 && allTriangles)
+ {
+ for (uint32_t i = 0; i < pMesh.mesh.indices.size(); i += 3)
+ {
+ SimpleMesh::Vertex& v0 = chunkMesh.vertices[chunkMesh.indices[i + 0]];
+ SimpleMesh::Vertex& v1 = chunkMesh.vertices[chunkMesh.indices[i + 1]];
+ SimpleMesh::Vertex& v2 = chunkMesh.vertices[chunkMesh.indices[i + 2]];
+
+ physx::PxVec3 tangent;
+ computeTangentByPositionAndTexcoord(
+ v0.position, v1.position, v2.position, v0.uv, v1.uv, v2.uv, tangent);
+
+ v0.tangent += tangent;
+ v1.tangent += tangent;
+ v2.tangent += tangent;
+ }
+ for (uint32_t i = 0; i < chunkMesh.vertices.size(); i++)
+ {
+ chunkMesh.vertices[i].tangent = chunkMesh.vertices[i].tangent.getNormalized();
+ }
+ }
+
// assign extents
chunkMesh.extents = (emax - emin) * 0.5f;
// get the center
chunkMesh.center = emin + chunkMesh.extents;
+ atcore_float3 min = gfsdk_min(*(atcore_float3*)&emin, *(atcore_float3*)&(model->bbMin));
+ model->bbMin = *(physx::PxVec3*)&min;
+ atcore_float3 max = gfsdk_max(*(atcore_float3*)&emax, *(atcore_float3*)&(model->bbMax));
+ model->bbMax = *(physx::PxVec3*)&max;
}
}
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastModel.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastModel.h
index 683a343..82d2af8 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastModel.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastModel.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef BLAST_MODEL_H
#define BLAST_MODEL_H
@@ -32,10 +50,9 @@ class BlastModel
public:
struct Material
{
-// Add By Lixu Begin
std::string name;
-// Add By Lixu End
std::string diffuseTexture;
+ float r, g, b, a;
};
struct Chunk
@@ -51,8 +68,11 @@ public:
std::vector<Material> materials;
std::vector<Chunk> chunks;
+ physx::PxVec3 bbMin;
+ physx::PxVec3 bbMax;
static BlastModelPtr loadFromFileTinyLoader(const char* path);
+ static BlastModelPtr loadFromFbxFile(const char* path);
private:
BlastModel() {}
};
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastReplay.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastReplay.cpp
index 13d2b33..678cec2 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastReplay.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastReplay.cpp
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "BlastReplay.h"
#include "NvBlastTk.h"
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastReplay.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastReplay.h
index a85c996..2c247a5 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastReplay.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastReplay.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef BLAST_REPLAY_H
#define BLAST_REPLAY_H
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/core/Application.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/core/Application.cpp
index 955d841..81754e4 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/core/Application.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/core/Application.cpp
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "Application.h"
#include <DirectXMath.h>
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/core/Application.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/core/Application.h
index f0e0601..3681eb3 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/core/Application.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/core/Application.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef APPLICATION_H
#define APPLICATION_H
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/core/DeviceManager.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/core/DeviceManager.cpp
index b29fb86..78eefe8 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/core/DeviceManager.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/core/DeviceManager.cpp
@@ -7,6 +7,7 @@
#include <sstream>
#include <algorithm>
#include <vector>
+#include "GlobalSettings.h"
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p)=NULL; } }
@@ -333,14 +334,7 @@ DeviceManager::MessageLoop()
if (m_SwapChain && GetWindowState() != kWindowMinimized)
{
Animate(elapsedSeconds);
- // changed by Junma Lixu
- CoreLib* pCore = CoreLib::Inst();
- RenderInterface::SwitchToDX11();
- pCore->SimpleScene_Draw_DX11();
Render();
- RenderInterface::FlushDX11();
- RenderInterface::PresentRenderWindow();
- //m_SwapChain->Present(m_SyncInterval, 0);
Sleep(0);
}
else
@@ -486,7 +480,8 @@ DeviceManager::Render()
}
}
- m_ImmediateContext->OMSetRenderTargets(0, NULL, NULL);
+ m_ImmediateContext->OMSetRenderTargets(1, &m_BackBufferRTV, m_DepthStencilDSV);
+ GlobalSettings::Inst().m_renderFrameCnt++;
}
void
@@ -796,6 +791,6 @@ DeviceManager::SetWindowDeviceAndSwapChain(D3DHandles& deviceHandles)
m_DepthStencilBuffer = (ID3D11Texture2D*)deviceHandles.pD3D11DepthBuffer;
m_DepthStencilDSV = (ID3D11DepthStencilView*)deviceHandles.pD3D11DepthStencilView;
m_DepthStencilBuffer->GetDesc(&m_DepthStencilDesc);
- //m_DepthStencilDSV->GetDesc(&);
+
return S_OK;
}
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/core/SampleController.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/core/SampleController.cpp
index 163b3b4..cd8ea4c 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/core/SampleController.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/core/SampleController.cpp
@@ -1,18 +1,37 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "SampleController.h"
#include "SceneController.h"
#include "CommonUIController.h"
#include "BlastController.h"
#include "PhysXController.h"
+#include "Renderer.h"
#include "imgui.h"
@@ -45,9 +64,12 @@ void SampleController::setUseGPUPhysics(bool useGPUPhysics)
int assetNum = getSceneController().releaseAll();
+ getBlastController().notifyPhysXControllerRelease();
getPhysXController().setUseGPUPhysics(useGPUPhysics);
getBlastController().reinitialize();
+ getRenderer().clearQueue();
+
getSceneController().spawnAsset(assetNum);
}
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/core/SampleController.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/core/SampleController.h
index a52c2fe..6d478c1 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/core/SampleController.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/core/SampleController.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef SAMPLE_CONTROLLER_H
#define SAMPLE_CONTROLLER_H
@@ -48,6 +66,11 @@ private:
return getManager()->getCommonUIController();
}
+ Renderer& getRenderer() const
+ {
+ return getManager()->getRenderer();
+ }
+
//////// private methods ////////
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/core/SampleManager.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/core/SampleManager.cpp
index 63178fd..61a174a 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/core/SampleManager.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/core/SampleManager.cpp
@@ -1,16 +1,35 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
+
#include "AppMainWindow.h"
#include "GlobalSettings.h"
#include <QtCore/QFileInfo>
-
+#include <QtCore/QDir>
#include "NvBlastExtAuthoringTypes.h"
#include "NvBlastExtAuthoringFractureTool.h"
#include "NvBlastExtAuthoringBondGenerator.h"
@@ -26,6 +45,7 @@
#include "CommonUIController.h"
#include "DamageToolController.h"
#include "SelectionToolController.h"
+#include "ExplodeToolController.h"
#include "GizmoToolController.h"
#include "EditionToolController.h"
#include "SceneController.h"
@@ -41,9 +61,20 @@
#include <set>
#include "MaterialLibraryPanel.h"
#include "MaterialAssignmentsPanel.h"
+#include "ViewerOutput.h"
+
+#include "NvBlastTkAsset.h"
+#include "BlastAssetModelSimple.h"
+#include "CorelibUtils.h"
+#include "BlastAssetModel.h"
+#include "SimpleScene.h"
+#include "FileReferencesPanel.h"
+#include "BlastPlugin.h"
+#include "BlastToolBar.h"
using namespace physx;
+const uint32_t DEFAULT_VORONOI_UNIFORM_SITES_NUMBER = 5;
physx::PxFoundation* foundation = nullptr;
physx::PxPhysics* physics = nullptr;
physx::PxCooking* cooking = nullptr;
@@ -89,7 +120,7 @@ void loggingCallback(int type, const char* msg, const char* file, int line)
}
void buildPxChunks(const std::vector<std::vector<Triangle>>& chunkGeometry, std::vector<ExtPxAssetDesc::ChunkDesc>& pxChunks,
- std::vector<ExtPxAssetDesc::SubchunkDesc>& pxSubchunks)
+ std::vector<ExtPxAssetDesc::SubchunkDesc>& pxSubchunks, std::vector<bool>& statics)
{
ConvexMeshBuilder collisionBuilder(cooking, &physics->getPhysicsInsertionCallback());
@@ -107,7 +138,7 @@ void buildPxChunks(const std::vector<std::vector<Triangle>>& chunkGeometry, std:
}
pxSubchunks[i].transform = physx::PxTransform(physx::PxIdentity);
pxSubchunks[i].geometry = physx::PxConvexMeshGeometry(collisionBuilder.buildConvexMesh(vertices));
- pxChunks[i].isStatic = false;
+ pxChunks[i].isStatic = statics.size() == 0 ? false : statics[i];
pxChunks[i].subchunkCount = 1;
pxChunks[i].subchunks = &pxSubchunks[i];
}
@@ -118,10 +149,61 @@ void buildPxChunks(const std::vector<std::vector<Triangle>>& chunkGeometry, std:
void saveFractureToObj(std::vector<std::vector<Triangle> > chunksGeometry, std::string name, std::string path)
{
- MaterialAssignmentsPanel* pMaterialAssignmentsPanel = MaterialAssignmentsPanel::ins();
- std::vector<std::string> materialNames;
- std::vector<std::string> materialPaths;
- pMaterialAssignmentsPanel->getMaterialNameAndPaths(materialNames, materialPaths);
+ std::vector<std::string> materialNames(2);
+ std::vector<std::string> materialPaths(2);
+ float diffuseColor[2][4];
+
+ SampleManager* pSampleManager = SampleManager::ins();
+ BlastAsset* pCurBlastAsset = nullptr;
+ int nCurIndex = -1;
+ pSampleManager->getCurrentSelectedInstance(&pCurBlastAsset, nCurIndex);
+ if (pCurBlastAsset != nullptr && nCurIndex != -1)
+ {
+ pSampleManager->getMaterialForCurrentFamily(materialNames[0], true);
+ pSampleManager->getMaterialForCurrentFamily(materialNames[1], false);
+
+ BPPGraphicsMaterial* pMaterialEx = BlastProject::ins().getGraphicsMaterial(materialNames[0].c_str());
+ BPPGraphicsMaterial* pMaterialIn = BlastProject::ins().getGraphicsMaterial(materialNames[1].c_str());
+
+ diffuseColor[0][0] = pMaterialEx->diffuseColor.x;
+ diffuseColor[0][1] = pMaterialEx->diffuseColor.y;
+ diffuseColor[0][2] = pMaterialEx->diffuseColor.z;
+ diffuseColor[0][3] = pMaterialEx->diffuseColor.w;
+ if (pMaterialEx->diffuseTextureFilePath != nullptr)
+ {
+ materialPaths[0] = pMaterialEx->diffuseTextureFilePath;
+ }
+
+ if (pMaterialIn == nullptr)
+ {
+ pMaterialIn = pMaterialEx;
+ }
+
+ diffuseColor[1][0] = pMaterialIn->diffuseColor.x;
+ diffuseColor[1][1] = pMaterialIn->diffuseColor.y;
+ diffuseColor[1][2] = pMaterialIn->diffuseColor.z;
+ diffuseColor[1][3] = pMaterialIn->diffuseColor.w;
+ if (pMaterialIn->diffuseTextureFilePath != nullptr)
+ {
+ materialPaths[1] = pMaterialIn->diffuseTextureFilePath;
+ }
+ }
+ else
+ {
+ MaterialAssignmentsPanel* pMaterialAssignmentsPanel = MaterialAssignmentsPanel::ins();
+ pMaterialAssignmentsPanel->getMaterialNameAndPaths(materialNames, materialPaths);
+
+ if (materialPaths[0] == "")
+ {
+ RenderMaterial* pMaterialEx = RenderMaterial::getDefaultRenderMaterial();
+ pMaterialEx->getDiffuseColor(diffuseColor[0][0], diffuseColor[0][1], diffuseColor[0][2], diffuseColor[0][3]);
+ }
+ if (materialPaths[1] == "")
+ {
+ RenderMaterial* pMaterialIn = RenderMaterial::getDefaultRenderMaterial();
+ pMaterialIn->getDiffuseColor(diffuseColor[1][0], diffuseColor[1][1], diffuseColor[1][2], diffuseColor[1][3]);
+ }
+ }
uint32_t submeshCount = 2;
// export materials (mtl file)
@@ -133,8 +215,12 @@ void saveFractureToObj(std::vector<std::vector<Triangle> > chunksGeometry, std::
for (uint32_t submeshIndex = 0; submeshIndex < submeshCount; ++submeshIndex)
{
- fprintf(f, "newmtl %s\n", materialNames[submeshIndex].c_str());
+ // Add By Lixu Begin
+ std::string& matName = materialNames[submeshIndex];
+ fprintf(f, "newmtl %s\n", matName.size()? matName.c_str() : "neverMat123XABCnever"); // this speical string is also used in another BlastModel.cpp.
+ // Add By Lixu End
fprintf(f, "\tmap_Kd %s\n", materialPaths[submeshIndex].c_str());
+ fprintf(f, "\tKd %f %f %f\n", diffuseColor[submeshIndex][0], diffuseColor[submeshIndex][1], diffuseColor[submeshIndex][2]);
fprintf(f, "\n");
}
@@ -217,81 +303,201 @@ void saveFractureToObj(std::vector<std::vector<Triangle> > chunksGeometry, std::
}
}
-void FractureExecutor::setSourceMesh(Nv::Blast::Mesh* mesh)
+#include "NvBlastExtLlSerialization.h"
+#include "NvBlastExtTkSerialization.h"
+#include "NvBlastExtPxSerialization.h"
+#include "NvBlastExtSerialization.h"
+
+bool saveBlastObject(const std::string& outputDir, const std::string& objectName, const void* object, uint32_t objectTypeID)
{
- assert(m_fractureTool);
- m_sourMesh = mesh;
- m_fractureTool->setSourceMesh(mesh);
+ ExtSerialization* mSerialization = SampleManager::ins()->getBlastController().getExtSerialization();
+
+ void* buffer;
+ const uint64_t bufferSize = mSerialization->serializeIntoBuffer(buffer, object, objectTypeID);
+ if (bufferSize == 0)
+ {
+ std::cerr << "saveBlastObject: Serialization failed.\n";
+ return false;
+ }
+
+ // Add By Lixu Begin
+ physx::PsFileBuffer fileBuf((outputDir + "/" + objectName).c_str(), physx::PxFileBuf::OPEN_WRITE_ONLY);
+ // Add By Lixu End
+
+ bool result = fileBuf.isOpen();
+
+ if (!result)
+ {
+ std::cerr << "Can't open output buffer.\n";
+ }
+ else
+ {
+ result = (bufferSize == (size_t)fileBuf.write(buffer, (uint32_t)bufferSize));
+ if (!result)
+ {
+ std::cerr << "Buffer write failed.\n";
+ }
+ fileBuf.close();
+ }
+
+ NVBLAST_FREE(buffer);
+
+ return result;
+}
+
+bool saveLlAsset(const std::string& outputDir, const std::string& objectName, const NvBlastAsset* assetLL)
+{
+ return saveBlastObject(outputDir, objectName, assetLL, LlObjectTypeID::Asset);
+}
+
+bool saveTkAsset(const std::string& outputDir, const std::string& objectName, const TkAsset* tkAsset)
+{
+ return saveBlastObject(outputDir, objectName, tkAsset, TkObjectTypeID::Asset);
}
-void FractureExecutor::setSourceAsset(const BlastAsset* blastAsset)
+bool saveExtAsset(const std::string& outputDir, const std::string& objectName, const ExtPxAsset* pxAsset)
+{
+ return saveBlastObject(outputDir, objectName, pxAsset, ExtPxObjectTypeID::Asset);
+}
+
+void FractureExecutor::setSourceAsset(BlastAsset* blastAsset)
{
assert(m_fractureTool);
m_fractureTool->setSourceAsset(blastAsset);
- m_sourMesh = nullptr;
+ m_pCurBlastAsset = blastAsset;
}
VoronoiFractureExecutor::VoronoiFractureExecutor()
-: m_cellsCount(5)
+: m_voronoi(nullptr)
{
if (sSampleManager)
m_fractureTool = sSampleManager->m_fTool;
}
-void VoronoiFractureExecutor::setCellsCount(uint32_t cellsCount)
-{
- m_cellsCount = cellsCount;
-}
-
bool VoronoiFractureExecutor::execute()
{
- Nv::Blast::Mesh* mesh = nullptr;
- if (m_sourMesh)
+ std::vector<uint32_t>::iterator it;
+ for (it = m_chunkIds.begin(); it != m_chunkIds.end(); it++)
{
- mesh = m_sourMesh;
+ Nv::Blast::Mesh* mesh = m_fractureTool->getSourceMesh(*it);
+ if (mesh == nullptr)
+ continue;
+
+ VoronoiSitesGenerator* siteGenerator = nullptr;
+ if (m_voronoi)
+ {
+ siteGenerator = new VoronoiSitesGenerator(mesh, m_randomGenerator == nullptr ? &sRandomGenerator : m_randomGenerator);
+ if (0 == m_voronoi->siteGeneration)
+ {
+ siteGenerator->uniformlyGenerateSitesInMesh(m_voronoi->numSites);
+ }
+ else if (1 == m_voronoi->siteGeneration)
+ {
+ siteGenerator->clusteredSitesGeneration(m_voronoi->numberOfClusters, m_voronoi->sitesPerCluster, m_voronoi->clusterRadius);
+ }
+ }
+ else
+ {
+ siteGenerator = new VoronoiSitesGenerator(mesh, m_randomGenerator == nullptr ? &sRandomGenerator : m_randomGenerator);
+ siteGenerator->uniformlyGenerateSitesInMesh(DEFAULT_VORONOI_UNIFORM_SITES_NUMBER);
+ }
+
+ m_fractureTool->voronoiFracturing(*it, siteGenerator->getVoronoiSites(), false);
+ delete siteGenerator;
}
- else
+ m_fractureTool->finalizeFracturing();
+
+ std::vector<bool> supports;
+ std::vector<bool> statics;
+ std::vector<uint8_t> joints;
+ std::vector<uint32_t> worlds;
+ BlastAsset* pNewBlastAsset = sSampleManager->_replaceAsset(m_pCurBlastAsset, supports, statics, joints, worlds);
+ if (nullptr == pNewBlastAsset)
{
- mesh = m_fractureTool->getSourceMesh(m_chunkId);
- }
- // Prevent crash Junma Added By Lixu
- if (mesh == nullptr)
return false;
+ }
- VoronoiSitesGenerator stGenerator(mesh, (m_randomGenerator == nullptr ? &sRandomGenerator : m_randomGenerator));
- stGenerator.uniformlyGenerateSitesInMesh(m_cellsCount);
- m_fractureTool->voronoiFracturing(m_chunkId, stGenerator.getVoronoiSites(), false);
- m_fractureTool->finalizeFracturing();
+ std::vector<uint32_t> NewChunkIndexes;
+ for (uint32_t ci = 0; ci < m_fractureTool->getChunkCount(); ci++)
+ {
+ for (uint32_t chunkId : m_chunkIds)
+ {
+ if (m_fractureTool->getChunkInfo(ci).parent == chunkId)
+ {
+ NewChunkIndexes.push_back(ci);
+ }
+ }
+ }
- return sSampleManager->postProcessCurrentAsset();
+ sSampleManager->ApplyAutoSelectNewChunks(pNewBlastAsset, NewChunkIndexes);
+
+ return true;
}
SliceFractureExecutor::SliceFractureExecutor()
-: m_config(new Nv::Blast::SlicingConfiguration())
+: m_slice(nullptr)
{
if (sSampleManager)
m_fractureTool = sSampleManager->m_fTool;
}
-void SliceFractureExecutor::applyNoise(float amplitude, float frequency, int32_t octaves, float falloff, int32_t relaxIterations, float relaxFactor, int32_t seed)
+bool SliceFractureExecutor::execute()
{
- m_fractureTool->applyNoise(amplitude, frequency, octaves, falloff, relaxIterations, relaxFactor, seed);
-}
+ SlicingConfiguration config;
+ if (m_slice)
+ {
+ config.x_slices = m_slice->numSlicesX;
+ config.y_slices = m_slice->numSlicesY;
+ config.z_slices = m_slice->numSlicesZ;
+ config.offset_variations = m_slice->offsetVariation;
+ config.angle_variations = m_slice->rotationVariation;
+ config.noiseAmplitude = m_slice->noiseAmplitude;
+ config.noiseFrequency = m_slice->noiseFrequency;
+ config.noiseOctaveNumber = m_slice->noiseOctaveNumber;
+ config.surfaceResolution = m_slice->surfaceResolution;
+ }
-void SliceFractureExecutor::applyConfig(int32_t xSlices, int32_t ySlices, int32_t zSlices, float offsetVariations, float angleVariations)
-{
- m_config->x_slices = xSlices;
- m_config->y_slices = ySlices;
- m_config->z_slices = zSlices;
- m_config->offset_variations = offsetVariations;
- m_config->angle_variations = angleVariations;
-}
+ if (m_randomGenerator == nullptr)
+ {
+ sRandomGenerator.seed(m_slice->noiseSeed);
+ }
+ else
+ {
+ m_randomGenerator->seed(m_slice->noiseSeed);
+ }
-bool SliceFractureExecutor::execute()
-{
- m_fractureTool->slicing(m_chunkId, *m_config, false, (m_randomGenerator == nullptr ? &sRandomGenerator : m_randomGenerator));
+ std::vector<uint32_t>::iterator it;
+ for (it = m_chunkIds.begin(); it != m_chunkIds.end(); it++)
+ {
+ m_fractureTool->slicing(*it, config, false, (m_randomGenerator == nullptr ? &sRandomGenerator : m_randomGenerator));
+ }
m_fractureTool->finalizeFracturing();
- return sSampleManager->postProcessCurrentAsset();
+
+ std::vector<bool> supports;
+ std::vector<bool> statics;
+ std::vector<uint8_t> joints;
+ std::vector<uint32_t> worlds;
+ BlastAsset* pNewBlastAsset = sSampleManager->_replaceAsset(m_pCurBlastAsset, supports, statics, joints, worlds);
+ if (nullptr == pNewBlastAsset)
+ {
+ return false;
+ }
+
+ std::vector<uint32_t> NewChunkIndexes;
+ for (uint32_t ci = 0; ci < m_fractureTool->getChunkCount(); ci++)
+ {
+ for (uint32_t chunkId : m_chunkIds)
+ {
+ if (m_fractureTool->getChunkInfo(ci).parent == chunkId)
+ {
+ NewChunkIndexes.push_back(ci);
+ }
+ }
+ }
+
+ sSampleManager->ApplyAutoSelectNewChunks(pNewBlastAsset, NewChunkIndexes);
+
+ return true;
}
static VoronoiFractureExecutor sVoronoiFracture;
@@ -302,9 +508,8 @@ SampleManager* SampleManager::ins()
}
SampleManager::SampleManager(DeviceManager* pDeviceManager)
-{
+{
sSampleManager = this;
- m_bNeedConfig = false;
m_bNeedRefreshTree = false;
m_renderer = new Renderer();
@@ -313,10 +518,11 @@ SampleManager::SampleManager(DeviceManager* pDeviceManager)
m_sceneController = new SceneController();
m_damageToolController = new DamageToolController();
m_selectionToolController = new SelectionToolController();
+ m_explodeToolController = new ExplodeToolController();
m_gizmoToolController = new GizmoToolController();
m_editionToolController = new EditionToolController();
m_sampleController = new SampleController();
-// m_commonUIController = new CommonUIController();
+ m_commonUIController = nullptr; // new CommonUIController();
m_pApplication = new Application(pDeviceManager);
@@ -328,8 +534,9 @@ SampleManager::SampleManager(DeviceManager* pDeviceManager)
app.addControllerToFront(m_sceneController);
app.addControllerToFront(m_damageToolController);
app.addControllerToFront(m_selectionToolController);
+ app.addControllerToFront(m_explodeToolController);
app.addControllerToFront(m_gizmoToolController);
- app.addControllerToFront(m_editionToolController);
+// app.addControllerToFront(m_editionToolController);
app.addControllerToFront(m_sampleController);
// app.addControllerToFront(m_commonUIController);
@@ -338,24 +545,14 @@ SampleManager::SampleManager(DeviceManager* pDeviceManager)
(static_cast<ISampleController*>(c))->setManager(this);
}
- m_config.sampleName = L"";
- m_config.assetsFile = "";
-
- m_config.additionalResourcesDir.clear();
- m_config.additionalResourcesDir.push_back("../resources");
- m_config.additionalResourcesDir.push_back("../../../../bin/resources");
-
- m_config.additionalAssetList.models.clear();
- m_config.additionalAssetList.boxes.clear();
- m_config.additionalAssetList.composites.clear();
-
- m_fTool = new BlastFractureTool(loggingCallback);
+ m_fTool = new BlastFractureTool();
m_fractureExecutor = nullptr;
setFractureExecutor(&sVoronoiFracture);
m_pCurBlastAsset = nullptr;
m_nCurFamilyIndex = -1;
+ EnableSimulating(false);
}
SampleManager::~SampleManager()
@@ -366,6 +563,7 @@ SampleManager::~SampleManager()
delete m_sceneController;
delete m_damageToolController;
delete m_selectionToolController;
+ delete m_explodeToolController;
delete m_gizmoToolController;
delete m_editionToolController;
delete m_sampleController;
@@ -378,34 +576,36 @@ int SampleManager::init()
Application& app = *m_pApplication;
app.init();
- m_ToolType = BTT_Num;
- setBlastToolType(BTT_Edit);
+ m_damageToolController->DisableController();
+ m_selectionToolController->EnableController();
+ m_explodeToolController->DisableController();
+ m_gizmoToolController->DisableController();
+ BlastPlugin::Inst().GetMainToolbar()->updateCheckIconsStates();
+
+ EnableSimulating(false);
return 0;
}
int SampleManager::run()
{
- if (m_bNeedConfig)
- {
- getSceneController().onSampleStop();
- getSceneController().onSampleStart();
-
- _setSourceAsset();
-
- m_bNeedConfig = false;
- m_bNeedRefreshTree = true;
- }
+ m_physXController->setPlaneVisible(AppMainWindow::Inst().m_bShowPlane);
Application& app = *m_pApplication;
app.run();
std::vector<std::string>::iterator itStr;
std::vector<Renderable*>::iterator itRenderable;
+ std::map<std::string, RenderMaterial*>::iterator itRenderMaterial;
for (itStr = m_NeedDeleteRenderMaterials.begin(); itStr != m_NeedDeleteRenderMaterials.end(); itStr++)
{
- std::string materialName = *itStr;
- RenderMaterial* pRenderMaterial = m_RenderMaterialMap[materialName];
+ itRenderMaterial = m_RenderMaterialMap.find(*itStr);
+ if (itRenderMaterial == m_RenderMaterialMap.end())
+ {
+ continue;
+ }
+ RenderMaterial* pRenderMaterial = itRenderMaterial->second;
+
std::vector<Renderable*>& renderables = pRenderMaterial->getRelatedRenderables();
for (itRenderable = renderables.begin(); itRenderable != renderables.end(); itRenderable++)
{
@@ -413,12 +613,12 @@ int SampleManager::run()
pRenderable->setMaterial(*RenderMaterial::getDefaultRenderMaterial());
}
- removeRenderMaterial(materialName);
+ delete pRenderMaterial;
+ pRenderMaterial = nullptr;
+ m_RenderMaterialMap.erase(itRenderMaterial);
}
m_NeedDeleteRenderMaterials.clear();
- MaterialLibraryPanel::ins()->deleteMaterials();
-
return 0;
}
@@ -436,161 +636,360 @@ int SampleManager::free()
Application& app = *m_pApplication;
app.free();
- /*
- std::vector<AssetList::ModelAsset>& modelAssets = m_config.additionalAssetList.models;
- std::vector<AssetList::ModelAsset>::iterator it;
- char filename[50];
- for (it = modelAssets.begin(); it != modelAssets.end(); it++)
+ return 0;
+}
+
+bool SampleManager::createAsset(
+ BlastAssetModelSimple** ppBlastAsset,
+ std::vector<Nv::Blast::Mesh*>& meshes,
+ std::vector<int32_t>& parentIds,
+ std::vector<bool>& supports,
+ std::vector<bool>& statics,
+ std::vector<uint8_t>& joints,
+ std::vector<uint32_t>& worlds)
+{
+ m_fTool->setSourceMeshes(meshes, parentIds);
+ m_fTool->finalizeFracturing();
+
+ _createAsset(ppBlastAsset, supports, statics, joints, worlds);
+
+ return true;
+}
+
+bool SampleManager::saveAsset(BlastAsset* pBlastAsset)
+{
+ if (pBlastAsset == nullptr)
{
- AssetList::ModelAsset& m = *it;
+ return false;
+ }
+
+ AssetList::ModelAsset& desc = m_AssetDescMap[pBlastAsset];
+
+ PhysXController& pc = getPhysXController();
+ BlastController& bc = getBlastController();
+ physics = &pc.getPhysics();
+ foundation = &physics->getFoundation();
+ cooking = &pc.getCooking();
+ physicsManager = &bc.getExtPxManager();
- sprintf(filename, "../../../../bin/resources/models/%s.bpxa", m.id.c_str());
- DeleteFileA(filename);
+ std::string outDir = GlobalSettings::Inst().m_projectFileDir;
+
+ std::string outBlastFilePath = GlobalSettings::MakeFileName(outDir.c_str(), std::string(desc.name + ".blast").c_str());
+ const ExtPxAsset* asset = pBlastAsset->getPxAsset();
+ if (asset == nullptr)
+ {
+ return false;
+ }
+ saveExtAsset(outDir, std::string(desc.name + ".blast"), asset);
- sprintf(filename, "../../../../bin/resources/models/%s.mtl", m.id.c_str());
- DeleteFileA(filename);
+ m_fTool->setSourceAsset(pBlastAsset);
+ m_fTool->finalizeFracturing();
- sprintf(filename, "../../../../bin/resources/models/%s.obj", m.id.c_str());
- DeleteFileA(filename);
+ size_t nChunkListSize = m_fTool->getChunkCount();
+ std::vector<std::shared_ptr<Triangle> > chunkMeshes(nChunkListSize);
+ std::vector<uint32_t> chunkMeshesTriangleCount(nChunkListSize);
+ std::vector<bool> isSupport(nChunkListSize);
+ for (uint32_t i = 0; i < nChunkListSize; ++i)
+ {
+ chunkMeshesTriangleCount[i] = m_fTool->getBaseMesh(i, chunkMeshes[i]);
+ isSupport[i] = m_fTool->getChunkInfo(i).isLeaf;
}
- */
- return 0;
-}
+ BlastBondGenerator bondGenerator(cooking, &physics->getPhysicsInsertionCallback());
+ BondGenerationConfig cnf;
+ cnf.bondMode = BondGenerationConfig::AVERAGE;
+ std::vector<NvBlastChunkDesc> chunkDesc;
+ std::vector<NvBlastBondDesc> bondDescs;
+ bondGenerator.buildDescFromInternalFracture(m_fTool, isSupport, bondDescs, chunkDesc);
+ const uint32_t chunkCount = static_cast<uint32_t>(chunkDesc.size());
+ const uint32_t bondCount = static_cast<uint32_t>(bondDescs.size());
+ if (bondCount == 0)
+ {
+ std::cout << "Can't create bonds descriptors..." << std::endl;
+ }
-void SampleManager::addModelAsset(std::string path, std::string file, bool isSkinned, physx::PxTransform transform, bool clear)
-{
- if (clear)
+ std::vector<uint32_t> chunkReorderInvMap;
{
- //m_config.additionalAssetList.models.clear();
- //clearScene();
- AppMainWindow::Inst().menu_clearScene();
- GlobalSettings::Inst().m_projectFileDir = path;
- GlobalSettings::Inst().m_projectFileName = file;
- QFileInfo fileInfo(file.c_str());
- std::string ext = fileInfo.suffix().toUtf8().data();
- if (ext.length() < 1)
- GlobalSettings::Inst().m_projectFileName += ".blastProj";
+ std::vector<uint32_t> chunkReorderMap(chunkCount);
+ std::vector<char> scratch(chunkCount * sizeof(NvBlastChunkDesc));
+ NvBlastEnsureAssetExactSupportCoverage(chunkDesc.data(), chunkCount, scratch.data(), loggingCallback);
+ NvBlastBuildAssetDescChunkReorderMap(chunkReorderMap.data(), chunkDesc.data(), chunkCount, scratch.data(), loggingCallback);
+ NvBlastApplyAssetDescChunkReorderMapInPlace(chunkDesc.data(), chunkCount, bondDescs.data(), bondCount, chunkReorderMap.data(), true, scratch.data(), loggingCallback);
+ chunkReorderInvMap.resize(chunkReorderMap.size());
+ Nv::Blast::invertMap(chunkReorderInvMap.data(), chunkReorderMap.data(), static_cast<unsigned int>(chunkReorderMap.size()));
}
- else
+
+ std::vector<std::vector<Triangle>> resultGeometry(nChunkListSize);
+ for (uint32_t i = 0; i < nChunkListSize; ++i)
{
- std::vector<AssetList::ModelAsset>& modelAssets = m_config.additionalAssetList.models;
- std::vector<AssetList::ModelAsset>::iterator it = modelAssets.begin();
- for (; it != modelAssets.end(); it++)
- {
- AssetList::ModelAsset& m = *it;
- if (m.id == file)
- {
- modelAssets.erase(it);
- break;
- }
- }
+ uint32_t chunkIndex = chunkReorderInvMap[i];
+ resultGeometry[chunkIndex].resize(chunkMeshesTriangleCount[i]);
+ memcpy(resultGeometry[chunkIndex].data(), chunkMeshes[i].get(), chunkMeshesTriangleCount[i] * sizeof(Triangle));
}
- AssetList::ModelAsset modelAsset;
- modelAsset.name = file;
- modelAsset.id = file;
- modelAsset.file = file;
- modelAsset.isSkinned = isSkinned;
- modelAsset.transform = transform;
+ saveFractureToObj(resultGeometry, desc.name, outDir);
- m_config.additionalAssetList.models.push_back(modelAsset);
+ char message[MAX_PATH];
+ sprintf(message, "Blast file %s was saved.", outBlastFilePath.c_str());
+ output(message);
- m_bNeedConfig = true;
+ return true;
}
-bool SampleManager::createAsset(
- std::string path,
- std::string assetName,
- std::vector<physx::PxVec3>& positions,
- std::vector<physx::PxVec3>& normals,
- std::vector<physx::PxVec2>& uv,
- std::vector<unsigned int>& indices,
- bool fracture)
+#include "fbxsdk.h"
+
+uint32_t currentDepth;
+bool bOutputFBXAscii = true;
+
+void PxVec3ToFbx(physx::PxVec3& inVector, FbxVector4& outVector)
{
- PhysXController& pc = getPhysXController();
- BlastController& bc = getBlastController();
+ outVector[0] = inVector.x;
+ outVector[1] = inVector.y;
+ outVector[2] = inVector.z;
+ outVector[3] = 0;
+}
- physics = &pc.getPhysics();
- foundation = &physics->getFoundation();
- cooking = &pc.getCooking();
- physicsManager = &bc.getExtPxManager();
+void PxVec2ToFbx(physx::PxVec2& inVector, FbxVector2& outVector)
+{
+ outVector[0] = inVector.x;
+ outVector[1] = inVector.y;
+}
- std::vector<Nv::Blast::Mesh* > meshes;
- PxVec3* nr = (!normals.empty()) ? normals.data() : 0;
- PxVec2* uvp = (!uv.empty()) ? uv.data() : 0;
- Nv::Blast::Mesh* sourceMesh = new Nv::Blast::Mesh(positions.data(), nr, uvp, static_cast<uint32_t>(positions.size()),
- indices.data(), static_cast<uint32_t>(indices.size()));
- meshes.push_back(sourceMesh);
+void VertexToFbx(Nv::Blast::Vertex& vert, FbxVector4& outVertex, FbxVector4& outNormal, FbxVector2& outUV)
+{
+ PxVec3ToFbx(vert.p, outVertex);
+ PxVec3ToFbx(vert.n, outNormal);
+ PxVec2ToFbx(vert.uv[0], outUV);
+}
- m_fractureExecutor->setSourceMesh(sourceMesh);
- if (fracture)
+uint32_t createChunkRecursive(FbxManager* sdkManager, uint32_t currentCpIdx, uint32_t chunkIndex, FbxNode *meshNode, FbxNode* parentNode, FbxSkin* skin, const NvBlastAsset* asset, std::vector<std::vector<Nv::Blast::Triangle>> chunksGeometry)
+{
+ currentDepth++;
+
+ auto chunks = NvBlastAssetGetChunks(asset, nullptr);
+ const NvBlastChunk* chunk = &chunks[chunkIndex];
+ auto triangles = chunksGeometry[chunkIndex];
+ physx::PxVec3 centroid = physx::PxVec3(chunk->centroid[0], chunk->centroid[1], chunk->centroid[2]);
+
+ std::ostringstream namestream;
+
+ //mesh->InitTextureUV(triangles.size() * 3);
+
+ std::ostringstream().swap(namestream); // Swap namestream with a default constructed ostringstream
+ namestream << "bone_" << chunkIndex;
+ std::string boneName = namestream.str();
+
+ FbxSkeleton* skelAttrib;
+ if (chunk->parentChunkIndex == UINT32_MAX)
{
- m_fractureExecutor->execute();
- m_fractureExecutor = &sVoronoiFracture;
+ skelAttrib = FbxSkeleton::Create(sdkManager, "SkelRootAttrib");
+ skelAttrib->SetSkeletonType(FbxSkeleton::eRoot);
+
+ // Change the centroid to origin
+ centroid = physx::PxVec3(0.0f);
}
else
{
- m_fTool->finalizeFracturing();
+ skelAttrib = FbxSkeleton::Create(sdkManager, boneName.c_str());
+ skelAttrib->SetSkeletonType(FbxSkeleton::eLimbNode);
}
- std::string outDir = path;
- _createAsset(assetName, outDir, meshes);
+ skelAttrib->Size.Set(1.0); // What's this for?
- delete sourceMesh;
- sourceMesh = 0;
- m_bNeedConfig = true;
+ FbxNode* boneNode = FbxNode::Create(sdkManager, boneName.c_str());
+ boneNode->SetNodeAttribute(skelAttrib);
- return true;
-}
+ auto mat = parentNode->EvaluateGlobalTransform().Inverse();
-bool SampleManager::createAsset(
- const std::string& path,
- const std::string& assetName,
- const std::vector<Nv::Blast::Mesh* >& meshes,
- bool fracture)
-{
- PhysXController& pc = getPhysXController();
- BlastController& bc = getBlastController();
+ FbxVector4 vec(centroid.x, centroid.y, centroid.z, 0);
+ FbxVector4 c2 = mat.MultT(vec);
- physics = &pc.getPhysics();
- foundation = &physics->getFoundation();
- cooking = &pc.getCooking();
- physicsManager = &bc.getExtPxManager();
+ boneNode->LclTranslation.Set(c2);
+
+ parentNode->AddChild(boneNode);
- if (meshes.size() == 1)
+ std::ostringstream().swap(namestream); // Swap namestream with a default constructed ostringstream
+ namestream << "cluster_" << std::setw(5) << std::setfill('0') << chunkIndex;
+ std::string clusterName = namestream.str();
+
+ FbxCluster* cluster = FbxCluster::Create(sdkManager, clusterName.c_str());
+ cluster->SetTransformMatrix(FbxAMatrix());
+ cluster->SetLink(boneNode);
+ cluster->SetLinkMode(FbxCluster::eTotalOne);
+
+ skin->AddCluster(cluster);
+
+ FbxMesh* mesh = static_cast<FbxMesh*>(meshNode->GetNodeAttribute());
+
+ FbxVector4* controlPoints = mesh->GetControlPoints();
+ auto geNormal = mesh->GetElementNormal();
+ auto geUV = mesh->GetElementUV("diffuseElement");
+ FbxGeometryElementMaterial* matElement = mesh->GetElementMaterial();
+
+ auto addVert = [&](Nv::Blast::Vertex vert, int controlPointIdx)
{
- Nv::Blast::Mesh* sourceMesh = meshes[0];
- m_fractureExecutor->setSourceMesh(sourceMesh);
- if (fracture)
+ FbxVector4 vertex;
+ FbxVector4 normal;
+ FbxVector2 uv;
+
+ VertexToFbx(vert, vertex, normal, uv);
+
+ controlPoints[controlPointIdx] = vertex;
+ geNormal->GetDirectArray().Add(normal);
+ geUV->GetDirectArray().Add(uv);
+ // Add this control point to the bone with weight 1.0
+ cluster->AddControlPointIndex(controlPointIdx, 1.0);
+ };
+
+ uint32_t cpIdx = 0;
+ uint32_t polyCount = mesh->GetPolygonCount();
+ for (auto tri : triangles)
+ {
+ addVert(tri.a, currentCpIdx + cpIdx + 0);
+ addVert(tri.b, currentCpIdx + cpIdx + 1);
+ addVert(tri.c, currentCpIdx + cpIdx + 2);
+
+ mesh->BeginPolygon();
+ mesh->AddPolygon(currentCpIdx + cpIdx + 0);
+ mesh->AddPolygon(currentCpIdx + cpIdx + 1);
+ mesh->AddPolygon(currentCpIdx + cpIdx + 2);
+ mesh->EndPolygon();
+ if (tri.userInfo == 0)
{
- m_fractureExecutor->execute();
- m_fractureExecutor = &sVoronoiFracture;
+ matElement->GetIndexArray().SetAt(polyCount, 0);
}
else
{
- m_fTool->finalizeFracturing();
+ matElement->GetIndexArray().SetAt(polyCount, 1);
}
+ polyCount++;
+ cpIdx += 3;
}
- std::string outDir = path;
- _createAsset(assetName, outDir, meshes);
+ mat = meshNode->EvaluateGlobalTransform();
+ cluster->SetTransformMatrix(mat);
+
+ mat = boneNode->EvaluateGlobalTransform();
+ cluster->SetTransformLinkMatrix(mat);
+
+ uint32_t addedCps = static_cast<uint32_t>(triangles.size() * 3);
+
+ for (uint32_t i = chunk->firstChildIndex; i < chunk->childIndexStop; i++)
+ {
+ addedCps += createChunkRecursive(sdkManager, currentCpIdx + addedCps, i, meshNode, boneNode, skin, asset, chunksGeometry);
+ }
+
+ return addedCps;
+}
- m_bNeedConfig = true;
+bool finalizeFbxAndSave(FbxManager* sdkManager, FbxScene* scene, FbxSkin* skin, const std::string& outputFilePath)
+{
+ // Store the bind pose
+
+ std::unordered_set<FbxNode*> clusterNodes;
+
+ std::function<void(FbxNode*)> addRecursively = [&](FbxNode* node)
+ {
+ if (node)
+ {
+ addRecursively(node->GetParent());
+
+ clusterNodes.insert(node);
+ }
+ };
+
+ for (uint32_t i = 0; i < (uint32_t)skin->GetClusterCount(); i++)
+ {
+ FbxNode* clusterNode = skin->GetCluster(i)->GetLink();
+
+ addRecursively(clusterNode);
+ }
+
+ assert(clusterNodes.size() > 0);
+
+ FbxPose* pose = FbxPose::Create(sdkManager, "BasePose");
+ pose->SetIsBindPose(true);
+
+ for (auto node : clusterNodes)
+ {
+ FbxMatrix bindMat = node->EvaluateGlobalTransform();
+
+ pose->Add(node, bindMat);
+ }
+
+ scene->AddPose(pose);
+
+ FbxExporter* exporter = FbxExporter::Create(sdkManager, "Scene Exporter");
+
+ int lFormat;
+
+ if (bOutputFBXAscii)
+ {
+ lFormat = sdkManager->GetIOPluginRegistry()->FindWriterIDByDescription("FBX ascii (*.fbx)");
+ }
+ else
+ {
+ lFormat = sdkManager->GetIOPluginRegistry()->FindWriterIDByDescription("FBX binary (*.fbx)");
+ }
+
+ bool exportStatus = exporter->Initialize(outputFilePath.c_str(), lFormat, sdkManager->GetIOSettings());
+
+ if (!exportStatus)
+ {
+ std::cerr << "Call to FbxExporter::Initialize failed" << std::endl;
+ std::cerr << "Error returned: " << exporter->GetStatus().GetErrorString() << std::endl;
+ return false;
+ }
+
+ exportStatus = exporter->Export(scene);
+
+ if (!exportStatus)
+ {
+ auto fbxStatus = exporter->GetStatus();
+
+ std::cerr << "Call to FbxExporter::Export failed" << std::endl;
+ std::cerr << "Error returned: " << fbxStatus.GetErrorString() << std::endl;
+ return false;
+ }
return true;
}
-bool SampleManager::saveAsset()
+bool SampleManager::exportAsset()
{
if (m_pCurBlastAsset == nullptr)
{
+ viewer_err("Please select one asset instance before saving!");
+ return false;
+ }
+
+ std::map<BlastAsset*, AssetList::ModelAsset>::iterator itADM = m_AssetDescMap.find(m_pCurBlastAsset);
+ if (itADM == m_AssetDescMap.end())
+ {
+ viewer_err("Fails to find out the selected asset instance in current project!");
+ return false;
+ }
+
+ BPParams& projectParams = BlastProject::ins().getParams();
+
+ AssetList::ModelAsset& desc = itADM->second;
+
+ BPPAssetArray& assetArray = projectParams.blast.blastAssets;
+ BPPAsset asset;
+ int aaas = 0;
+ for (; aaas < assetArray.arraySizes[0]; aaas++)
+ {
+ asset = assetArray.buf[aaas];
+ std::string assetname = asset.name;
+ if (assetname == desc.name)
+ break;
+ }
+ if (aaas == assetArray.arraySizes[0])
+ {
return false;
}
- AssetList::ModelAsset& desc = m_AssetDescMap[m_pCurBlastAsset];
-
PhysXController& pc = getPhysXController();
BlastController& bc = getBlastController();
physics = &pc.getPhysics();
@@ -600,29 +999,17 @@ bool SampleManager::saveAsset()
std::string outDir = GlobalSettings::Inst().m_projectFileDir;
- std::string outBlastFilePath = GlobalSettings::MakeFileName(outDir.c_str(), std::string(desc.name + ".bpxa").c_str());
- const ExtPxAsset* asset = m_pCurBlastAsset->getPxAsset();
- if (asset == nullptr)
- {
- return false;
- }
- physx::PsFileBuffer fileBuf(outBlastFilePath.c_str(), physx::PxFileBuf::OPEN_WRITE_ONLY);
- if (!asset->serialize(fileBuf, *cooking))
- {
- return false;
- }
- fileBuf.close();
-
m_fTool->setSourceAsset(m_pCurBlastAsset);
m_fTool->finalizeFracturing();
- size_t nChunkListSize = m_fTool->getChunkList().size();
- std::vector<std::vector<Triangle> > chunkMeshes(nChunkListSize);
+ size_t nChunkListSize = m_fTool->getChunkCount();
+ std::vector<std::shared_ptr<Triangle> > chunkMeshes(nChunkListSize);
+ std::vector<uint32_t> chunkMeshesTriangleCount(nChunkListSize);
std::vector<bool> isSupport(nChunkListSize);
for (uint32_t i = 0; i < nChunkListSize; ++i)
{
- m_fTool->getBaseMesh(i, chunkMeshes[i]);
- isSupport[i] = m_fTool->getChunkList()[i].isLeaf;
+ chunkMeshesTriangleCount[i] = m_fTool->getBaseMesh(i, chunkMeshes[i]);
+ isSupport[i] = m_fTool->getChunkInfo(i).isLeaf;
}
BlastBondGenerator bondGenerator(cooking, &physics->getPhysicsInsertionCallback());
@@ -644,27 +1031,212 @@ bool SampleManager::saveAsset()
std::vector<char> scratch(chunkCount * sizeof(NvBlastChunkDesc));
NvBlastEnsureAssetExactSupportCoverage(chunkDesc.data(), chunkCount, scratch.data(), loggingCallback);
NvBlastBuildAssetDescChunkReorderMap(chunkReorderMap.data(), chunkDesc.data(), chunkCount, scratch.data(), loggingCallback);
- NvBlastApplyAssetDescChunkReorderMapInplace(chunkDesc.data(), chunkCount, bondDescs.data(), bondCount, chunkReorderMap.data(), scratch.data(), loggingCallback);
+ NvBlastApplyAssetDescChunkReorderMapInPlace(chunkDesc.data(), chunkCount, bondDescs.data(), bondCount, chunkReorderMap.data(), true, scratch.data(), loggingCallback);
chunkReorderInvMap.resize(chunkReorderMap.size());
Nv::Blast::invertMap(chunkReorderInvMap.data(), chunkReorderMap.data(), static_cast<unsigned int>(chunkReorderMap.size()));
}
- std::vector<std::vector<Triangle>> resultGeometry(chunkMeshes.size());
- for (uint32_t i = 0; i < chunkMeshes.size(); ++i)
+ std::vector<std::vector<Triangle>> resultGeometry(nChunkListSize);
+ for (uint32_t i = 0; i < nChunkListSize; ++i)
{
uint32_t chunkIndex = chunkReorderInvMap[i];
- resultGeometry[chunkIndex] = chunkMeshes[i];
+ resultGeometry[chunkIndex].resize(chunkMeshesTriangleCount[i]);
+ memcpy(resultGeometry[chunkIndex].data(), chunkMeshes[i].get(), chunkMeshesTriangleCount[i] * sizeof(Triangle));
}
- saveFractureToObj(resultGeometry, desc.name, outDir);
+ if (asset.exportFBX)
+ {
+ FbxManager* sdkManager = FbxManager::Create();
+
+ FbxIOSettings* ios = FbxIOSettings::Create(sdkManager, IOSROOT);
+ // Set some properties on the io settings
+
+ sdkManager->SetIOSettings(ios);
+
+ sdkManager->GetIOSettings()->SetBoolProp(EXP_ASCIIFBX, bOutputFBXAscii);
+
+ FbxScene* scene = FbxScene::Create(sdkManager, "Export Scene");
+ /*
+ if (getConvertToUE4())
+ {
+ FbxAxisSystem::EFrontVector FrontVector = (FbxAxisSystem::EFrontVector) - FbxAxisSystem::eParityOdd;
+ const FbxAxisSystem UnrealZUp(FbxAxisSystem::eZAxis, FrontVector, FbxAxisSystem::eRightHanded);
+
+ scene->GetGlobalSettings().SetAxisSystem(UnrealZUp);
+ }
+ */
+ // Otherwise default to Maya defaults
+
+ FbxMesh* mesh = FbxMesh::Create(sdkManager, "meshgeo");
+
+ FbxGeometryElementNormal* geNormal = mesh->CreateElementNormal();
+ geNormal->SetMappingMode(FbxGeometryElement::eByControlPoint);
+ geNormal->SetReferenceMode(FbxGeometryElement::eDirect);
+
+ FbxGeometryElementUV* geUV = mesh->CreateElementUV("diffuseElement");
+ geUV->SetMappingMode(FbxGeometryElement::eByPolygonVertex);
+ geUV->SetReferenceMode(FbxGeometryElement::eDirect);
+
+ // Get the triangles count for all of the mesh parts
+
+ size_t triangleCount = 0;
+ for (auto triangles : resultGeometry)
+ {
+ triangleCount += triangles.size();
+ }
+
+ mesh->InitControlPoints((int)triangleCount * 3);
- std::string saveInfo = outBlastFilePath + " saved successfully\n";
- output(saveInfo.c_str());
+ FbxNode* meshNode = FbxNode::Create(scene, "meshnode");
+ meshNode->SetNodeAttribute(mesh);
+ meshNode->SetShadingMode(FbxNode::eTextureShading);
+
+ FbxNode* lRootNode = scene->GetRootNode();
+ lRootNode->AddChild(meshNode);
+
+ FbxSkin* skin = FbxSkin::Create(sdkManager, "Skin of the thing");
+ skin->SetGeometry(mesh);
+
+ mesh->AddDeformer(skin);
+
+ // Add a material otherwise UE4 freaks out on import
+
+ FbxGeometryElementMaterial* matElement = mesh->CreateElementMaterial();
+ matElement->SetMappingMode(FbxGeometryElement::eByPolygon);
+ matElement->SetReferenceMode(FbxGeometryElement::eIndexToDirect);
+
+ FbxSurfacePhong* material = FbxSurfacePhong::Create(sdkManager, "FirstExportMaterial");
+
+ material->Diffuse.Set(FbxDouble3(1.0, 1.0, 0));
+ material->DiffuseFactor.Set(1.0);
+
+ meshNode->AddMaterial(material);
+
+ FbxSurfacePhong* material2 = FbxSurfacePhong::Create(sdkManager, "SecondExportMaterial");
+
+ material2->Diffuse.Set(FbxDouble3(1.0, 0.0, 1.0));
+ material2->DiffuseFactor.Set(1.0);
+
+ meshNode->AddMaterial(material2);
+
+ const ExtPxAsset* pExtPxAsset = m_pCurBlastAsset->getPxAsset();
+ if (pExtPxAsset == nullptr)
+ {
+ return false;
+ }
+
+ const TkAsset& tkAsset = pExtPxAsset->getTkAsset();
+ const NvBlastAsset* pAssetLL = tkAsset.getAssetLL();
+ uint32_t chunkCount = NvBlastAssetGetChunkCount(pAssetLL, nullptr);
+
+ auto chunks = NvBlastAssetGetChunks(pAssetLL, nullptr);
+
+ currentDepth = 0;
+ uint32_t cpIdx = 0;
+ for (uint32_t i = 0; i < chunkCount; i++)
+ {
+ const NvBlastChunk* chunk = &chunks[i];
+
+ if (chunk->parentChunkIndex == UINT32_MAX)
+ {
+ uint32_t addedCps = createChunkRecursive(sdkManager, cpIdx, i, meshNode, lRootNode, skin, pAssetLL, resultGeometry);
+
+ cpIdx += addedCps;
+ }
+ }
+
+ std::string outputFilePath = GlobalSettings::MakeFileName(outDir.c_str(), asset.fbx.buf);
+ finalizeFbxAndSave(sdkManager, scene, skin, outputFilePath);
+
+ sdkManager->Destroy();
+ sdkManager = nullptr;
+
+ std::string info = outputFilePath + " is saved.";
+ viewer_info(info.c_str());
+ }
+
+ if (asset.exportOBJ)
+ {
+ std::string filename = asset.obj.buf;
+ filename = filename.substr(0, filename.find_last_of('.'));
+ saveFractureToObj(resultGeometry, filename, outDir);
+
+ std::string outputFilePath = GlobalSettings::MakeFileName(outDir.c_str(), asset.obj.buf);
+ std::string info = outputFilePath + " is saved.";
+ viewer_info(info.c_str());
+ }
+
+ if (asset.exportBPXA)
+ {
+ std::string outputFilePath = GlobalSettings::MakeFileName(outDir.c_str(), asset.bpxa.buf);
+ const ExtPxAsset* pExtPxAsset = m_pCurBlastAsset->getPxAsset();
+ if (pExtPxAsset == nullptr)
+ {
+ return false;
+ }
+ saveExtAsset(outDir, std::string(asset.bpxa.buf), pExtPxAsset);
+
+ std::string info = outputFilePath + " is saved.";
+ viewer_info(info.c_str());
+ }
+
+ if (asset.exportCollision)
+ {
+ SampleManager* pSampleManager = SampleManager::ins();
+ PhysXController& physXController = pSampleManager->getPhysXController();
+ PxPhysics& physics = physXController.getPhysics();
+ PxScene& scene = physXController.getPhysXScene();
+
+ std::string outputFilePath = GlobalSettings::MakeFileName(outDir.c_str(), asset.collision.buf);
+ physXController.ExportCollisionRepX(outputFilePath.c_str(), &physics, &scene, false);
+
+ std::string info = outputFilePath + " is saved.";
+ viewer_info(info.c_str());
+ }
+
+ if (asset.exportTKAsset)
+ {
+ std::string outputFilePath = GlobalSettings::MakeFileName(outDir.c_str(), asset.tkasset.buf);
+ const ExtPxAsset* pExtPxAsset = m_pCurBlastAsset->getPxAsset();
+ if (pExtPxAsset == nullptr)
+ {
+ return false;
+ }
+
+ const TkAsset& tkAsset = pExtPxAsset->getTkAsset();
+
+ saveTkAsset(outDir, std::string(asset.tkasset.buf), &tkAsset);
+
+ std::string info = outputFilePath + " is saved.";
+ viewer_info(info.c_str());
+ }
+
+ if (asset.exportLLAsset)
+ {
+ std::string outputFilePath = GlobalSettings::MakeFileName(outDir.c_str(), asset.llasset.buf);
+ const ExtPxAsset* pExtPxAsset = m_pCurBlastAsset->getPxAsset();
+ if (pExtPxAsset == nullptr)
+ {
+ return false;
+ }
+
+ const TkAsset& tkAsset = pExtPxAsset->getTkAsset();
+ const NvBlastAsset* pAssetLL = tkAsset.getAssetLL();
+
+ saveLlAsset(outDir, std::string(asset.llasset.buf), pAssetLL);
+
+ std::string info = outputFilePath + " is saved.";
+ viewer_info(info.c_str());
+ }
return true;
}
-bool SampleManager::fractureAsset(std::string& path, std::string& assetName, const BlastAsset* pBlastAsset, int32_t chunkId)
+void SampleManager::_createAsset(BlastAssetModelSimple** ppBlastAsset,
+ std::vector<bool>& supports,
+ std::vector<bool>& statics,
+ std::vector<uint8_t>& joints,
+ std::vector<uint32_t>& worlds)
{
PhysXController& pc = getPhysXController();
BlastController& bc = getBlastController();
@@ -673,35 +1245,38 @@ bool SampleManager::fractureAsset(std::string& path, std::string& assetName, con
foundation = &physics->getFoundation();
cooking = &pc.getCooking();
physicsManager = &bc.getExtPxManager();
-
- m_fractureExecutor->setSourceAsset(pBlastAsset);
- m_fractureExecutor->setTargetChunk(chunkId);
- m_fractureExecutor->execute();
- m_fractureExecutor = &sVoronoiFracture;
-
- std::string outDir = path;
-
- std::string outBlastFilePath = GlobalSettings::MakeFileName(outDir.c_str(), std::string(assetName + ".bpxa").c_str());
+ TkFramework& tk = bc.getTkFramework();
std::vector<NvBlastChunkDesc> chunkDesc;
std::vector<NvBlastBondDesc> bondDescs;
- std::vector<std::vector<Triangle> > chunkMeshes;
+ std::vector<std::shared_ptr<Triangle> > chunkMeshes;
+ std::vector<uint32_t> chunkMeshesTriangleCount(nChunkListSize);
std::vector<bool> isSupport;
- size_t nChunkListSize = m_fTool->getChunkList().size();
+ size_t nChunkListSize = m_fTool->getChunkCount();
chunkMeshes.resize(nChunkListSize);
isSupport.resize(nChunkListSize);
for (uint32_t i = 0; i < nChunkListSize; ++i)
{
- m_fTool->getBaseMesh(i, chunkMeshes[i]);
- isSupport[i] = m_fTool->getChunkList()[i].isLeaf;
+ chunkMeshesTriangleCount[i] = m_fTool->getBaseMesh(i, chunkMeshes[i]);
+ isSupport[i] = supports.size() == 0 ? m_fTool->getChunkInfo(i).isLeaf : supports[i];
}
BlastBondGenerator bondGenerator(cooking, &physics->getPhysicsInsertionCallback());
-
- BondGenerationConfig cnf;
- cnf.bondMode = BondGenerationConfig::AVERAGE;
bondGenerator.buildDescFromInternalFracture(m_fTool, isSupport, bondDescs, chunkDesc);
+ bondDescs.clear();
+ bondGenerator.bondsFromPrefractured(chunkMeshes, isSupport, bondDescs);
+ int bondDescsSize = bondDescs.size();
+ if (bondDescsSize == worlds.size())
+ {
+ for (int bds = 0; bds < bondDescsSize; bds++)
+ {
+ if (worlds[bds] == 0xFFFFFFFF)
+ {
+ bondDescs[bds].chunkIndices[1] = worlds[bds];
+ }
+ }
+ }
const uint32_t chunkCount = static_cast<uint32_t>(chunkDesc.size());
const uint32_t bondCount = static_cast<uint32_t>(bondDescs.size());
@@ -717,23 +1292,24 @@ bool SampleManager::fractureAsset(std::string& path, std::string& assetName, con
std::vector<char> scratch(chunkCount * sizeof(NvBlastChunkDesc));
NvBlastEnsureAssetExactSupportCoverage(chunkDesc.data(), chunkCount, scratch.data(), loggingCallback);
NvBlastBuildAssetDescChunkReorderMap(chunkReorderMap.data(), chunkDesc.data(), chunkCount, scratch.data(), loggingCallback);
- NvBlastApplyAssetDescChunkReorderMapInplace(chunkDesc.data(), chunkCount, bondDescs.data(), bondCount, chunkReorderMap.data(), scratch.data(), loggingCallback);
+ NvBlastApplyAssetDescChunkReorderMapInPlace(chunkDesc.data(), chunkCount, bondDescs.data(), bondCount, chunkReorderMap.data(), true, scratch.data(), loggingCallback);
chunkReorderInvMap.resize(chunkReorderMap.size());
Nv::Blast::invertMap(chunkReorderInvMap.data(), chunkReorderMap.data(), static_cast<unsigned int>(chunkReorderMap.size()));
}
// get result geometry
- std::vector<std::vector<Triangle>> resultGeometry(chunkMeshes.size());
- for (uint32_t i = 0; i < chunkMeshes.size(); ++i)
+ std::vector<std::vector<Triangle>> resultGeometry(nChunkListSize);
+ for (uint32_t i = 0; i < nChunkListSize; ++i)
{
uint32_t chunkIndex = chunkReorderInvMap[i];
- resultGeometry[chunkIndex] = chunkMeshes[i];
+ resultGeometry[chunkIndex].resize(chunkMeshesTriangleCount[i]);
+ memcpy(resultGeometry[chunkIndex].data(), chunkMeshes[i].get(), chunkMeshesTriangleCount[i] * sizeof(Triangle));
}
// prepare physics data (convexes)
std::vector<ExtPxAssetDesc::ChunkDesc> pxChunks(chunkCount);
std::vector<ExtPxAssetDesc::SubchunkDesc> pxSubchunks;
- buildPxChunks(resultGeometry, pxChunks, pxSubchunks);
+ buildPxChunks(resultGeometry, pxChunks, pxSubchunks, statics);
// build and serialize ExtPhysicsAsset
ExtPxAssetDesc descriptor;
@@ -741,45 +1317,83 @@ bool SampleManager::fractureAsset(std::string& path, std::string& assetName, con
descriptor.bondDescs = bondDescs.data();
descriptor.chunkCount = chunkCount;
descriptor.chunkDescs = chunkDesc.data();
- descriptor.bondFlags = nullptr;
+ descriptor.bondFlags = joints.data();
descriptor.pxChunks = pxChunks.data();
- ExtPxAsset* asset = ExtPxAsset::create(descriptor, bc.getTkFramework());
+ ExtPxAsset* asset = ExtPxAsset::create(descriptor, tk);
if (asset == nullptr)
{
- return false;
+ return;
}
- physx::PsFileBuffer fileBuf(outBlastFilePath.c_str(), physx::PxFileBuf::OPEN_WRITE_ONLY);
- if (!asset->serialize(fileBuf, *cooking))
+ std::string tempFilePath = utils::GetTempFilePath();
+ QFileInfo tempFileInfo(tempFilePath.c_str());
+ std::string tempdir = QDir::toNativeSeparators(tempFileInfo.absoluteDir().absolutePath()).toLocal8Bit();
+ std::string tempfile = tempFileInfo.fileName().toLocal8Bit();
+ saveFractureToObj(resultGeometry, tempfile, tempdir);
+ std::string objFilePath = tempFilePath + ".obj";
+ std::string mtlFilePath = tempFilePath + ".mtl";
+ BlastModel* pBlastModel = BlastModel::loadFromFileTinyLoader(objFilePath.c_str());
+ DeleteFileA(tempFilePath.c_str());
+ DeleteFileA(objFilePath.c_str());
+ DeleteFileA(mtlFilePath.c_str());
+
+ *ppBlastAsset = new BlastAssetModelSimple(asset, pBlastModel, getRenderer());
+}
+
+BlastAsset* SampleManager::_replaceAsset(BlastAsset* pBlastAsset,
+ std::vector<bool>& supports,
+ std::vector<bool>& statics,
+ std::vector<uint8_t>& joints,
+ std::vector<uint32_t>& worlds)
+{
+ if (pBlastAsset == nullptr)
{
return false;
}
- fileBuf.close();
- asset->release();
- saveFractureToObj(resultGeometry, assetName, outDir);
+ BlastAsset* pCurBlastAsset = nullptr;
+ int nFamilyIndex = -1;
+ getCurrentSelectedInstance(&pCurBlastAsset, nFamilyIndex);
- m_bNeedConfig = true;
+ std::vector<BlastFamily*> familiesOld = m_AssetFamiliesMap[pBlastAsset];
+ int familiesSize = familiesOld.size();
+ std::vector<physx::PxTransform> transforms(familiesSize);
+ std::vector<std::string> extMaterials(familiesSize);
+ std::vector<std::string> intMaterials(familiesSize);
+ for (int fs = 0; fs < familiesSize; fs++)
+ {
+ transforms[fs] = familiesOld[fs]->getSettings().transform;
- return true;
-}
+ setCurrentSelectedInstance(pBlastAsset, fs);
+ getMaterialForCurrentFamily(extMaterials[fs], true);
+ getMaterialForCurrentFamily(intMaterials[fs], false);
+ }
-bool SampleManager::postProcessCurrentAsset()
-{
- std::vector<AssetList::ModelAsset>& models = m_config.additionalAssetList.models;
- if (models.size() < 0)
+ BlastAssetModelSimple* pBlastAssetNew;
+ _createAsset(&pBlastAssetNew, supports, statics, joints, worlds);
+
+ BlastAssetModelSimple* pBlastAssetOld = (BlastAssetModelSimple*)pBlastAsset;
+ AssetList::ModelAsset desc = m_AssetDescMap[pBlastAsset];
+ removeBlastAsset(pBlastAssetOld);
+ addBlastAsset(pBlastAssetNew, desc);
+
+ for (int fs = 0; fs < familiesSize; fs++)
{
- return true;
- }
+ addBlastFamily(pBlastAssetNew, transforms[fs]);
- std::string assetName = models.at(models.size() - 1).file;
- std::string outDir = GlobalSettings::Inst().m_projectFileDir;
- std::vector<Nv::Blast::Mesh* > meshes;
- _createAsset(assetName, outDir, meshes);
+ setCurrentSelectedInstance(pBlastAssetNew, fs);
- m_bNeedConfig = true;
+ setMaterialForCurrentFamily(extMaterials[fs], true);
+ setMaterialForCurrentFamily(intMaterials[fs], false);
+ }
- return true;
+ if (pCurBlastAsset == pBlastAsset)
+ {
+ pCurBlastAsset = pBlastAssetNew;
+ }
+ setCurrentSelectedInstance(pCurBlastAsset, nFamilyIndex);
+
+ return pBlastAssetNew;
}
std::vector<uint32_t> SampleManager::getCurrentSelectedChunks()
@@ -880,405 +1494,1664 @@ void SampleManager::setFractureExecutor(FractureExecutor* executor)
}
}
-void SampleManager::setBlastToolType(BlastToolType type)
+void SampleManager::EnableStepforward(bool bStepforward)
+{
+ m_stepforward = bStepforward;
+}
+
+void SampleManager::EnableSimulating(bool bSimulating)
{
- if (m_ToolType == type)
+ m_simulating = bSimulating;
+ m_stepforward = false;
+ m_physXController->setPaused(!m_simulating);
+
+ if (!m_simulating)
{
- getPhysXController().setPaused(type != BTT_Damage);
- return;
+ m_damageToolController->DisableController();
+#if 0
+ BlastSceneTree* pBlastSceneTree = BlastSceneTree::ins();
+ if (pBlastSceneTree)
+ {
+ pBlastSceneTree->hideAllChunks();
+ // make sure chunk0 shows.
+ std::vector<uint32_t> depths(1, 0);
+ pBlastSceneTree->setChunkVisible(depths, true);
+ // refresh in scene tree and viewport
+ //pBlastSceneTree->updateValues(false);
+ SampleManager::ins()->m_bNeedRefreshTree = true;
+ }
+#endif
}
+}
- // refresh selection
- bool needClear = true;
- bool currentGizmo = (m_ToolType >= BTT_Translate && m_ToolType <= BTT_Rotation);
- bool switchToGizmo = (type >= BTT_Translate && type <= BTT_Rotation);
- if (currentGizmo && switchToGizmo)
+#include <ViewerOutput.h>
+void SampleManager::output(const char* str)
+{
+ viewer_msg("%s", str);
+}
+
+void SampleManager::output(float value)
+{
+ viewer_msg("%f", value);
+}
+
+void SampleManager::output(physx::PxVec3& vec)
+{
+ viewer_msg("%f,%f,%f", vec.x, vec.y, vec.z);
+}
+
+void SampleManager::clearScene()
+{
+ m_gizmoToolController->resetPos();
+ /*
+ BPPAssetArray& assets = BlastProject::ins().getParams().blast.blastAssets;
+ int assetSize = assets.arraySizes[0];
+ for (int as = 0; as < assetSize; as++)
{
- needClear = false;
+ BPPAsset& asset = assets.buf[as];
+ BlastSceneTree::ins()->removeBlastInstances(asset);
+ BlastSceneTree::ins()->removeBlastAsset(asset);
}
- if (needClear)
+ BlastSceneTree::ins()->clearProjectile();
+ */
+ m_sceneController->ClearScene();
+
+ EnableSimulating(false);
+
+ std::map<std::string, RenderMaterial*>::iterator itRenderMaterial;
+ for (itRenderMaterial = m_RenderMaterialMap.begin();
+ itRenderMaterial != m_RenderMaterialMap.end(); itRenderMaterial++)
{
- getSelectionToolController().clearSelect();
- getGizmoToolController().resetPos();
+ RenderMaterial* pRenderMaterial = itRenderMaterial->second;
+ delete pRenderMaterial;
+ pRenderMaterial = nullptr;
}
+ m_RenderMaterialMap.clear();
- getDamageToolController().getPickPointer()->setHidden(type != BTT_Damage);
- getGizmoToolController().showAxisRenderables(switchToGizmo);
- getPhysXController().setPaused(type != BTT_Damage);
+ std::map<BlastAsset*, std::vector<BlastFamily*>>::iterator itAssetFamilies;
+ for (itAssetFamilies = m_AssetFamiliesMap.begin();
+ itAssetFamilies != m_AssetFamiliesMap.end(); itAssetFamilies++)
+ {
+ std::vector<BlastFamily*>& fs = itAssetFamilies->second;
+ fs.clear();
+ }
+ m_AssetFamiliesMap.clear();
+ m_AssetDescMap.clear();
+ m_instanceFamilyMap.clear();
+
+ physx::PxVec3 zero(0.0f, 0.0f, 0.0f);
+ m_assetExtents = zero;
- getDamageToolController().DisableController();
- getSelectionToolController().DisableController();
- getGizmoToolController().DisableController();
- getEditionToolController().DisableController();
+ m_bNeedRefreshTree = true;
- switch (type)
+ m_pCurBlastAsset = nullptr;
+ m_nCurFamilyIndex = -1;
+
+ SimpleScene::Inst()->m_pCamera->SetDefaults();
+}
+
+void SampleManager::resetScene()
+{
+ std::map<BPPAssetInstance*, std::set<uint32_t>> selectChunks;
+
+ if (m_selectionToolController->IsEnabled())
{
- case BTT_Damage:
+ std::set<PxActor*> actors = m_selectionToolController->getTargetActors();
+ for (PxActor* actor : actors)
{
- getDamageToolController().EnableController();
+ BlastFamily* pBlastFamily = m_blastController->getFamilyByPxActor(*actor);
+ if (pBlastFamily)
+ {
+ BPPAssetInstance* assetInstance = getInstanceByFamily(pBlastFamily);
+ uint32_t chunkIndex = pBlastFamily->getChunkIndexByPxActor(*actor);
+ selectChunks[assetInstance].insert(chunkIndex);
+ }
}
- break;
- case BTT_Drag:
+ }
+ else if (m_gizmoToolController->IsEnabled())
+ {
+ PxActor* actor = m_gizmoToolController->getTargetActor();
+
+ if (actor)
{
- getDamageToolController().EnableController();
+ BlastFamily* pBlastFamily = m_blastController->getFamilyByPxActor(*actor);
+ if (pBlastFamily)
+ {
+ BPPAssetInstance* assetInstance = getInstanceByFamily(pBlastFamily);
+ uint32_t chunkIndex = pBlastFamily->getChunkIndexByPxActor(*actor);
+ selectChunks[assetInstance].insert(chunkIndex);
+ }
}
- break;
- case BTT_Select:
+ }
+
+ m_selectionToolController->clearSelect();
+ /*
+ std::map<BPPAssetInstance*, BlastFamily*>::iterator itIFM;
+ for (itIFM = m_instanceFamilyMap.begin(); itIFM != m_instanceFamilyMap.end(); itIFM++)
+ {
+ BPPAssetInstance* pInstance = itIFM->first;
+ BlastSceneTree::ins()->removeBlastInstance(*pInstance);
+ }
+ BlastSceneTree::ins()->clearProjectile();
+ */
+ getSceneController().ResetScene();
+ EnableSimulating(false);
+ /*
+ for (itIFM = m_instanceFamilyMap.begin(); itIFM != m_instanceFamilyMap.end(); itIFM++)
+ {
+ BPPAssetInstance* pInstance = itIFM->first;
+ BlastSceneTree::ins()->addBlastInstance(*pInstance);
+ }
+ */
+ std::set<PxActor*> actors;
+ for (std::map<BPPAssetInstance*, std::set<uint32_t>>::iterator itr = selectChunks.begin(); itr != selectChunks.end(); ++itr)
+ {
+ BlastFamily* family = getFamilyByInstance(itr->first);
+ std::set<uint32_t>& chunkIndexes = itr->second;
+
+ if (nullptr != family)
{
- getSelectionToolController().EnableController();
+ for (uint32_t chunkIndex : chunkIndexes)
+ {
+ PxActor* actor = nullptr;
+ family->getPxActorByChunkIndex(chunkIndex, &actor);
+
+ if (actor)
+ actors.insert(actor);
+ }
}
- break;
- case BTT_Translate:
+ }
+
+ if (m_selectionToolController->IsEnabled())
+ {
+ m_selectionToolController->setTargetActors(actors);
+ }
+ else if (m_gizmoToolController->IsEnabled())
+ {
+ if (actors.size() > 0)
+ m_gizmoToolController->setTargetActor(*actors.begin());
+ }
+
+ // reset scene should not restore camera
+ //SimpleScene::Inst()->m_pCamera->SetDefaults();
+}
+
+bool isChunkVisible(std::vector<BlastFamily*>& fs, uint32_t chunkIndex)
+{
+ int fsSize = fs.size();
+ if (fsSize == 0)
+ {
+ return true;
+ }
+
+ bool visible = false;
+ for (int i = 0; i < fsSize; i++)
+ {
+ if (fs[i]->isChunkVisible(chunkIndex))
{
- getGizmoToolController().EnableController();
- getGizmoToolController().setGizmoToolMode(GTM_Translate);
- }
+ visible = true;
break;
- case BTT_Scale:
+ }
+ }
+ return visible;
+}
+
+void SampleManager::_setSourceAsset()
+{
+ std::vector<BlastFamilyPtr>& families = m_blastController->getFamilies();
+ if (families.size() > 0)
+ {
+ BlastFamilyPtr spLastFamily = families.back();
+
+ m_fTool->setSourceAsset(&(spLastFamily->getBlastAsset()));
+ }
+}
+
+BlastFamily* SampleManager::getFamilyByInstance(BPPAssetInstance* instance)
+{
+ if (instance)
+ {
+ if (m_instanceFamilyMap.find(instance) != m_instanceFamilyMap.end())
{
- getGizmoToolController().EnableController();
- getGizmoToolController().setGizmoToolMode(GTM_Scale);
+ return m_instanceFamilyMap[instance];
}
- break;
- case BTT_Rotation:
+ }
+ return nullptr;
+}
+
+BPPAssetInstance* SampleManager::getInstanceByFamily(BlastFamily* family)
+{
+ if (family)
+ {
+ std::map<BPPAssetInstance*, BlastFamily*>::iterator itr = m_instanceFamilyMap.begin();
+ for (; itr != m_instanceFamilyMap.end(); ++itr)
{
- getGizmoToolController().EnableController();
- getGizmoToolController().setGizmoToolMode(GTM_Rotation);
+ if (itr->second == family)
+ {
+ return itr->first;
+ }
}
- break;
- case BTT_Edit:
+ }
+ return nullptr;
+}
+
+void SampleManager::updateFamily(BlastFamily* oldFamily, BlastFamily* newFamily)
+{
+ if (oldFamily)
+ {
+ BPPAssetInstance* instance = getInstanceByFamily(oldFamily);
+ if (instance)
{
- getEditionToolController().EnableController();
+ m_instanceFamilyMap[instance] = newFamily;
}
- break;
- default:
- break;
}
+}
- m_ToolType = type;
+void SampleManager::removeRenderMaterial(std::string name)
+{
+ if (name.empty())
+ {
+ return;
+ }
+
+ std::map<std::string, RenderMaterial*>::iterator it = m_RenderMaterialMap.find(name);
+ if (it != m_RenderMaterialMap.end())
+ {
+ m_NeedDeleteRenderMaterials.push_back(name);
+ }
}
-#include <ViewerOutput.h>
-void SampleManager::output(const char* str)
+void SampleManager::renameRenderMaterial(std::string oldName, std::string newName)
{
- viewer_msg("%s", str);
+ if (oldName.empty() || newName.empty())
+ {
+ return;
+ }
+
+ std::map<std::string, RenderMaterial*>::iterator it = m_RenderMaterialMap.find(oldName);
+ if (it != m_RenderMaterialMap.end())
+ {
+ RenderMaterial* pRenderMaterial = it->second;
+ m_RenderMaterialMap.erase(it);
+ pRenderMaterial->setMaterialName(newName);
+ m_RenderMaterialMap[newName] = pRenderMaterial;
+ }
}
-void SampleManager::output(float value)
+void SampleManager::reloadRenderMaterial(std::string name, float r, float g, float b, bool diffuse)
{
- viewer_msg("%f", value);
+ if (name.empty())
+ {
+ return;
+ }
+
+ std::map<std::string, RenderMaterial*>::iterator it = m_RenderMaterialMap.find(name);
+ if (it != m_RenderMaterialMap.end())
+ {
+ RenderMaterial* pRenderMaterial = it->second;
+ if (diffuse)
+ {
+ pRenderMaterial->setDiffuseColor(r, g, b);
+ }
+ else
+ {
+ pRenderMaterial->setSpecularColor(r, g, b);
+ }
+ }
}
-void SampleManager::output(physx::PxVec3& vec)
+void SampleManager::reloadRenderMaterial(std::string name, std::string texture, RenderMaterial::TextureType tt)
{
- viewer_msg("%f,%f,%f", vec.x, vec.y, vec.z);
+ if (name.empty())
+ {
+ return;
+ }
+
+ std::map<std::string, RenderMaterial*>::iterator it = m_RenderMaterialMap.find(name);
+ if (it != m_RenderMaterialMap.end())
+ {
+ RenderMaterial* pRenderMaterial = it->second;
+ pRenderMaterial->setTextureFileName(texture, tt);
+ }
}
-void SampleManager::clearScene()
+void SampleManager::reloadRenderMaterial(std::string name, float specularShininess)
{
- getSceneController().ClearScene();
- setBlastToolType(BTT_Edit);
+ if (name.empty())
+ {
+ return;
+ }
- MaterialLibraryPanel::ins()->deleteMaterialMap();
+ std::map<std::string, RenderMaterial*>::iterator it = m_RenderMaterialMap.find(name);
+ if (it != m_RenderMaterialMap.end())
+ {
+ RenderMaterial* pRenderMaterial = it->second;
+ pRenderMaterial->setSpecularShininess(specularShininess);
+ }
+}
- m_config.sampleName.clear();
- m_config.assetsFile.clear();
- m_config.additionalAssetList.models.clear();
- m_config.additionalAssetList.composites.clear();
- m_config.additionalAssetList.boxes.clear();
+RenderMaterial* SampleManager::getRenderMaterial(std::string name, bool create)
+{
+ if (name == "" || name == "None")
+ {
+ return RenderMaterial::getDefaultRenderMaterial();
+ }
- std::map<BlastAsset*, std::vector<BlastFamily*>>::iterator it;
- for (it = m_AssetFamiliesMap.begin(); it != m_AssetFamiliesMap.end(); it++)
+ std::map<std::string, RenderMaterial*>::iterator itRenderMaterial = m_RenderMaterialMap.find(name);
+ RenderMaterial* pRenderMaterial = nullptr;
+ if (itRenderMaterial != m_RenderMaterialMap.end())
{
- std::vector<BlastFamily*>& fs = it->second;
- fs.clear();
+ pRenderMaterial = itRenderMaterial->second;
}
- m_AssetFamiliesMap.clear();
- m_AssetDescMap.clear();
+ else if(create)
+ {
+ ResourceManager* pResourceManager = ResourceManager::ins();
- m_bNeedRefreshTree = true;
+ BPPGraphicsMaterial* pBPPGraphicsMaterial = BlastProject::ins().getGraphicsMaterial(name.c_str());
+
+ if (pBPPGraphicsMaterial == nullptr)
+ {
+ return RenderMaterial::getDefaultRenderMaterial();
+ }
+ else if (pBPPGraphicsMaterial->diffuseTextureFilePath.buf != nullptr)
+ {
+ pRenderMaterial = new RenderMaterial(name.c_str(), *pResourceManager,
+ "model_simple_textured_ex",
+ pBPPGraphicsMaterial->diffuseTextureFilePath.buf);
+ pRenderMaterial->setDiffuseColor(
+ pBPPGraphicsMaterial->diffuseColor[0],
+ pBPPGraphicsMaterial->diffuseColor[1],
+ pBPPGraphicsMaterial->diffuseColor[2],
+ pBPPGraphicsMaterial->diffuseColor[3]);
+ }
+ else
+ {
+ pRenderMaterial = new RenderMaterial(name.c_str(), *pResourceManager,
+ "model_simple_textured_ex",
+ pBPPGraphicsMaterial->diffuseColor[0],
+ pBPPGraphicsMaterial->diffuseColor[1],
+ pBPPGraphicsMaterial->diffuseColor[2],
+ pBPPGraphicsMaterial->diffuseColor[3]);
+ }
+
+ m_RenderMaterialMap[name] = pRenderMaterial;
+ }
+ return pRenderMaterial;
}
-void SampleManager::resetScene()
+void SampleManager::getCurrentSelectedInstance(BlastAsset** ppBlastAsset, int& index)
{
- getSceneController().ResetScene();
- setBlastToolType(BTT_Edit);
+ *ppBlastAsset = m_pCurBlastAsset;
+ index = m_nCurFamilyIndex;
}
-bool SampleManager::_createAsset(
- const std::string& assetName,
- const std::string& outDir,
- const std::vector<Nv::Blast::Mesh* >& meshes)
+void SampleManager::setCurrentSelectedInstance(BlastAsset* pBlastAsset, int index)
{
- PhysXController& pc = getPhysXController();
- BlastController& bc = getBlastController();
+ m_pCurBlastAsset = pBlastAsset;
+ m_nCurFamilyIndex = index;
- physics = &pc.getPhysics();
- foundation = &physics->getFoundation();
- cooking = &pc.getCooking();
- physicsManager = &bc.getExtPxManager();
- TkFramework& tk = bc.getTkFramework();
+ MaterialAssignmentsPanel::ins()->updateValues();
+ FileReferencesPanel::ins()->updateValues();
+}
- std::string outBlastFilePath = GlobalSettings::MakeFileName(outDir.c_str(), std::string(assetName + ".bpxa").c_str());
+void SampleManager::getMaterialForCurrentFamily(std::string& name, bool externalSurface)
+{
+ name = "";
- std::vector<NvBlastChunkDesc> chunkDesc;
- std::vector<NvBlastBondDesc> bondDescs;
- std::vector<std::vector<Triangle> > chunkMeshes;
- std::vector<bool> isSupport;
+ if (m_pCurBlastAsset == nullptr || m_nCurFamilyIndex < 0)
+ {
+ return;
+ }
- if (meshes.size() <= 1)
+ std::map<BlastAsset*, std::vector<BlastFamily*>>::iterator it = m_AssetFamiliesMap.find(m_pCurBlastAsset);
+ if (it == m_AssetFamiliesMap.end())
{
- size_t nChunkListSize = m_fTool->getChunkList().size();
- chunkMeshes.resize(nChunkListSize);
- isSupport.resize(nChunkListSize);
- for (uint32_t i = 0; i < nChunkListSize; ++i)
+ return;
+ }
+
+ std::vector<BlastFamily*>& fs = it->second;
+ int fsSize = fs.size();
+ if (fsSize == 0 || fsSize <= m_nCurFamilyIndex)
+ {
+ return;
+ }
+
+ BlastFamily* pBlastFamily = fs[m_nCurFamilyIndex];
+ RenderMaterial* pRenderMaterial = nullptr;
+ pBlastFamily->getMaterial(&pRenderMaterial, externalSurface);
+ if (pRenderMaterial != nullptr)
+ {
+ name = pRenderMaterial->getMaterialName();
+ if (name != "")
{
- m_fTool->getBaseMesh(i, chunkMeshes[i]);
- isSupport[i] = m_fTool->getChunkList()[i].isLeaf;
+ return;
}
}
- // If there are more than one mesh, then it seems that it prefractured, lets consider first mesh in meshes as depth 0, other meshes as depth 1 chunks
- // we should just build Blast descriptors for such input.
+
+ AssetList::ModelAsset modelAsset = m_AssetDescMap[m_pCurBlastAsset];
+ int assetID = BlastProject::ins().getAssetIDByName(modelAsset.name.c_str());
+ BPPAssetInstance* instance = BlastProject::ins().getAssetInstance(assetID, m_nCurFamilyIndex);
+ if (externalSurface && instance->exMaterial.buf != nullptr)
+ {
+ name = instance->exMaterial.buf;
+ }
+ else if (!externalSurface && instance->inMaterial.buf != nullptr)
+ {
+ name = instance->inMaterial.buf;
+ }
+}
+
+void SampleManager::setMaterialForCurrentFamily(std::string name, bool externalSurface)
+{
+ if (m_pCurBlastAsset == nullptr || m_nCurFamilyIndex < 0)
+ {
+ return;
+ }
+
+ std::map<BlastAsset*, std::vector<BlastFamily*>>::iterator it = m_AssetFamiliesMap.find(m_pCurBlastAsset);
+ if (it == m_AssetFamiliesMap.end())
+ {
+ return;
+ }
+
+ std::vector<BlastFamily*>& fs = it->second;
+ int fsSize = fs.size();
+ if (fsSize == 0 || fsSize <= m_nCurFamilyIndex)
+ {
+ return;
+ }
+
+ RenderMaterial* pRenderMaterial = getRenderMaterial(name);
+
+ BlastFamily* pBlastFamily = fs[m_nCurFamilyIndex];
+ pBlastFamily->setMaterial(pRenderMaterial, externalSurface);
+
+ AssetList::ModelAsset modelAsset = m_AssetDescMap[m_pCurBlastAsset];
+ int assetID = BlastProject::ins().getAssetIDByName(modelAsset.name.c_str());
+ BPPAssetInstance* instance = BlastProject::ins().getAssetInstance(assetID, m_nCurFamilyIndex);
+ if (externalSurface)
+ {
+ copy(instance->exMaterial, name.c_str());
+ }
+ else
+ {
+ copy(instance->inMaterial, name.c_str());
+ }
+}
+
+#if 0
+void SampleManager::applyAssetToProjectParam(BlastAsset* pBlastAsset, bool addTo)
+{
+ BlastAssetModel* assetModel = dynamic_cast<BlastAssetModel*>(pBlastAsset);
+
+ BPPBlast& blast = BlastProject::ins().getParams().blast;
+
+ std::map<BlastAsset*, std::vector<BlastFamily*>>& AssetFamiliesMap = getAssetFamiliesMap();
+ std::map<BlastAsset*, AssetList::ModelAsset>& AssetDescMap = getAssetDescMap();
+
+ AssetList::ModelAsset desc = AssetDescMap[pBlastAsset];
+ std::vector<BlastFamily*>& fs = AssetFamiliesMap[pBlastAsset];
+
+ BlastController& blastController = getBlastController();
+ SceneController& sceneController = getSceneController();
+
+ char str[MAX_PATH];
+
+ // asset array
+ BPPAssetArray assetArray;
+ assetArray.arraySizes[0] = 1;
+ assetArray.buf = new BPPAsset[1];
+ BPPAsset& asset = assetArray.buf[0];
+ ::init(asset);
+ copy(asset.name, desc.name.c_str());
+ if (addTo)
+ {
+ asset.ID = BlastProject::ins().generateNewAssetID();
+ merge(blast.blastAssets, assetArray);
+ }
else
{
- chunkMeshes.resize(meshes.size());
- std::vector<PxVec3> chunkCentroids(meshes.size(), PxVec3(0, 0, 0));
+ asset.ID = BlastProject::ins().getAssetIDByName(asset.name.buf);
+ apart(blast.blastAssets, assetArray);
+ }
+
+ const ExtPxAsset* pExtPxAsset = pBlastAsset->getPxAsset();
+ const ExtPxChunk* pExtPxChunk = pExtPxAsset->getChunks();
+
+ const TkAsset& tkAsset = pExtPxAsset->getTkAsset();
+ uint32_t chunkCount = tkAsset.getChunkCount();
+ const NvBlastChunk* pNvBlastChunk = tkAsset.getChunks();
+ uint32_t bondCount = tkAsset.getBondCount();
+ const NvBlastBond* pNvBlastBond = tkAsset.getBonds();
+
+ const NvBlastSupportGraph supportGraph = tkAsset.getGraph();
+ uint32_t* chunkIndices = supportGraph.chunkIndices;
+ uint32_t* adjacencyPartition = supportGraph.adjacencyPartition;
+ uint32_t* adjacentNodeIndices = supportGraph.adjacentNodeIndices;
+ uint32_t* adjacentBondIndices = supportGraph.adjacentBondIndices;
+
+ std::vector<bool> isSupports(chunkCount);
+ isSupports.assign(chunkCount, false);
+ std::vector<uint32_t> fromIDs(bondCount);
+ std::vector<uint32_t> toIDs(bondCount);
+ fromIDs.assign(bondCount, -1);
+ toIDs.assign(bondCount, -1);
+
+ for (uint32_t node0 = 0; node0 < supportGraph.nodeCount; ++node0)
+ {
+ const uint32_t chunkIndex0 = supportGraph.chunkIndices[node0];
+ if (chunkIndex0 >= chunkCount)
+ {
+ continue;
+ }
+
+ isSupports[chunkIndex0] = true;
- for (uint32_t i = 0; i < meshes.size(); ++i)
+ for (uint32_t adjacencyIndex = adjacencyPartition[node0]; adjacencyIndex < adjacencyPartition[node0 + 1]; adjacencyIndex++)
{
- std::vector<Triangle>& chunk = chunkMeshes[i];
+ uint32_t node1 = supportGraph.adjacentNodeIndices[adjacencyIndex];
+
+ // add this condition if you don't want to iterate all bonds twice
+ if (node0 > node1)
+ continue;
- Vertex* vbf = meshes[i]->getVertices();
- Edge* ebf = meshes[i]->getEdges();
+ const uint32_t chunkIndex1 = supportGraph.chunkIndices[node1];
- for (uint32_t fc = 0; fc < meshes[i]->getFacetCount(); ++fc)
+ uint32_t bondIndex = supportGraph.adjacentBondIndices[adjacencyIndex];
+
+ if (chunkIndex0 < chunkIndex1)
{
- Facet* f = meshes[i]->getFacet(fc);
- Triangle tr;
- tr.a = vbf[ebf[f->firstEdgeNumber].s];
- tr.b = vbf[ebf[f->firstEdgeNumber + 1].s];
- tr.c = vbf[ebf[f->firstEdgeNumber + 2].s];
- chunk.push_back(tr);
-
- chunkCentroids[i] += tr.a.p + tr.b.p + tr.c.p;
+ fromIDs[bondIndex] = chunkIndex0;
+ toIDs[bondIndex] = chunkIndex1;
}
+ else
+ {
+ fromIDs[bondIndex] = chunkIndex1;
+ toIDs[bondIndex] = chunkIndex0;
+ }
+ }
+ }
+
+ // chunks
+ BPPChunkArray chunkArray;
+ {
+ chunkArray.buf = new BPPChunk[chunkCount];
+ chunkArray.arraySizes[0] = chunkCount;
+ char chunkname[10];
+ for (int cc = 0; cc < chunkCount; ++cc)
+ {
+ BPPChunk& chunk = chunkArray.buf[cc];
+ ::init(chunk);
+
+ std::vector<uint32_t> parentChunkIndexes;
+ parentChunkIndexes.push_back(cc);
+ uint32_t parentChunkIndex = cc;
+ while ((parentChunkIndex = pNvBlastChunk[parentChunkIndex].parentChunkIndex) != -1)
+ {
+ parentChunkIndexes.push_back(parentChunkIndex);
+ }
+
+ std::string strChunkName = "Chunk";
+ for (int pcIndex = parentChunkIndexes.size() - 1; pcIndex >= 0; pcIndex--)
+ {
+ sprintf(chunkname, "_%d", parentChunkIndexes[pcIndex]);
+ strChunkName += chunkname;
+ }
+ copy(chunk.name, strChunkName.c_str());
+
+ chunk.asset = asset.ID;
+ chunk.ID = cc;
+ chunk.parentID = pNvBlastChunk[cc].parentChunkIndex;
+ chunk.staticFlag = pExtPxChunk[cc].isStatic;
+ chunk.visible = isChunkVisible(fs, cc);
+ chunk.support = isSupports[cc];
+
+ if (assetModel != nullptr)
+ {
+ const BlastModel& model = assetModel->getModel();
+
+ BPPGraphicsMesh& graphicsMesh = chunk.graphicsMesh;
+ ::init(graphicsMesh);
+
+ const BlastModel::Chunk& chunk = model.chunks[cc];
+
+ const std::vector<BlastModel::Chunk::Mesh>& meshes = chunk.meshes;
+ int meshSize = meshes.size();
+
+ if (meshSize == 0)
+ {
+ continue;
+ }
+
+ std::vector<physx::PxVec3> positions;
+ std::vector<physx::PxVec3> normals;
+ std::vector<physx::PxVec2> uv;
+ std::vector<uint32_t> ind;
+ std::vector<int> faceBreakPoint;
+ std::vector<uint32_t> materialIndexes;
+ uint16_t curIndex = 0;
+ for (int ms = 0; ms < meshSize; ms++)
+ {
+ const BlastModel::Chunk::Mesh& mesh = meshes[ms];
+ materialIndexes.push_back(mesh.materialIndex);
+ const SimpleMesh& simpleMesh = mesh.mesh;
+ const std::vector<SimpleMesh::Vertex>& vertices = simpleMesh.vertices;
+ const std::vector<uint16_t>& indices = simpleMesh.indices;
+
+ int NumVertices = vertices.size();
+ for (uint32_t i = 0; i < NumVertices; ++i)
+ {
+ positions.push_back(physx::PxVec3(vertices[i].position.x, vertices[i].position.y, vertices[i].position.z));
+ normals.push_back(physx::PxVec3(vertices[i].normal.x, vertices[i].normal.y, vertices[i].normal.z));
+ uv.push_back(physx::PxVec2(vertices[i].uv.x, vertices[i].uv.y));
+ }
+ int NumIndices = indices.size();
+ for (uint32_t i = 0; i < NumIndices; ++i)
+ {
+ ind.push_back(indices[i] + curIndex);
+ }
+ curIndex += NumIndices;
+ faceBreakPoint.push_back(NumIndices / 3);
+ }
+
+ graphicsMesh.materialAssignments.buf = new BPPMaterialAssignments[materialIndexes.size()];
+ graphicsMesh.materialAssignments.arraySizes[0] = materialIndexes.size();
+ for (size_t i = 0; i < materialIndexes.size(); ++i)
+ {
+ BPPMaterialAssignments& assignment = graphicsMesh.materialAssignments.buf[i];
+ assignment.libraryMaterialID = materialIndexes[i];
+ assignment.faceMaterialID = materialIndexes[i];
+ }
+
+ graphicsMesh.positions.buf = new nvidia::NvVec3[positions.size()];
+ graphicsMesh.positions.arraySizes[0] = positions.size();
+ for (size_t i = 0; i < positions.size(); ++i)
+ {
+ nvidia::NvVec3& item = graphicsMesh.positions.buf[i];
+ item.x = positions[i].x;
+ item.y = positions[i].y;
+ item.z = positions[i].z;
+ }
+
+ graphicsMesh.normals.buf = new nvidia::NvVec3[normals.size()];
+ graphicsMesh.normals.arraySizes[0] = normals.size();
+ for (size_t i = 0; i < normals.size(); ++i)
+ {
+ nvidia::NvVec3& item = graphicsMesh.normals.buf[i];
+ item.x = normals[i].x;
+ item.y = normals[i].y;
+ item.z = normals[i].z;
+ }
+
+ graphicsMesh.texcoords.buf = new nvidia::NvVec2[uv.size()];
+ graphicsMesh.texcoords.arraySizes[0] = uv.size();
+ for (size_t i = 0; i < uv.size(); ++i)
+ {
+ nvidia::NvVec2& item = graphicsMesh.texcoords.buf[i];
+ item.x = uv[i].x;
+ item.y = uv[i].y;
+ }
+
+ size_t indexCount = ind.size();
+ size_t faceCount = ind.size() / 3;
+
+ graphicsMesh.vertextCountInFace = 3;
- chunkCentroids[i] *= 1.0f / (3 * meshes[i]->getFacetCount());
+ graphicsMesh.positionIndexes.buf = new int32_t[indexCount];
+ graphicsMesh.positionIndexes.arraySizes[0] = indexCount;
+
+ graphicsMesh.normalIndexes.buf = new int32_t[indexCount];
+ graphicsMesh.normalIndexes.arraySizes[0] = indexCount;
+
+ graphicsMesh.texcoordIndexes.buf = new int32_t[indexCount];
+ graphicsMesh.texcoordIndexes.arraySizes[0] = indexCount;
+
+ graphicsMesh.materialIDs.buf = new int32_t[faceCount];
+ graphicsMesh.materialIDs.arraySizes[0] = faceCount;
+
+ for (size_t i = 0; i < indexCount; ++i)
+ {
+ graphicsMesh.positionIndexes.buf[i] = ind[i];
+ graphicsMesh.normalIndexes.buf[i] = ind[i];
+ graphicsMesh.texcoordIndexes.buf[i] = ind[i];
+ /*
+ size_t j = 0;
+ for (; j < faceBreakPoint.size(); ++j)
+ {
+ if (i < faceBreakPoint[j])
+ break;
+ }
+ graphicsMesh.materialIDs.buf[i / 3] = j;
+ */
+ }
+
+ for (size_t f = 0; f < faceCount; f++)
+ {
+ int32_t ex = f < faceBreakPoint[0] ? 0 : 1;
+ graphicsMesh.materialIDs.buf[f] = ex;
+ }
+ }
}
- isSupport.resize(chunkMeshes.size());
- chunkDesc.resize(chunkMeshes.size());
- isSupport[0] = false;
+ if (addTo)
+ {
+ merge(blast.chunks, chunkArray);
+ }
+ else
+ {
+ apart(blast.chunks, chunkArray);
+ }
+ }
- chunkDesc[0].centroid[0] = chunkCentroids[0].x;
- chunkDesc[0].centroid[1] = chunkCentroids[0].y;
- chunkDesc[0].centroid[2] = chunkCentroids[0].z;
- chunkDesc[0].parentChunkIndex = UINT32_MAX;
+ // bonds
+ BPPBondArray bondArray;
+ {
+ bondArray.buf = new BPPBond[bondCount];
+ bondArray.arraySizes[0] = bondCount;
+ char bondname[10];
+ bool visible;
+ for (int bc = 0; bc < bondCount; ++bc)
+ {
+ BPPBond& bond = bondArray.buf[bc];
+ bond.name.buf = nullptr;
+ ::init(bond);
+
+ visible = isChunkVisible(fs, fromIDs[bc]) || isChunkVisible(fs, toIDs[bc]);
+ bond.visible = visible;
+ bond.fromChunk = fromIDs[bc];
+ bond.toChunk = toIDs[bc];
+
+ sprintf(bondname, "Bond_%d_%d", bond.fromChunk, bond.toChunk);
+ copy(bond.name, bondname);
+ bond.asset = asset.ID;
+
+ bond.support.healthMask.buf = nullptr;
+ bond.support.bondStrength = 1.0;
+ bond.support.enableJoint = false;
+ }
- for (uint32_t i = 1; i < chunkDesc.size(); ++i)
+ if (addTo)
+ {
+ merge(blast.bonds, bondArray);
+ }
+ else
{
- chunkDesc[i].parentChunkIndex = 0;
- chunkDesc[i].flags = NvBlastChunkDesc::SupportFlag;
- chunkDesc[i].centroid[0] = chunkCentroids[i].x;
- chunkDesc[i].centroid[1] = chunkCentroids[i].y;
- chunkDesc[i].centroid[2] = chunkCentroids[i].z;
- isSupport[i] = true;
+ apart(blast.bonds, bondArray);
}
}
- BlastBondGenerator bondGenerator(cooking, &physics->getPhysicsInsertionCallback());
+ freeBlast(bondArray);
+ freeBlast(chunkArray);
+ freeBlast(assetArray);
- BondGenerationConfig cnf;
- cnf.bondMode = BondGenerationConfig::AVERAGE;
+ m_bNeedRefreshTree = true;
+}
+#endif
- if (meshes.size() > 1)
+void SampleManager::updateAssetFamilyStressSolver(BPPAsset* bppAsset, BPPStressSolver& stressSolver)
+{
+ if (nullptr == bppAsset || nullptr == bppAsset->name.buf || 0 == strlen(bppAsset->name.buf))
+ return;
+
+ BlastAsset* blastAsset = nullptr;
+ std::map<BlastAsset*, AssetList::ModelAsset>::iterator itr = m_AssetDescMap.begin();
+ for (; itr != m_AssetDescMap.end(); ++itr)
{
- bondGenerator.bondsFromPrefractured(chunkMeshes, isSupport, bondDescs, cnf);
+ if (itr->second.name == bppAsset->name.buf)
+ {
+ blastAsset = itr->first;
+ break;
+ }
}
- else
+
+ if (nullptr == blastAsset)
+ return;
+
+ std::vector<BlastFamily*>& families = m_AssetFamiliesMap[blastAsset];
+
+ for (BlastFamily* family : families)
{
- bondGenerator.buildDescFromInternalFracture(m_fTool, isSupport, bondDescs, chunkDesc);
+ BlastFamily::Settings settings = family->getSettings();
+
+ ExtStressSolverSettings & stressSolverSettings = settings.stressSolverSettings;
+ stressSolverSettings.hardness = stressSolver.hardness;
+ stressSolverSettings.stressLinearFactor = stressSolver.linearFactor;
+ stressSolverSettings.stressAngularFactor = stressSolver.angularFactor;
+ stressSolverSettings.bondIterationsPerFrame = stressSolver.bondIterationsPerFrame;
+ stressSolverSettings.graphReductionLevel = stressSolver.graphReductionLevel;
+ family->setSettings(settings);
}
+}
- const uint32_t chunkCount = static_cast<uint32_t>(chunkDesc.size());
- const uint32_t bondCount = static_cast<uint32_t>(bondDescs.size());
- if (bondCount == 0)
+void SampleManager::updateModelMeshToProjectParam(BlastAsset* pBlastAsset)
+{
+ BlastProject& project = BlastProject::ins();
+ BlastAssetModel* assetModel = dynamic_cast<BlastAssetModel*>(pBlastAsset);
+ BPPBlast& blast = project.getParams().blast;
+ std::map<BlastAsset*, AssetList::ModelAsset>& AssetDescMap = getAssetDescMap();
+ AssetList::ModelAsset desc = AssetDescMap[pBlastAsset];
+
+ int assetId = project.getAssetIDByName(desc.name.c_str());
+ if (-1 == assetId)
+ return;
+
+ std::vector<BPPChunk*> chunks = project.getChildrenChunks(assetId);
+
+ BPPChunk& chunk = *chunks[0];//unfracture model only has one chunk
+
+ if (assetModel != nullptr)
{
- std::cout << "Can't create bonds descriptors..." << std::endl;
+ const BlastModel& model = assetModel->getModel();
+
+ BPPGraphicsMesh& graphicsMesh = chunk.graphicsMesh;
+
+ const BlastModel::Chunk& chunk = model.chunks[0];//unfracture model only has one chunk
+
+ const std::vector<BlastModel::Chunk::Mesh>& meshes = chunk.meshes;
+ int meshSize = meshes.size();
+
+ if (meshSize == 0)
+ {
+ return;
+ }
+
+ std::vector<physx::PxVec3> positions;
+ for (int ms = 0; ms < meshSize; ms++)
+ {
+ const BlastModel::Chunk::Mesh& mesh = meshes[ms];
+ const SimpleMesh& simpleMesh = mesh.mesh;
+ const std::vector<SimpleMesh::Vertex>& vertices = simpleMesh.vertices;
+
+ int NumVertices = vertices.size();
+ for (uint32_t i = 0; i < NumVertices; ++i)
+ {
+ positions.push_back(physx::PxVec3(vertices[i].position.x, vertices[i].position.y, vertices[i].position.z));
+ }
+ }
+
+ for (size_t i = 0; i < positions.size(); ++i)
+ {
+ nvidia::NvVec3& item = graphicsMesh.positions.buf[i];
+ item.x = positions[i].x;
+ item.y = positions[i].y;
+ item.z = positions[i].z;
+ }
}
+}
- // order chunks, build map
- std::vector<uint32_t> chunkReorderInvMap;
+#if 0
+void SampleManager::applyFamilyToProjectParam(BlastFamily* pBlastFamily, bool addTo)
+{
+ const BlastAsset& blastAsset = pBlastFamily->getBlastAsset();
+ BlastAsset* pBlastAsset = (BlastAsset*)&blastAsset;
+
+ std::vector<BlastFamily*>& fs = m_AssetFamiliesMap[pBlastAsset];
+ std::map<BlastAsset*, AssetList::ModelAsset>& AssetDescMap = getAssetDescMap();
+ AssetList::ModelAsset desc = AssetDescMap[pBlastAsset];
+
+ const BlastFamily::Settings& familySetting = pBlastFamily->getSettings();
+ physx::PxTransform transform = familySetting.transform;
+
+ char str[MAX_PATH];
+
+ BPPBlast& blast = BlastProject::ins().getParams().blast;
+ int assetID = BlastProject::ins().getAssetIDByName(desc.name.c_str());
+
+ // instance array
+ BPPAssetInstanceArray instanceArray;
+ instanceArray.arraySizes[0] = 1;
+ instanceArray.buf = new BPPAssetInstance[1];
+ BPPAssetInstance& instance = instanceArray.buf[0];
+ if (addTo)
+ {
+ ::init(instance);
+ int instanceIndex = fs.size() - 1;
+ sprintf(str, "%s_%d", desc.name.c_str(), instanceIndex);
+ copy(instance.name, str);
+ instance.asset = assetID;
+ PxVec3 p = transform.p;
+ PxQuat q = transform.q;
+ instance.transform.position = nvidia::NvVec3(p.x, p.y, p.z);
+ instance.transform.rotation = nvidia::NvVec4(q.x, q.y, q.z, q.w);
+ }
+ else
{
- std::vector<uint32_t> chunkReorderMap(chunkCount);
- std::vector<char> scratch(chunkCount * sizeof(NvBlastChunkDesc));
- NvBlastEnsureAssetExactSupportCoverage(chunkDesc.data(), chunkCount, scratch.data(), loggingCallback);
- NvBlastBuildAssetDescChunkReorderMap(chunkReorderMap.data(), chunkDesc.data(), chunkCount, scratch.data(), loggingCallback);
- NvBlastApplyAssetDescChunkReorderMapInplace(chunkDesc.data(), chunkCount, bondDescs.data(), bondCount, chunkReorderMap.data(), scratch.data(), loggingCallback);
- chunkReorderInvMap.resize(chunkReorderMap.size());
- Nv::Blast::invertMap(chunkReorderInvMap.data(), chunkReorderMap.data(), static_cast<unsigned int>(chunkReorderMap.size()));
+ BPPAssetInstance* pInstance = getInstanceByFamily(pBlastFamily);
+ copy(instance, *pInstance);
}
- // get result geometry
- std::vector<std::vector<Triangle>> resultGeometry(chunkMeshes.size());
- for (uint32_t i = 0; i < chunkMeshes.size(); ++i)
+ std::vector<BPPAssetInstance*> instances;
+ BlastProject::ins().getAssetInstances(assetID, instances);
+ int instanceSize = instances.size();
+ std::vector<std::string> instanceNames(instanceSize);
+ std::vector<BlastFamily*> instanceFamilys(instanceSize);
+ for (int is = 0; is < instanceSize; is++)
{
- uint32_t chunkIndex = chunkReorderInvMap[i];
- resultGeometry[chunkIndex] = chunkMeshes[i];
+ instanceNames[is] = instances[is]->name;
+ instanceFamilys[is] = m_instanceFamilyMap[instances[is]];
+ m_instanceFamilyMap.erase(m_instanceFamilyMap.find(instances[is]));
}
- // prepare physics data (convexes)
- std::vector<ExtPxAssetDesc::ChunkDesc> pxChunks(chunkCount);
- std::vector<ExtPxAssetDesc::SubchunkDesc> pxSubchunks;
- buildPxChunks(resultGeometry, pxChunks, pxSubchunks);
+ if (addTo)
+ {
+ merge(blast.blastAssetInstances, instanceArray);
+ instanceNames.push_back(str);
+ instanceFamilys.push_back(pBlastFamily);
- // build and serialize ExtPhysicsAsset
- ExtPxAssetDesc descriptor;
- descriptor.bondCount = bondCount;
- descriptor.bondDescs = bondDescs.data();
- descriptor.chunkCount = chunkCount;
- descriptor.chunkDescs = chunkDesc.data();
- descriptor.bondFlags = nullptr;
- descriptor.pxChunks = pxChunks.data();
- ExtPxAsset* asset = ExtPxAsset::create(descriptor, tk);
- if (asset == nullptr)
+ std::vector<BPPChunk*> chunks = BlastProject::ins().getChildrenChunks(assetID);
+ for (size_t i = 0; i < chunks.size(); ++i)
+ {
+ chunks[i]->visible = isChunkVisible(fs, i);
+ }
+ }
+ else
{
- return false;
+ apart(blast.blastAssetInstances, instanceArray);
}
- physx::PsFileBuffer fileBuf(outBlastFilePath.c_str(), physx::PxFileBuf::OPEN_WRITE_ONLY);
- if (!asset->serialize(fileBuf, *cooking))
+ instanceSize = instanceNames.size();
+ for (int is = 0; is < instanceSize; is++)
{
- return false;
+ BPPAssetInstance* curInstance = BlastProject::ins().getAssetInstance(assetID, instanceNames[is].c_str());
+ if (curInstance != nullptr)
+ {
+ m_instanceFamilyMap[curInstance] = instanceFamilys[is];
+ }
}
- fileBuf.close();
- asset->release();
- saveFractureToObj(resultGeometry, assetName, outDir);
+ freeBlast(instanceArray);
- m_bNeedConfig = true;
+ m_bNeedRefreshTree = true;
+}
+#endif
- return true;
+BlastAsset* SampleManager::loadBlastFile(std::string dir, std::string file, AssetList::ModelAsset modelAsset)
+{
+ GlobalSettings::Inst().m_projectFileDir = dir;
+ GlobalSettings::Inst().m_projectFileName = file;
+
+ TkFramework& framework = getBlastController().getTkFramework();
+ PxPhysics& physics = getPhysXController().getPhysics();
+ PxCooking& cooking = getPhysXController().getCooking();
+ Renderer& renderer = getRenderer();
+ ExtSerialization& serialization = *getBlastController().getExtSerialization();
+
+ BlastAssetModelSimple* pBlastAssetModelSimple = new BlastAssetModelSimple(
+ framework, physics, cooking, serialization, renderer, file.c_str());
+
+ addBlastAsset(pBlastAssetModelSimple, modelAsset);
+
+ return pBlastAssetModelSimple;
}
-void SampleManager::_setSourceAsset()
+void SampleManager::addBlastAsset(BlastAssetModelSimple* pBlastAssetModelSimple, AssetList::ModelAsset modelAsset, bool inProject)
{
- std::vector<BlastFamilyPtr>& families = m_blastController->getFamilies();
- if (families.size() > 0)
+ // 1
+ m_AssetDescMap[pBlastAssetModelSimple] = modelAsset;
+ m_AssetFamiliesMap[pBlastAssetModelSimple].clear();
+ pBlastAssetModelSimple->initialize();
+
+ // 2
+ m_sceneController->addBlastAsset(pBlastAssetModelSimple, modelAsset);
+
+ if (!inProject)
{
- BlastFamilyPtr spLastFamily = families.back();
+ // 3
+ _addAssetToProjectParam(pBlastAssetModelSimple);
+ }
- m_fTool->setSourceAsset(&(spLastFamily->getBlastAsset()));
+ //4
+ const BlastModel& model = pBlastAssetModelSimple->getModel();
+ const physx::PxVec3 extent = (model.bbMax - model.bbMin) * 0.5f;
+ atcore_float3 max = gfsdk_max(*(atcore_float3*)&m_assetExtents, *(atcore_float3*)&(extent));
+ m_assetExtents = *(physx::PxVec3*)&max;
+
+ getGizmoToolController().setAxisLength(m_assetExtents.magnitude());
+
+ m_bNeedRefreshTree = true;
+ /*
+ BPPAsset* pBPPAsset = BlastProject::ins().getAsset(modelAsset.name.c_str());
+ BlastSceneTree::ins()->addBlastAsset(*pBPPAsset);
+ */
+}
+
+void SampleManager::removeBlastAsset(BlastAssetModelSimple* pBlastAssetModelSimple)
+{
+ std::map<BlastAsset*, AssetList::ModelAsset>::iterator itADM = m_AssetDescMap.find(pBlastAssetModelSimple);
+ /*
+ AssetList::ModelAsset modelAsset = itADM->second;
+ BPPAsset* pBPPAsset = BlastProject::ins().getAsset(modelAsset.name.c_str());
+ BlastSceneTree::ins()->removeBlastInstances(*pBPPAsset);
+ BlastSceneTree::ins()->removeBlastAsset(*pBPPAsset);
+ */
+ // 3
+ _removeInstancesFromProjectParam(pBlastAssetModelSimple);
+ _removeAssetFromProjectParam(pBlastAssetModelSimple);
+
+ // 2
+ m_sceneController->removeBlastAsset(pBlastAssetModelSimple);
+
+ _refreshInstanceFamilyMap();
+
+ // 1
+ m_AssetDescMap.erase(itADM);
+
+ m_bNeedRefreshTree = true;
+}
+
+BlastFamily* SampleManager::addBlastFamily(BlastAsset* pBlastAsset, physx::PxTransform transform, bool inProject)
+{
+ if (pBlastAsset == nullptr)
+ {
+ return nullptr;
+ }
+
+ BlastFamily* pBlastFamily = m_sceneController->addBlastFamily(pBlastAsset, transform);
+
+ if (!inProject)
+ {
+ _addInstanceToProjectParam(pBlastFamily);
}
+
+ _refreshInstanceFamilyMap();
+ /*
+ BPPAssetInstance* pBPPAssetInstance = getInstanceByFamily(pBlastFamily);
+ BlastSceneTree::ins()->addBlastInstance(*pBPPAssetInstance);
+ */
+ /*
+ AssetList::ModelAsset modelAsset = m_AssetDescMap[pBlastAsset];
+ int assetID = BlastProject::ins().getAssetIDByName(modelAsset.name.c_str());
+ std::vector<BPPAssetInstance*> instances;
+ BlastProject::ins().getAssetInstances(assetID, instances);
+ std::vector<BlastFamily*> families = m_AssetFamiliesMap[pBlastAsset];
+ int familiesSize = families.size();
+ for (int fs = 0; fs < familiesSize; fs++)
+ {
+ m_instanceFamilyMap.insert(std::make_pair(instances[fs], families[fs]));
+ }
+ */
+ // should not quit here. we still need set up right bounding extent
+ m_bNeedRefreshTree = true;
+ return pBlastFamily;
}
-void SampleManager::addRenderMaterial(RenderMaterial* pRenderMaterial)
+bool SampleManager::removeBlastFamily(BlastAsset* pBlastAsset, int nFamilyIndex)
{
- if (pRenderMaterial == nullptr)
+ if (pBlastAsset == nullptr)
{
- return;
+ return false;
}
- std::string materialName = pRenderMaterial->getMaterialName();
- if (materialName.empty())
+ std::map<BlastAsset*, std::vector<BlastFamily*>>::iterator itAFM = m_AssetFamiliesMap.find(pBlastAsset);
+ if (itAFM == m_AssetFamiliesMap.end())
{
- return;
+ return false;
}
- m_RenderMaterialMap[materialName] = pRenderMaterial;
+ std::vector<BlastFamily*> families = itAFM->second;
+ int familySize = families.size();
+ if (familySize == 0 || familySize <= nFamilyIndex)
+ {
+ return false;
+ }
- std::string textureFileName = pRenderMaterial->getTextureFileName();
- MaterialLibraryPanel::ins()->addMaterial(materialName, textureFileName);
+ _removeInstanceFromProjectParam(families[nFamilyIndex]);
+ /*
+ BPPAssetInstance* pBPPAssetInstance = getInstanceByFamily(families[nFamilyIndex]);
+ BlastSceneTree::ins()->addBlastInstance(*pBPPAssetInstance);
+ */
+ m_sceneController->removeBlastFamily(pBlastAsset, nFamilyIndex);
+
+ _refreshInstanceFamilyMap();
+ m_bNeedRefreshTree = true;
+ return true;
}
-void SampleManager::removeRenderMaterial(std::string name)
+void SampleManager::refreshAsset(BlastAsset* pBlastAsset)
{
- if (name.empty())
+ m_fTool->setSourceAsset(pBlastAsset);
+ m_fTool->finalizeFracturing();
+
+ std::map<BlastAsset*, AssetList::ModelAsset>::iterator it = m_AssetDescMap.find(pBlastAsset);
+ AssetList::ModelAsset desc = it->second;
+
+ int nChunkCount = pBlastAsset->getPxAsset()->getChunkCount();
+ int nBondCount = pBlastAsset->getPxAsset()->getTkAsset().getBondCount();
+
+ std::vector<bool> supports(nChunkCount);
+ std::vector<bool> statics(nChunkCount);
+
+ int nCur = 0;
+
+ BPPBlast& blast = BlastProject::ins().getParams().blast;
+ int assetID = BlastProject::ins().getAssetIDByName(desc.name.c_str());
+ int chunkSize = blast.chunks.arraySizes[0];
+ for (int cs = 0; cs < chunkSize; cs++)
{
- return;
+ BPPChunk& chunk = blast.chunks.buf[cs];
+ if (chunk.asset == assetID)
+ {
+ supports[nCur] = chunk.support;
+ statics[nCur] = chunk.staticFlag;
+ nCur++;
+ }
}
- std::map<std::string, RenderMaterial*>::iterator it = m_RenderMaterialMap.find(name);
- if (it != m_RenderMaterialMap.end())
+ if (nCur != nChunkCount)
{
- m_RenderMaterialMap.erase(it);
- MaterialLibraryPanel::ins()->removeMaterial(name);
+ assert("chunk size not right");
}
+
+ nCur = 0;
+
+ std::vector<uint8_t> joints(nBondCount);
+ std::vector<uint32_t> worlds(nBondCount);
+ int bondSize = blast.bonds.arraySizes[0];
+ for (int bs = 0; bs < bondSize; bs++)
+ {
+ BPPBond& bond = blast.bonds.buf[bs];
+ if (bond.asset == assetID)
+ {
+ joints[nCur] = bond.support.enableJoint;
+ worlds[nCur] = bond.toChunk;
+ nCur++;
+ }
+ }
+
+ if (nCur != nBondCount)
+ {
+ assert("bond size not right");
+ }
+
+ _replaceAsset(pBlastAsset, supports, statics, joints, worlds);
}
-void SampleManager::deleteRenderMaterial(std::string name)
+void SampleManager::UpdateCamera()
{
- if (name.empty())
+ m_renderer->UpdateCamera();
+}
+
+void SampleManager::_addAssetToProjectParam(BlastAsset* pBlastAsset)
+{
+ BlastAssetModel* assetModel = dynamic_cast<BlastAssetModel*>(pBlastAsset);
+
+ BPPBlast& blast = BlastProject::ins().getParams().blast;
+
+ std::map<BlastAsset*, std::vector<BlastFamily*>>& AssetFamiliesMap = getAssetFamiliesMap();
+ std::map<BlastAsset*, AssetList::ModelAsset>& AssetDescMap = getAssetDescMap();
+
+ AssetList::ModelAsset desc = AssetDescMap[pBlastAsset];
+ std::vector<BlastFamily*>& fs = AssetFamiliesMap[pBlastAsset];
+
+ BlastController& blastController = getBlastController();
+ SceneController& sceneController = getSceneController();
+
+ char str[MAX_PATH];
+
+ // asset array
+ BPPAssetArray assetArray;
+ assetArray.arraySizes[0] = 1;
+ assetArray.buf = new BPPAsset[1];
+ BPPAsset& asset = assetArray.buf[0];
+ ::init(asset);
+ copy(asset.name, desc.name.c_str());
+ asset.ID = BlastProject::ins().generateNewAssetID();
+ merge(blast.blastAssets, assetArray);
+
+ const ExtPxAsset* pExtPxAsset = pBlastAsset->getPxAsset();
+ const ExtPxChunk* pExtPxChunk = pExtPxAsset->getChunks();
+
+ const TkAsset& tkAsset = pExtPxAsset->getTkAsset();
+ uint32_t chunkCount = tkAsset.getChunkCount();
+ const NvBlastChunk* pNvBlastChunk = tkAsset.getChunks();
+ uint32_t bondCount = tkAsset.getBondCount();
+ const NvBlastBond* pNvBlastBond = tkAsset.getBonds();
+
+ const NvBlastSupportGraph supportGraph = tkAsset.getGraph();
+ uint32_t* chunkIndices = supportGraph.chunkIndices;
+ uint32_t* adjacencyPartition = supportGraph.adjacencyPartition;
+ uint32_t* adjacentNodeIndices = supportGraph.adjacentNodeIndices;
+ uint32_t* adjacentBondIndices = supportGraph.adjacentBondIndices;
+
+ std::vector<bool> isSupports(chunkCount);
+ isSupports.assign(chunkCount, false);
+ std::vector<uint32_t> fromIDs(bondCount);
+ std::vector<uint32_t> toIDs(bondCount);
+ fromIDs.assign(bondCount, -1);
+ toIDs.assign(bondCount, -1);
+
+ for (uint32_t node0 = 0; node0 < supportGraph.nodeCount; ++node0)
{
- return;
+ const uint32_t chunkIndex0 = supportGraph.chunkIndices[node0];
+ if (chunkIndex0 >= chunkCount)
+ {
+ continue;
+ }
+
+ isSupports[chunkIndex0] = true;
+
+ for (uint32_t adjacencyIndex = adjacencyPartition[node0]; adjacencyIndex < adjacencyPartition[node0 + 1]; adjacencyIndex++)
+ {
+ uint32_t node1 = supportGraph.adjacentNodeIndices[adjacencyIndex];
+
+ // add this condition if you don't want to iterate all bonds twice
+ if (node0 > node1)
+ continue;
+
+ const uint32_t chunkIndex1 = supportGraph.chunkIndices[node1];
+
+ uint32_t bondIndex = supportGraph.adjacentBondIndices[adjacencyIndex];
+
+ if (chunkIndex0 < chunkIndex1)
+ {
+ fromIDs[bondIndex] = chunkIndex0;
+ toIDs[bondIndex] = chunkIndex1;
+ }
+ else
+ {
+ fromIDs[bondIndex] = chunkIndex1;
+ toIDs[bondIndex] = chunkIndex0;
+ }
+ }
}
- m_NeedDeleteRenderMaterials.push_back(name);
+ // chunks
+ BPPChunkArray chunkArray;
+ {
+ chunkArray.buf = new BPPChunk[chunkCount];
+ chunkArray.arraySizes[0] = chunkCount;
+ char chunkname[10];
+ for (int cc = 0; cc < chunkCount; ++cc)
+ {
+ BPPChunk& chunk = chunkArray.buf[cc];
+ ::init(chunk);
+
+ std::vector<uint32_t> parentChunkIndexes;
+ parentChunkIndexes.push_back(cc);
+ uint32_t parentChunkIndex = cc;
+ while ((parentChunkIndex = pNvBlastChunk[parentChunkIndex].parentChunkIndex) != -1)
+ {
+ parentChunkIndexes.push_back(parentChunkIndex);
+ }
+
+ std::string strChunkName = "Chunk";
+ for (int pcIndex = parentChunkIndexes.size() - 1; pcIndex >= 0; pcIndex--)
+ {
+ sprintf(chunkname, "_%d", parentChunkIndexes[pcIndex]);
+ strChunkName += chunkname;
+ }
+ copy(chunk.name, strChunkName.c_str());
+
+ chunk.asset = asset.ID;
+ chunk.ID = cc;
+ chunk.parentID = pNvBlastChunk[cc].parentChunkIndex;
+ chunk.staticFlag = pExtPxChunk[cc].isStatic;
+ chunk.visible = isChunkVisible(fs, cc);
+ chunk.support = isSupports[cc];
+
+ if (assetModel != nullptr)
+ {
+ const BlastModel& model = assetModel->getModel();
+
+ BPPGraphicsMesh& graphicsMesh = chunk.graphicsMesh;
+ ::init(graphicsMesh);
+
+ const BlastModel::Chunk& chunk = model.chunks[cc];
+
+ const std::vector<BlastModel::Chunk::Mesh>& meshes = chunk.meshes;
+ int meshSize = meshes.size();
+
+ if (meshSize == 0)
+ {
+ continue;
+ }
+
+ std::vector<physx::PxVec3> positions;
+ std::vector<physx::PxVec3> normals;
+ std::vector<physx::PxVec3> tangents;
+ std::vector<physx::PxVec2> uv;
+ std::vector<uint32_t> ind;
+ std::vector<int> faceBreakPoint;
+ std::vector<uint32_t> materialIndexes;
+ uint16_t curIndex = 0;
+ for (int ms = 0; ms < meshSize; ms++)
+ {
+ const BlastModel::Chunk::Mesh& mesh = meshes[ms];
+ materialIndexes.push_back(mesh.materialIndex);
+ const SimpleMesh& simpleMesh = mesh.mesh;
+ const std::vector<SimpleMesh::Vertex>& vertices = simpleMesh.vertices;
+ const std::vector<uint16_t>& indices = simpleMesh.indices;
+
+ int NumVertices = vertices.size();
+ for (uint32_t i = 0; i < NumVertices; ++i)
+ {
+ positions.push_back(physx::PxVec3(vertices[i].position.x, vertices[i].position.y, vertices[i].position.z));
+ normals.push_back(physx::PxVec3(vertices[i].normal.x, vertices[i].normal.y, vertices[i].normal.z));
+ tangents.push_back(physx::PxVec3(vertices[i].tangent.x, vertices[i].tangent.y, vertices[i].tangent.z));
+ uv.push_back(physx::PxVec2(vertices[i].uv.x, vertices[i].uv.y));
+ }
+ int NumIndices = indices.size();
+ for (uint32_t i = 0; i < NumIndices; ++i)
+ {
+ ind.push_back(indices[i] + curIndex);
+ }
+ curIndex += NumVertices;
+ faceBreakPoint.push_back(NumIndices / 3);
+ }
+
+ graphicsMesh.materialAssignments.buf = new BPPMaterialAssignments[materialIndexes.size()];
+ graphicsMesh.materialAssignments.arraySizes[0] = materialIndexes.size();
+ for (size_t i = 0; i < materialIndexes.size(); ++i)
+ {
+ BPPMaterialAssignments& assignment = graphicsMesh.materialAssignments.buf[i];
+ assignment.libraryMaterialID = materialIndexes[i];
+ assignment.faceMaterialID = materialIndexes[i];
+ }
+
+ graphicsMesh.positions.buf = new nvidia::NvVec3[positions.size()];
+ graphicsMesh.positions.arraySizes[0] = positions.size();
+ for (size_t i = 0; i < positions.size(); ++i)
+ {
+ nvidia::NvVec3& item = graphicsMesh.positions.buf[i];
+ item.x = positions[i].x;
+ item.y = positions[i].y;
+ item.z = positions[i].z;
+ }
+
+ graphicsMesh.normals.buf = new nvidia::NvVec3[normals.size()];
+ graphicsMesh.normals.arraySizes[0] = normals.size();
+ for (size_t i = 0; i < normals.size(); ++i)
+ {
+ nvidia::NvVec3& item = graphicsMesh.normals.buf[i];
+ item.x = normals[i].x;
+ item.y = normals[i].y;
+ item.z = normals[i].z;
+ }
+
+ graphicsMesh.tangents.buf = new nvidia::NvVec3[tangents.size()];
+ graphicsMesh.tangents.arraySizes[0] = tangents.size();
+ for (size_t i = 0; i < tangents.size(); ++i)
+ {
+ nvidia::NvVec3& item = graphicsMesh.tangents.buf[i];
+ item.x = tangents[i].x;
+ item.y = tangents[i].y;
+ item.z = tangents[i].z;
+ }
+
+ graphicsMesh.texcoords.buf = new nvidia::NvVec2[uv.size()];
+ graphicsMesh.texcoords.arraySizes[0] = uv.size();
+ for (size_t i = 0; i < uv.size(); ++i)
+ {
+ nvidia::NvVec2& item = graphicsMesh.texcoords.buf[i];
+ item.x = uv[i].x;
+ item.y = uv[i].y;
+ }
+
+ size_t indexCount = ind.size();
+ size_t faceCount = ind.size() / 3;
+
+ graphicsMesh.vertextCountInFace = 3;
+
+ graphicsMesh.positionIndexes.buf = new int32_t[indexCount];
+ graphicsMesh.positionIndexes.arraySizes[0] = indexCount;
+
+ graphicsMesh.normalIndexes.buf = new int32_t[indexCount];
+ graphicsMesh.normalIndexes.arraySizes[0] = indexCount;
+
+ graphicsMesh.texcoordIndexes.buf = new int32_t[indexCount];
+ graphicsMesh.texcoordIndexes.arraySizes[0] = indexCount;
+
+ graphicsMesh.materialIDs.buf = new int32_t[faceCount];
+ graphicsMesh.materialIDs.arraySizes[0] = faceCount;
+
+ for (size_t i = 0; i < indexCount; ++i)
+ {
+ graphicsMesh.positionIndexes.buf[i] = ind[i];
+ graphicsMesh.normalIndexes.buf[i] = ind[i];
+ graphicsMesh.texcoordIndexes.buf[i] = ind[i];
+ }
+
+ for (size_t f = 0; f < faceCount; f++)
+ {
+ int32_t ex = f < faceBreakPoint[0] ? 0 : 1;
+ graphicsMesh.materialIDs.buf[f] = ex;
+ }
+ }
+ }
+
+ merge(blast.chunks, chunkArray);
+ }
+
+ // bonds
+ BPPBondArray bondArray;
+ {
+ bondArray.buf = new BPPBond[bondCount];
+ bondArray.arraySizes[0] = bondCount;
+ char bondname[20];
+ bool visible;
+ for (int bc = 0; bc < bondCount; ++bc)
+ {
+ BPPBond& bond = bondArray.buf[bc];
+ bond.name.buf = nullptr;
+ ::init(bond);
+
+ visible = isChunkVisible(fs, fromIDs[bc]) || isChunkVisible(fs, toIDs[bc]);
+ bond.visible = visible;
+ bond.fromChunk = fromIDs[bc];
+ bond.toChunk = toIDs[bc];
+
+ if (bond.toChunk == 0xFFFFFFFF)
+ {
+ sprintf(bondname, "Bond_%d_world", bond.fromChunk);
+ }
+ else
+ {
+ sprintf(bondname, "Bond_%d_%d", bond.fromChunk, bond.toChunk);
+ }
+ copy(bond.name, bondname);
+ bond.asset = asset.ID;
+
+ bond.support.healthMask.buf = nullptr;
+ bond.support.bondStrength = 1.0;
+ bond.support.enableJoint = false;
+ }
+
+ merge(blast.bonds, bondArray);
+ }
+
+ freeBlast(bondArray);
+ freeBlast(chunkArray);
+ freeBlast(assetArray);
+
+ m_bNeedRefreshTree = true;
}
-void SampleManager::renameRenderMaterial(std::string oldName, std::string newName)
+void SampleManager::_removeAssetFromProjectParam(BlastAsset* pBlastAsset)
{
- if (oldName.empty() || newName.empty())
+ if (pBlastAsset == nullptr)
{
return;
}
- std::map<std::string, RenderMaterial*>::iterator it = m_RenderMaterialMap.find(oldName);
- if (it != m_RenderMaterialMap.end())
+ std::map<BlastAsset*, AssetList::ModelAsset>::iterator itADM = m_AssetDescMap.find(pBlastAsset);
+ if (itADM == m_AssetDescMap.end())
{
- RenderMaterial* pRenderMaterial = it->second;
- m_RenderMaterialMap.erase(it);
- pRenderMaterial->setMaterialName(newName);
- m_RenderMaterialMap[newName] = pRenderMaterial;
+ return;
}
+
+ AssetList::ModelAsset desc = m_AssetDescMap[pBlastAsset];
+
+ BPPBlast& blast = BlastProject::ins().getParams().blast;
+
+ int32_t assetId = BlastProject::ins().getAssetIDByName(desc.name.c_str());
+
+ apart(blast.blastAssets, assetId);
+ apart(blast.chunks, assetId);
+ apart(blast.bonds, assetId);
}
-void SampleManager::getCurrentSelectedInstance(BlastAsset** ppBlastAsset, int& index)
+void SampleManager::_addInstanceToProjectParam(BlastFamily* pBlastFamily)
{
- *ppBlastAsset = m_pCurBlastAsset;
- index = m_nCurFamilyIndex;
+ const BlastAsset& blastAsset = pBlastFamily->getBlastAsset();
+ BlastAsset* pBlastAsset = (BlastAsset*)&blastAsset;
+
+ std::vector<BlastFamily*>& fs = m_AssetFamiliesMap[pBlastAsset];
+ AssetList::ModelAsset desc = m_AssetDescMap[pBlastAsset];
+
+ const BlastFamily::Settings& familySetting = pBlastFamily->getSettings();
+ physx::PxTransform transform = familySetting.transform;
+
+ char str[MAX_PATH];
+
+ BPPBlast& blast = BlastProject::ins().getParams().blast;
+ int assetID = BlastProject::ins().getAssetIDByName(desc.name.c_str());
+
+ // instance array
+ BPPAssetInstanceArray instanceArray;
+ instanceArray.arraySizes[0] = 1;
+ instanceArray.buf = new BPPAssetInstance[1];
+ BPPAssetInstance& instance = instanceArray.buf[0];
+ ::init(instance);
+ int instanceIndex = fs.size() - 1;
+ sprintf(str, "%s_%d", desc.name.c_str(), instanceIndex);
+ copy(instance.name, str);
+ instance.asset = assetID;
+ PxVec3 p = transform.p;
+ PxQuat q = transform.q;
+ instance.transform.position = nvidia::NvVec3(p.x, p.y, p.z);
+ instance.transform.rotation = nvidia::NvVec4(q.x, q.y, q.z, q.w);
+
+ merge(blast.blastAssetInstances, instanceArray);
+
+ std::vector<BPPChunk*> chunks = BlastProject::ins().getChildrenChunks(assetID);
+ for (size_t i = 0; i < chunks.size(); ++i)
+ {
+ chunks[i]->visible = isChunkVisible(fs, i);
+ }
+
+ freeBlast(instanceArray);
+
+ m_bNeedRefreshTree = true;
}
-void SampleManager::setCurrentSelectedInstance(BlastAsset* pBlastAsset, int index)
+void SampleManager::_removeInstanceFromProjectParam(BlastFamily* pBlastFamily)
{
- m_pCurBlastAsset = pBlastAsset;
- m_nCurFamilyIndex = index;
+ BPPAssetInstance* pInstance = getInstanceByFamily(pBlastFamily);
+ if (pInstance == nullptr)
+ {
+ return;
+ }
- MaterialAssignmentsPanel::ins()->updateValues();
+ BPPBlast& blast = BlastProject::ins().getParams().blast;
+ apart(blast.blastAssetInstances, pInstance->asset, pInstance->name.buf);
}
-void SampleManager::getMaterialForCurrentFamily(RenderMaterial** ppRenderMaterial, bool externalSurface)
+void SampleManager::_removeInstancesFromProjectParam(BlastAsset* pBlastAsset)
{
- if (m_pCurBlastAsset == nullptr || m_nCurFamilyIndex < 0)
+ if (pBlastAsset == nullptr)
{
return;
}
- std::vector<BlastFamily*>& fs = m_AssetFamiliesMap[m_pCurBlastAsset];
- int fsSize = fs.size();
- if (fsSize == 0 || fsSize < m_nCurFamilyIndex)
+ std::map<BlastAsset*, AssetList::ModelAsset>::iterator itADM = m_AssetDescMap.find(pBlastAsset);
+ if (itADM == m_AssetDescMap.end())
{
return;
}
- BlastFamily* pBlastFamily = fs[m_nCurFamilyIndex];
- pBlastFamily->getMaterial(ppRenderMaterial, externalSurface);
+ AssetList::ModelAsset desc = m_AssetDescMap[pBlastAsset];
+
+ BPPBlast& blast = BlastProject::ins().getParams().blast;
+
+ int32_t assetId = BlastProject::ins().getAssetIDByName(desc.name.c_str());
+
+ apart(blast.blastAssetInstances, assetId);
}
-void SampleManager::setMaterialForCurrentFamily(RenderMaterial* pRenderMaterial, bool externalSurface)
+void SampleManager::_refreshInstanceFamilyMap()
{
- if (m_pCurBlastAsset == nullptr || m_nCurFamilyIndex < 0)
+ m_instanceFamilyMap.clear();
+
+ std::map<BlastAsset*, AssetList::ModelAsset>::iterator itADM;
+ std::map<BlastAsset*, std::vector<BlastFamily*>>::iterator itAFM;
+ for (itADM = m_AssetDescMap.begin(); itADM != m_AssetDescMap.end(); itADM++)
{
- return;
+ BlastAsset* pBlastAsset = itADM->first;
+ itAFM = m_AssetFamiliesMap.find(pBlastAsset);
+ if (itAFM == m_AssetFamiliesMap.end())
+ {
+ continue;
+ }
+
+ AssetList::ModelAsset modelAsset = itADM->second;
+ int assetID = BlastProject::ins().getAssetIDByName(modelAsset.name.c_str());
+ std::vector<BPPAssetInstance*> instances;
+ BlastProject::ins().getAssetInstances(assetID, instances);
+ int instancesSize = instances.size();
+ std::vector<BlastFamily*> families = itAFM->second;
+ int familiesSize = families.size();
+ if (instancesSize != familiesSize)
+ {
+ assert("size of instance in scene and project not equal");
+ }
+ for (int fs = 0; fs < familiesSize; fs++)
+ {
+ m_instanceFamilyMap.insert(std::make_pair(instances[fs], families[fs]));
+ }
}
+}
- std::vector<BlastFamily*>& fs = m_AssetFamiliesMap[m_pCurBlastAsset];
- int fsSize = fs.size();
- if (fsSize == 0 || fsSize < m_nCurFamilyIndex)
+bool SampleManager::eventAlreadyHandled()
+{
+ bool isAlt = (GetAsyncKeyState(VK_MENU) && 0x8000);
+ bool isLight = (GetAsyncKeyState('L') && 0x8000);
+ return m_selectionToolController->IsEnabled() && !(isAlt || isLight);
+}
+
+void SampleManager::ApplyAutoSelectNewChunks(BlastAsset* pNewBlastAsset, std::vector<uint32_t>& NewChunkIndexes)
+{
+ std::map<BlastAsset*, std::vector<BlastFamily*>>::iterator itAFM = m_AssetFamiliesMap.find(pNewBlastAsset);
+ if (itAFM == m_AssetFamiliesMap.end())
{
return;
}
- BlastFamily* pBlastFamily = fs[m_nCurFamilyIndex];
- pBlastFamily->setMaterial(pRenderMaterial, externalSurface);
+ bool autoSelectNewChunks = BlastProject::ins().getParams().fracture.general.autoSelectNewChunks;
+
+ std::vector<BlastFamily*> families = itAFM->second;
+ for (BlastFamily* pBlastFamily : families)
+ {
+ pBlastFamily->clearChunksSelected();
+
+ if (!autoSelectNewChunks)
+ {
+ continue;
+ }
+
+ for (uint32_t chunkInd : NewChunkIndexes)
+ {
+ pBlastFamily->setChunkSelected(chunkInd, true);
+ pBlastFamily->setChunkVisible(chunkInd, true);
+ }
+ }
+
+ BlastSceneTree::ins()->ApplyAutoSelectNewChunks(pNewBlastAsset, NewChunkIndexes);
+}
+
+void SampleManager::ApplySelectionDepthTest()
+{
+ bool selectionDepthTest = BlastProject::ins().getParams().fracture.general.selectionDepthTest;
+
+ std::vector<BlastFamily*>& families = m_blastController->getFamilies();
+
+ for (BlastFamily* pBlastFamily : families)
+ {
+ std::vector<uint32_t> selectedChunks = pBlastFamily->getSelectedChunks();
+
+ for (uint32_t chunkInd : selectedChunks)
+ {
+ pBlastFamily->setChunkSelected(chunkInd, true);
+ pBlastFamily->setChunkVisible(chunkInd, true);
+ }
+ }
} \ No newline at end of file
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/core/SampleManager.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/core/SampleManager.h
index 0c5c8b6..c16fa25 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/core/SampleManager.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/core/SampleManager.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef SAMPLE_MANAGER_H
#define SAMPLE_MANAGER_H
@@ -14,21 +32,23 @@
#include "Application.h"
#include "Sample.h"
#include <map>
-
+#include <functional>
+#include "ProjectParams.h"
+#include "RenderMaterial.h"
class SampleManager;
class BlastFractureTool;
class BlastAsset;
class BlastFamily;
-class RenderMaterial;
+
namespace Nv
{
-namespace Blast
-{
- class Mesh;
- class RandomGeneratorBase;
- class VoronoiSitesGenerator;
- struct SlicingConfiguration;
-}
+ namespace Blast
+ {
+ class Mesh;
+ class RandomGeneratorBase;
+ class VoronoiSitesGenerator;
+ struct SlicingConfiguration;
+ }
}
class ISampleController : public IApplicationController
@@ -56,59 +76,59 @@ class FractureExecutor
public:
FractureExecutor()
: m_fractureTool(0)
- , m_chunkId(-1)
, m_randomGenerator(nullptr)
- , m_sourMesh(nullptr)
+ , m_pCurBlastAsset(nullptr)
{
+ m_chunkIds.clear();
}
virtual bool execute() = 0;
- void setSourceMesh(Nv::Blast::Mesh* mesh);
- void setSourceAsset(const BlastAsset* blastAsset);
- void setTargetChunk(uint32_t chunkId) { m_chunkId = chunkId; }
+ void setSourceAsset(BlastAsset* blastAsset);
+ void setTargetChunk(uint32_t chunkId)
+ {
+ m_chunkIds.clear();
+ m_chunkIds.push_back(chunkId);
+ }
+ void setTargetChunks(std::vector<uint32_t>& chunkIds)
+ {
+ m_chunkIds.clear();
+ std::vector<uint32_t>::iterator it;
+ for (it = chunkIds.begin(); it != chunkIds.end(); it++)
+ {
+ m_chunkIds.push_back(*it);
+ }
+ std::sort(m_chunkIds.begin(), m_chunkIds.end(), std::greater<uint32_t>());
+ }
void setRandomGenerator(Nv::Blast::RandomGeneratorBase* randomGenerator) { m_randomGenerator = randomGenerator; }
protected:
BlastFractureTool* m_fractureTool;
- uint32_t m_chunkId;
+ std::vector<uint32_t> m_chunkIds;
Nv::Blast::RandomGeneratorBase* m_randomGenerator;
- Nv::Blast::Mesh* m_sourMesh;
+ BlastAsset* m_pCurBlastAsset;
};
class VoronoiFractureExecutor : public FractureExecutor
{
public:
VoronoiFractureExecutor();
- void setCellsCount(uint32_t cellsCount);
+ void setBPPVoronoi(BPPVoronoi* voronoi) { m_voronoi = voronoi; }
virtual bool execute();
private:
- uint32_t m_cellsCount;
+ BPPVoronoi* m_voronoi;
};
class SliceFractureExecutor : public FractureExecutor
{
public:
SliceFractureExecutor();
- void applyNoise(float amplitude, float frequency, int32_t octaves, float falloff, int32_t relaxIterations, float relaxFactor, int32_t seed = 0);
- void applyConfig(int32_t xSlices, int32_t ySlices, int32_t zSlices, float offsetVariations, float angleVariations);
+ void setBPPSlice(BPPSlice* slice) { m_slice = slice; }
virtual bool execute();
private:
- Nv::Blast::SlicingConfiguration* m_config;
-};
-
-enum BlastToolType
-{
- BTT_Damage = 0,
- BTT_Drag,
- BTT_Select,
- BTT_Translate,
- BTT_Scale,
- BTT_Rotation,
- BTT_Edit,
- BTT_Num
+ BPPSlice* m_slice;
};
enum SelectMode
@@ -125,12 +145,13 @@ class BlastController;
class SceneController;
class DamageToolController;
class SelectionToolController;
+class ExplodeToolController;
class GizmoToolController;
class EditionToolController;
class SampleController;
class CommonUIController;
class SimpleRandomGenerator;
-
+class BlastAssetModelSimple;
/**
*/
class SampleManager
@@ -146,27 +167,18 @@ class SampleManager
int run();
int free();
- void addModelAsset(std::string path, std::string file, bool isSkinned, physx::PxTransform transform, bool clear = true);
-
bool createAsset(
- std::string path,
- std::string assetName,
- std::vector<physx::PxVec3>& positions,
- std::vector<physx::PxVec3>& normals,
- std::vector<physx::PxVec2>& uv,
- std::vector<unsigned int>& indices,
- bool fracture = false);
+ BlastAssetModelSimple** ppBlastAsset,
+ std::vector<Nv::Blast::Mesh*>& meshes,
+ std::vector<int32_t>& parentIds,
+ std::vector<bool>& supports,
+ std::vector<bool>& statics,
+ std::vector<uint8_t>& joints,
+ std::vector<uint32_t>& worlds);
- bool createAsset(
- const std::string& path,
- const std::string& assetName,
- const std::vector<Nv::Blast::Mesh* >& meshes,
- bool fracture = false);
-
- bool saveAsset();
- bool fractureAsset(std::string& path, std::string& assetName, const BlastAsset* blastAsset, int32_t chunkId);
+ bool saveAsset(BlastAsset* pBlastAsset);
- bool postProcessCurrentAsset();
+ bool exportAsset();
Renderer& getRenderer()
{
@@ -198,6 +210,10 @@ class SampleManager
return *m_selectionToolController;
}
+ ExplodeToolController& getExplodeToolController() const
+ {
+ return *m_explodeToolController;
+ }
GizmoToolController& getGizmoToolController() const
{
return *m_gizmoToolController;
@@ -218,11 +234,6 @@ class SampleManager
return *m_commonUIController;
}
- const SampleConfig& getConfig() const
- {
- return m_config;
- }
-
std::vector<uint32_t> getCurrentSelectedChunks();
std::map<BlastAsset*, std::vector<uint32_t>> getSelectedChunks();
void clearChunksSelected();
@@ -231,8 +242,6 @@ class SampleManager
void setFractureExecutor(FractureExecutor* executor);
- void setBlastToolType(BlastToolType type);
-
void output(const char* str);
void output(float value);
void output(physx::PxVec3& vec);
@@ -249,27 +258,75 @@ class SampleManager
return m_AssetDescMap;
}
+ BlastFamily* getFamilyByInstance(BPPAssetInstance* instance);
+ BPPAssetInstance* getInstanceByFamily(BlastFamily* family);
+ void updateFamily(BlastFamily* oldFamily, BlastFamily* newFamily);
+
std::map<std::string, RenderMaterial*>& getRenderMaterials(){ return m_RenderMaterialMap; }
- void addRenderMaterial(RenderMaterial* pRenderMaterial);
void removeRenderMaterial(std::string name);
- void deleteRenderMaterial(std::string name);
void renameRenderMaterial(std::string oldName, std::string newName);
+ void reloadRenderMaterial(std::string name, float r, float g, float b, bool diffuse = true);
+ void reloadRenderMaterial(std::string name, std::string texture, RenderMaterial::TextureType tt = RenderMaterial::TT_Diffuse);
+ void reloadRenderMaterial(std::string name, float specularShininess);
+ RenderMaterial* getRenderMaterial(std::string name, bool create = true);
bool m_bNeedRefreshTree;
void getCurrentSelectedInstance(BlastAsset** ppBlastAsset, int& index);
void setCurrentSelectedInstance(BlastAsset* pBlastAsset, int index);
- void getMaterialForCurrentFamily(RenderMaterial** ppRenderMaterial, bool externalSurface);
- void setMaterialForCurrentFamily(RenderMaterial* pRenderMaterial, bool externalSurface);
+ void getMaterialForCurrentFamily(std::string& name, bool externalSurface);
+ void setMaterialForCurrentFamily(std::string name, bool externalSurface);
+
+ void updateAssetFamilyStressSolver(BPPAsset* bppAsset, BPPStressSolver& stressSolver);
+ // only update unfractured mode mesh
+ void updateModelMeshToProjectParam(BlastAsset* pBlastAsset);
+
+ BlastAsset* loadBlastFile(std::string dir, std::string file, AssetList::ModelAsset modelAsset);
+ void addBlastAsset(BlastAssetModelSimple* pBlastAsset, AssetList::ModelAsset modelAsset, bool inProject = false);
+ void removeBlastAsset(BlastAssetModelSimple* pBlastAsset);
+ BlastFamily* addBlastFamily(BlastAsset* pBlastAsset, physx::PxTransform transform, bool inProject = false);
+ bool removeBlastFamily(BlastAsset* pBlastAsset, int nFamilyIndex);
+
+ BlastAsset* getCurBlastAsset() { return m_pCurBlastAsset; }
+
+ void refreshAsset(BlastAsset* pBlastAsset);
+
+ void UpdateCamera();
+
+ bool IsSimulating() { return m_simulating; }
+ void EnableSimulating(bool bSimulating);
+ bool IsStepforward() { return m_stepforward; }
+ void EnableStepforward(bool bStepforward);
+
+ physx::PxVec3 getAssetExtent() { return m_assetExtents; }
+
+ bool eventAlreadyHandled();
+
+ void ApplyAutoSelectNewChunks(BlastAsset* pNewBlastAsset, std::vector<uint32_t>& NewChunkIndexes);
+ void ApplySelectionDepthTest();
private:
- bool _createAsset(
- const std::string& assetName,
- const std::string& outDir,
- const std::vector<Nv::Blast::Mesh* >& meshes);
+ void _createAsset(BlastAssetModelSimple** ppBlastAsset,
+ std::vector<bool>& supports,
+ std::vector<bool>& statics,
+ std::vector<uint8_t>& joints,
+ std::vector<uint32_t>& worlds);
+
+ BlastAsset* _replaceAsset(BlastAsset* pBlastAsset,
+ std::vector<bool>& supports,
+ std::vector<bool>& statics,
+ std::vector<uint8_t>& joints,
+ std::vector<uint32_t>& worlds);
void _setSourceAsset();
+ void _addAssetToProjectParam(BlastAsset* pBlastAsset);
+ void _removeAssetFromProjectParam(BlastAsset* pBlastAsset);
+ void _addInstanceToProjectParam(BlastFamily* pBlastFamily);
+ void _removeInstanceFromProjectParam(BlastFamily* pBlastFamily);
+ void _removeInstancesFromProjectParam(BlastAsset* pBlastAsset);
+ void _refreshInstanceFamilyMap();
+
private:
Renderer* m_renderer;
PhysXController* m_physXController;
@@ -277,15 +334,13 @@ private:
SceneController* m_sceneController;
DamageToolController* m_damageToolController;
SelectionToolController* m_selectionToolController;
+ ExplodeToolController* m_explodeToolController;
GizmoToolController* m_gizmoToolController;
EditionToolController* m_editionToolController;
SampleController* m_sampleController;
CommonUIController* m_commonUIController;
-
- SampleConfig m_config;
-
+
Application* m_pApplication;
- BlastToolType m_ToolType;
BlastFractureTool* m_fTool;
FractureExecutor* m_fractureExecutor;
@@ -294,11 +349,13 @@ private:
std::map<BlastAsset*, AssetList::ModelAsset> m_AssetDescMap;
std::map<std::string, RenderMaterial*> m_RenderMaterialMap;
std::vector<std::string> m_NeedDeleteRenderMaterials;
+ std::map<BPPAssetInstance*, BlastFamily*> m_instanceFamilyMap;
BlastAsset* m_pCurBlastAsset;
int m_nCurFamilyIndex;
-
- bool m_bNeedConfig;
+ physx::PxVec3 m_assetExtents;
+ bool m_simulating;
+ bool m_stepforward;
};
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/physx/PhysXController.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/physx/PhysXController.cpp
index 5146914..1cf9e26 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/physx/PhysXController.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/physx/PhysXController.cpp
@@ -1,12 +1,30 @@
-/*
- * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
- *
- * NVIDIA CORPORATION and its licensors retain all intellectual property
- * and proprietary rights in and to this software, 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.
- */
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "PhysXController.h"
#include "RenderMaterial.h"
@@ -19,7 +37,11 @@
#include "ConvexRenderMesh.h"
#include "RenderUtils.h"
#include "SampleProfiler.h"
-#include "NvBlastProfiler.h"
+#include "NvBlastExtCustomProfiler.h"
+#include "NvBlastPxCallbacks.h"
+// Add By Lixu Begin
+#include "Mesh.h"
+// Add By Lixu End
#include "PxPhysicsVersion.h"
#include "PxPvdTransport.h"
@@ -35,6 +57,10 @@
#include "PxMaterial.h"
#include "PxFoundationVersion.h"
#include "PxMath.h"
+// Add By Lixu Begin
+#include "PxRigidActorExt.h"
+#include "SimpleScene.h"
+// Add By Lixu End
#include <imgui.h>
#include <chrono>
@@ -47,14 +73,17 @@ const DirectX::XMFLOAT4 PLANE_COLOR(1.0f, 1.0f, 1.0f, 1.0f);
const DirectX::XMFLOAT4 HOOK_LINE_COLOR(1.0f, 1.0f, 1.0f, 1.0f);
const float DEFAULT_FIXED_TIMESTEP = 1.0f / 60.0f;
+static Nv::Blast::ExtCustomProfiler gBlastProfiler;
+
PhysXController::PhysXController(PxSimulationFilterShader filterShader)
: m_filterShader(filterShader)
, m_gpuPhysicsAvailable(true)
+, m_isSimulating(false)
, m_useGPUPhysics(true)
, m_lastSimulationTime(0)
, m_paused(false)
, m_draggingActor(nullptr)
-, m_draggingEnabled(true)
+, m_draggingEnabled(false)
, m_draggingTryReconnect(false)
, m_perfWriter(NULL)
, m_fixedTimeStep(DEFAULT_FIXED_TIMESTEP)
@@ -65,7 +94,7 @@ PhysXController::PhysXController(PxSimulationFilterShader filterShader)
QueryPerformanceFrequency(&m_performanceFreq);
// Add By Lixu Begin
- m_bForce = true;
+ m_bFirstTime = true;
// Add By Lixu End
}
@@ -81,6 +110,7 @@ void PhysXController::onInitialize()
void PhysXController::onTerminate()
{
+ simualtionSyncEnd();
releasePhysXPrimitives();
releasePhysX();
}
@@ -92,13 +122,13 @@ void PhysXController::onTerminate()
void PhysXController::initPhysX()
{
- m_foundation = PxCreateFoundation(PX_FOUNDATION_VERSION, m_allocator, m_errorCallback);
+ m_foundation = PxCreateFoundation(PX_FOUNDATION_VERSION, NvBlastGetPxAllocatorCallback(), NvBlastGetPxErrorCallback());
m_pvd = PxCreatePvd(*m_foundation);
- NvBlastProfilerSetCallback(m_pvd);
- NvBlastProfilerEnablePlatform(false);
- NvBlastProfilerSetDetail(NvBlastProfilerDetail::LOW);
+ NvBlastProfilerSetCallback(&gBlastProfiler);
+ NvBlastProfilerSetDetail(Nv::Blast::ProfilerDetail::LOW);
+ gBlastProfiler.setPlatformEnabled(false);
PxTolerancesScale scale;
@@ -144,6 +174,7 @@ void PhysXController::initPhysX()
}
m_physicsScene = m_physics->createScene(sceneDesc);
+ m_editPhysicsScene = m_physics->createScene(sceneDesc);
m_defaultMaterial = m_physics->createMaterial(0.8f, 0.7f, 0.1f);
@@ -176,6 +207,7 @@ void PhysXController::releasePhysX()
{
m_defaultMaterial->release();
m_physicsScene->release();
+ m_editPhysicsScene->release();
if (m_cudaContext)
m_cudaContext->release();
m_dispatcher->release();
@@ -241,61 +273,92 @@ void PhysXController::notifyRigidDynamicDestroyed(PxRigidDynamic* rigidDynamic)
}
-
-
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Controller events
+// Simulation control
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-void PhysXController::Animate(double dt)
+void PhysXController::simulationBegin(float dt)
{
PROFILER_SCOPED_FUNCTION();
// Add By Lixu Begin
- if (m_paused && !m_bForce)
+ if (m_paused && !m_bFirstTime)
return;
- if (m_bForce)
+ if (m_bFirstTime)
{
m_paused = true;
- m_bForce = false;
+ m_bFirstTime = false;
}
// Add By Lixu End
- // slower physics if fps is too low
- dt = PxClamp(dt, 0.0, 0.033333);
-
updateDragging(dt);
+ processExplosionQueue();
+
+ // slower physics if fps is too low
+ dt = PxClamp(dt, 0.0f, 0.0333f);
{
- PROFILER_SCOPED("PhysX simulate");
- steady_clock::time_point start = steady_clock::now();
+ PROFILER_SCOPED("PhysX simulate call");
if (m_useFixedTimeStep)
{
m_timeAccumulator += dt;
m_substepCount = (uint32_t)std::floor(m_timeAccumulator / m_fixedTimeStep);
m_timeAccumulator -= m_fixedTimeStep * m_substepCount;
m_substepCount = m_maxSubstepCount > 0 ? physx::PxClamp<uint32_t>(m_substepCount, 0, m_maxSubstepCount) : m_substepCount;
- for (uint32_t i = 0; i < m_substepCount; ++i)
+ if (m_substepCount > 0)
{
- PROFILER_SCOPED("PhysX simulate (substep)");
m_physicsScene->simulate(m_fixedTimeStep);
- m_physicsScene->fetchResults(true);
+ m_isSimulating = true;
}
}
else
{
m_substepCount = 1;
+ PX_ASSERT(!m_isSimulating);
m_physicsScene->simulate(dt);
- m_physicsScene->fetchResults(true);
+ m_isSimulating = true;
+
}
- m_lastSimulationTime = duration_cast<microseconds>(steady_clock::now() - start).count() * 0.000001;
}
- PROFILER_BEGIN("Debug Render Buffer");
- getRenderer().queueRenderBuffer(&m_physicsScene->getRenderBuffer());
- PROFILER_END();
+// Add By Lixu Begin
+ if (getManager()->IsStepforward())
+ {
+ m_paused = true;
+ getManager()->EnableStepforward(false);
+ }
+// Add By Lixu End
+}
+
+void PhysXController::simualtionSyncEnd()
+{
+ PROFILER_SCOPED_FUNCTION();
+
+ if (m_isSimulating)
+ {
+ steady_clock::time_point start = steady_clock::now();
+ m_physicsScene->fetchResults(true);
+
+ // For fixed time step case it could be that we need more then one step (m_maxSubstepCount > 1). We will run leftover steps synchronously right there.
+ // Ideally is to make them overlap with other logic too, but it's much harder and requires more synchronization logic. Don't want to obfuscate sample code.
+ if (m_useFixedTimeStep && m_substepCount > 1)
+ {
+ for (uint32_t i = 0; i < m_substepCount - 1; i++)
+ {
+ m_physicsScene->simulate(m_fixedTimeStep);
+ m_physicsScene->fetchResults(true);
+ }
+ }
+ m_lastSimulationTime = duration_cast<microseconds>(steady_clock::now() - start).count() * 0.000001;
- updateActorTransforms();
+ m_isSimulating = false;
+
+ updateActorTransforms();
+
+ PROFILER_BEGIN("Debug Render Buffer");
+ getRenderer().queueRenderBuffer(&m_physicsScene->getRenderBuffer());
+ PROFILER_END();
+ }
}
@@ -363,8 +426,11 @@ void PhysXController::updateDragging(double dt)
PxVec3 hookPoint = m_draggingActor->getGlobalPose().transform(m_draggingActorHookLocalPoint);
m_draggingActorLastHookWorldPoint = hookPoint;
m_dragVector = (m_dragAttractionPoint - hookPoint);
- PxVec3 dragVeloctiy = (m_dragVector * DRAGGING_FORCE_FACTOR - DRAGGING_VELOCITY_FACTOR * m_draggingActor->getLinearVelocity()) * dt;
- PxRigidBodyExt::addForceAtLocalPos(*m_draggingActor, dragVeloctiy * m_draggingActor->getMass(), m_draggingActorHookLocalPoint, PxForceMode::eIMPULSE, true);
+ if (!m_draggingActor->getRigidBodyFlags().isSet(PxRigidBodyFlag::eKINEMATIC))
+ {
+ PxVec3 dragVeloctiy = (m_dragVector * DRAGGING_FORCE_FACTOR - DRAGGING_VELOCITY_FACTOR * m_draggingActor->getLinearVelocity()) * dt;
+ PxRigidBodyExt::addForceAtLocalPos(*m_draggingActor, dragVeloctiy * m_draggingActor->getMass(), m_draggingActorHookLocalPoint, PxForceMode::eIMPULSE, true);
+ }
// debug render line
m_dragDebugRenderBuffer.clear();
@@ -404,9 +470,12 @@ LRESULT PhysXController::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa
m_dragDistance = (eyePos - hit.position).magnitude();
m_draggingActor = hit.actor->is<PxRigidDynamic>();
m_draggingActorHookLocalPoint = m_draggingActor->getGlobalPose().getInverse().transform(hit.position);
- m_draggingActor->setLinearVelocity(PxVec3(0, 0, 0));
- m_draggingActor->setAngularVelocity(PxVec3(0, 0, 0));
m_dragAttractionPoint = hit.position;
+ if (!m_draggingActor->getRigidBodyFlags().isSet(PxRigidBodyFlag::eKINEMATIC))
+ {
+ m_draggingActor->setLinearVelocity(PxVec3(0, 0, 0));
+ m_draggingActor->setAngularVelocity(PxVec3(0, 0, 0));
+ }
}
}
}
@@ -433,6 +502,71 @@ LRESULT PhysXController::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Explosion
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+class ExplodeOverlapCallback : public PxOverlapCallback
+{
+public:
+ ExplodeOverlapCallback(PxVec3 worldPos, float radius, float explosiveImpulse)
+ : m_worldPos(worldPos)
+ , m_radius(radius)
+ , m_explosiveImpulse(explosiveImpulse)
+ , PxOverlapCallback(m_hitBuffer, sizeof(m_hitBuffer) / sizeof(m_hitBuffer[0])) {}
+
+ PxAgain processTouches(const PxOverlapHit* buffer, PxU32 nbHits)
+ {
+ for (PxU32 i = 0; i < nbHits; ++i)
+ {
+ PxRigidActor* actor = buffer[i].actor;
+ PxRigidDynamic* rigidDynamic = actor->is<PxRigidDynamic>();
+ if (rigidDynamic && !(rigidDynamic->getRigidBodyFlags() & PxRigidBodyFlag::eKINEMATIC))
+ {
+ if (m_actorBuffer.find(rigidDynamic) == m_actorBuffer.end())
+ {
+ m_actorBuffer.insert(rigidDynamic);
+ PxVec3 dr = rigidDynamic->getGlobalPose().transform(rigidDynamic->getCMassLocalPose()).p - m_worldPos;
+ float distance = dr.magnitude();
+ float factor = PxClamp(1.0f - (distance * distance) / (m_radius * m_radius), 0.0f, 1.0f);
+ float impulse = factor * m_explosiveImpulse * 1000.0f;
+ PxVec3 vel = dr.getNormalized() * impulse / rigidDynamic->getMass();
+ rigidDynamic->setLinearVelocity(rigidDynamic->getLinearVelocity() + vel);
+ }
+ }
+ }
+ return true;
+ }
+
+private:
+ PxOverlapHit m_hitBuffer[1000];
+ float m_explosiveImpulse;
+ std::set<PxRigidDynamic*> m_actorBuffer;
+ PxVec3 m_worldPos;
+ float m_radius;
+};
+
+void PhysXController::explode(PxVec3 worldPos, float damageRadius, float explosiveImpulse)
+{
+ ExplodeOverlapCallback overlapCallback(worldPos, damageRadius, explosiveImpulse);
+ m_physicsScene->overlap(PxSphereGeometry(damageRadius), PxTransform(worldPos), overlapCallback);
+}
+
+void PhysXController::explodeDelayed(PxVec3 worldPos, float damageRadius, float explosiveImpulse)
+{
+ m_explosionQueue.push_back({ worldPos, damageRadius, explosiveImpulse });
+}
+
+void PhysXController::processExplosionQueue()
+{
+ for (auto& e : m_explosionQueue)
+ {
+ explode(e.worldPos, e.damageRadius, e.explosiveImpulse);
+ }
+ m_explosionQueue.clear();
+}
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// UI
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -446,8 +580,7 @@ void PhysXController::drawUI()
}
ImGui::Text("Substep Count: %d", m_substepCount);
- ImGui::Text("Simulation Time (total): %4.2f ms", getLastSimulationTime() * 1000);
- ImGui::Text("Simulation Time (substep): %4.2f ms", m_substepCount > 0 ? (getLastSimulationTime() / m_substepCount) * 1000 : 0.0);
+ ImGui::Text("Sync Simulation Time (total): %4.2f ms", getLastSimulationTime() * 1000);
}
@@ -456,6 +589,10 @@ void PhysXController::drawUI()
// PhysX Primitive
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Add By Lixu Begin
+PhysXController::Actor* planeActor_Pri = nullptr;
+// Add By Lixu End
+
void PhysXController::initPhysXPrimitives()
{
// physx primitive render materials
@@ -470,6 +607,11 @@ void PhysXController::initPhysXPrimitives()
// create plane
Actor* plane = spawnPhysXPrimitivePlane(PxPlane(PxVec3(0, 1, 0).getNormalized(), 0));
plane->setColor(PLANE_COLOR);
+
+// Add By Lixu Begin
+ planeActor_Pri = plane;
+ planeActor_Pri->setHidden(true);
+// Add By Lixu End
}
void PhysXController::releasePhysXPrimitives()
@@ -557,7 +699,7 @@ void PhysXController::removeUnownedPhysXActors()
{
if (m_physXActorsToRemove.size())
{
- m_physicsScene->removeActors(&m_physXActorsToRemove[0], (PxU32)m_physXActorsToRemove.size());
+ m_physicsScene->removeActors(m_physXActorsToRemove.data(), (PxU32)m_physXActorsToRemove.size());
for (size_t i = 0; i < m_physXActorsToRemove.size(); ++i)
{
m_physXActorsToRemove[i]->release();
@@ -580,7 +722,7 @@ PhysXController::Actor::Actor(PhysXController* controller, PxRigidActor* actor,
uint32_t shapesCount = actor->getNbShapes();
m_shapes.resize(shapesCount);
- actor->getShapes(&m_shapes[0], shapesCount);
+ actor->getShapes(m_shapes.data(), shapesCount);
m_renderables.resize(m_shapes.size());
for (uint32_t i = 0; i < m_shapes.size(); i++)
@@ -724,8 +866,23 @@ PxVec3 unproject(PxMat44& proj, PxMat44& view, float x, float y)
void PhysXController::getEyePoseAndPickDir(float mouseX, float mouseY, PxVec3& eyePos, PxVec3& pickDir)
{
- PxMat44 view = XMMATRIXToPxMat44(getRenderer().getCamera().GetViewMatrix());
- PxMat44 proj = XMMATRIXToPxMat44(getRenderer().getCamera().GetProjMatrix());
+ // Add By Lixu Begin
+ PxMat44 view, proj;
+ SimpleScene* simpleScene = SimpleScene::Inst();
+ Camera* pSceneCamera = simpleScene->GetCamera();
+ if (pSceneCamera->UseLHS())
+ {
+ DirectX::XMMATRIX viewMatrix = SimpleScene::Inst()->GetViewMatrix();
+ DirectX::XMMATRIX projMatrix = SimpleScene::Inst()->GetProjMatrix();
+ view = XMMATRIXToPxMat44(viewMatrix);
+ proj = XMMATRIXToPxMat44(projMatrix);
+ }
+ else
+ {
+ view = XMMATRIXToPxMat44(getRenderer().getCamera().GetViewMatrix());
+ proj = XMMATRIXToPxMat44(getRenderer().getCamera().GetProjMatrix());
+ }
+ // Add By Lixu End
PxMat44 eyeTransform = view.inverseRT();
eyePos = eyeTransform.getPosition();
@@ -750,7 +907,6 @@ bool PhysXController::ExportCollisionRepX(const char* fname, physx::PxPhysics* p
return false;
int count = pSDK->getNbScenes();
- assert(count == 1);
physx::PxSerializationRegistry* psr = physx::PxSerialization::createSerializationRegistry(*pSDK);
@@ -822,4 +978,77 @@ void PhysXController::ClearOldCOllisions()
size = m_physics->getNbConvexMeshes();
}
}
-// Add By Lixu Begin
+
+bool PhysXController::isPlaneVisible()
+{
+ return !planeActor_Pri->isHidden();
+}
+
+void PhysXController::setPlaneVisible(bool bVisible)
+{
+ planeActor_Pri->setHidden(!bVisible);
+}
+
+PxRigidDynamic* PhysXController::createEditPhysXActor(const std::vector<BlastModel::Chunk::Mesh>& meshes, const PxTransform& pos)
+{
+ PxRigidDynamic *actor = m_physics->createRigidDynamic(PxTransform(pos));
+
+ for (size_t i = 0; i < meshes.size(); ++i)
+ {
+ const SimpleMesh& mesh = meshes[i].mesh;
+
+ size_t vertexCount = mesh.vertices.size();
+ if (vertexCount == 0)
+ {
+ continue;
+ }
+ PxVec3* verts = new PxVec3[vertexCount];
+ for (size_t i = 0; i < vertexCount; ++i)
+ {
+ verts[i] = mesh.vertices[i].position;
+ }
+
+ PxConvexMeshDesc convexDesc;
+ convexDesc.points.count = vertexCount;
+ convexDesc.points.stride = sizeof(PxVec3);
+ convexDesc.points.data = verts;
+ convexDesc.flags = PxConvexFlag::eCOMPUTE_CONVEX;
+
+ {
+ PxCookingParams params = m_cooking->getParams();
+ params.convexMeshCookingType = PxConvexMeshCookingType::eQUICKHULL;
+ m_cooking->setParams(params);
+
+ PxDefaultMemoryOutputStream outStream;
+ bool bCooking = m_cooking->cookConvexMesh(convexDesc, outStream);
+ PxU8* outStreamData = outStream.getData();
+ PxU32 outStreamSize = outStream.getSize();
+ if (!bCooking || outStreamData == nullptr || outStreamSize == 0)
+ {
+ delete[] verts;
+ continue;
+ }
+
+ PxDefaultMemoryInputData input(outStreamData, outStreamSize);
+ PxConvexMesh* convexMesh = m_physics->createConvexMesh(input);
+ if (convexMesh == nullptr)
+ {
+ delete[] verts;
+ continue;
+ }
+ PxShape* shape = m_physics->createShape(PxConvexMeshGeometry(convexMesh), *m_defaultMaterial);
+ if (shape)
+ {
+ actor->attachShape(*shape);
+ }
+
+ }
+
+ delete[] verts;
+ }
+
+ actor->setRigidBodyFlag(PxRigidBodyFlag::eKINEMATIC, true);
+ m_editPhysicsScene->addActor(*actor);
+ return actor;
+}
+// Add By Lixu End
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/physx/PhysXController.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/physx/PhysXController.h
index 2473526..fc59203 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/physx/PhysXController.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/physx/PhysXController.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef PHYSX_CONTROLLER_H
#define PHYSX_CONTROLLER_H
@@ -15,10 +33,11 @@
#include <DirectXMath.h>
#include "DebugRenderBuffer.h"
#include "PxFiltering.h"
-#include "PxDefaultAllocator.h"
-#include "PxDefaultErrorCallback.h"
#include <set>
#include <map>
+// Add By Lixu Begin
+#include "BlastModel.h"
+// Add By Lixu End
using namespace physx;
@@ -27,13 +46,14 @@ class PerformanceDataWriter;
class RenderMaterial;
class Renderable;
class IRenderMesh;
+// Add By Lixu Begin
+class SimpleMesh;
+// Add By Lixu End
namespace physx
{
class PxCpuDispatcher;
class PxFoundation;
-class PxDefaultAllocator;
-class PxDefaultErrorCallback;
class PxPhysics;
class PxCooking;
class PxPvd;
@@ -95,16 +115,17 @@ class PhysXController : public ISampleController
//////// virtual callbacks ////////
- virtual void onInitialize();
- virtual void onTerminate();
-
- virtual void Animate(double dt);
+ virtual void onInitialize() override;
+ virtual void onTerminate() override;
virtual LRESULT MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
//////// public API ////////
+ void simulationBegin(float dt);
+ void simualtionSyncEnd();
+
void getEyePoseAndPickDir(float mouseX, float mouseY, PxVec3& eyePos, PxVec3& pickDir);
// wrappers to physx calls
@@ -138,6 +159,9 @@ class PhysXController : public ISampleController
void notifyRigidDynamicDestroyed(PxRigidDynamic*);
+ void explode(PxVec3 worldPos, float damageRadius, float explosiveImpulse);
+ void explodeDelayed(PxVec3 worldPos, float damageRadius, float explosiveImpulse);
+
void drawUI();
//////// public getters ////////
@@ -159,7 +183,16 @@ class PhysXController : public ISampleController
{
return m_physXPlaneRenderMaterial;
}
- bool m_bForce;
+ bool m_bFirstTime;
+ bool isPlaneVisible();
+ void setPlaneVisible(bool bVisible);
+
+ PxScene& getEditPhysXScene() const
+ {
+ return *m_editPhysicsScene;
+ }
+
+ PxRigidDynamic* createEditPhysXActor(const std::vector<BlastModel::Chunk::Mesh>& meshes, const PxTransform& pos);
// Add By Lixu End
PxPhysics& getPhysics() const
@@ -229,6 +262,7 @@ class PhysXController : public ISampleController
void releasePhysXPrimitives();
void updateActorTransforms();
void updateDragging(double dt);
+ void processExplosionQueue();
//////// used controllers ////////
@@ -243,8 +277,6 @@ class PhysXController : public ISampleController
// PhysX
PxFoundation* m_foundation;
- PxDefaultAllocator m_allocator;
- PxDefaultErrorCallback m_errorCallback;
PxPhysics* m_physics;
PxCooking* m_cooking;
PxPvd* m_pvd;
@@ -253,6 +285,9 @@ class PhysXController : public ISampleController
PxMaterial* m_defaultMaterial;
PxSimulationFilterShader m_filterShader;
PxScene* m_physicsScene;
+ // Add By Lixu Begin
+ PxScene* m_editPhysicsScene;
+ // Add By Lixu End
// PhysX API related
std::vector<PxActor*> m_physXActorsToRemove;
@@ -265,9 +300,10 @@ class PhysXController : public ISampleController
RenderMaterial* m_physXPrimitiveTransparentRenderMaterial;
// simulation
+ bool m_isSimulating;
bool m_gpuPhysicsAvailable;
bool m_useGPUPhysics;
- double m_lastSimulationTime;
+ double m_lastSimulationTime;
LARGE_INTEGER m_performanceFreq;
bool m_paused;
bool m_useFixedTimeStep;
@@ -290,6 +326,15 @@ class PhysXController : public ISampleController
// Performance writer
PerformanceDataWriter* m_perfWriter;
+ // explosion
+ struct ExplosionData
+ {
+ PxVec3 worldPos;
+ float damageRadius;
+ float explosiveImpulse;
+ };
+
+ std::vector<ExplosionData> m_explosionQueue;
};
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ConvexRenderMesh.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ConvexRenderMesh.cpp
index 074cc2d..dc938b9 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ConvexRenderMesh.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ConvexRenderMesh.cpp
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "ConvexRenderMesh.h"
#include "Renderer.h"
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ConvexRenderMesh.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ConvexRenderMesh.h
index dfe8d8f..f7bc5c6 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ConvexRenderMesh.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ConvexRenderMesh.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef CONVEX_RENDER_MESH_H
#define CONVEX_RENDER_MESH_H
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/CustomRenderMesh.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/CustomRenderMesh.cpp
index 61ae9e0..0feae3f 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/CustomRenderMesh.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/CustomRenderMesh.cpp
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "CustomRenderMesh.h"
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/CustomRenderMesh.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/CustomRenderMesh.h
index b0ddea1..025d3bf 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/CustomRenderMesh.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/CustomRenderMesh.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef CUSTOM_RENDER_MESH_H
#define CUSTOM_RENDER_MESH_H
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/DebugRenderBuffer.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/DebugRenderBuffer.h
index 7810733..06cd509 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/DebugRenderBuffer.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/DebugRenderBuffer.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef DEBUGRENDERBUFFER_H
#define DEBUGRENDERBUFFER_H
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Mesh.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Mesh.cpp
index cdf63f2..c6c8398 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Mesh.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Mesh.cpp
@@ -1,12 +1,29 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
#include "Mesh.h"
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Mesh.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Mesh.h
index b10f0d6..fa214e0 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Mesh.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Mesh.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef MESH_H
#define MESH_H
@@ -38,6 +56,7 @@ public:
public:
physx::PxVec3 position;
physx::PxVec3 normal;
+ physx::PxVec3 tangent;
physx::PxVec2 uv;
};
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/PrimitiveRenderMesh.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/PrimitiveRenderMesh.cpp
index 06c7616..bcb1580 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/PrimitiveRenderMesh.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/PrimitiveRenderMesh.cpp
@@ -1,12 +1,29 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
#include "PrimitiveRenderMesh.h"
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/PrimitiveRenderMesh.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/PrimitiveRenderMesh.h
index 0f3f345..107af25 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/PrimitiveRenderMesh.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/PrimitiveRenderMesh.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef PRIMITIVE_RENDER_MESH_H
#define PRIMITIVE_RENDER_MESH_H
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderMaterial.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderMaterial.cpp
index 1b90f8f..a9fedf0 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderMaterial.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderMaterial.cpp
@@ -1,20 +1,38 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "RenderMaterial.h"
#include <DirectXMath.h>
#include "ShaderUtils.h"
#include "Renderer.h"
#include "SampleManager.h"
-
-
+#include "Light.h"
+#include "D3D11TextureResource.h"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// RenderMaterial
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -22,15 +40,20 @@
RenderMaterial::RenderMaterial(const char* materialName, ResourceManager& resourceCallback, const char* shaderFileName,
const char* textureFileName, BlendMode blendMode)
{
-// Add By Lixu Begin
mMaterialName = materialName;
- mTextureFileName = textureFileName;
- SampleManager::ins()->addRenderMaterial(this);
-// Add By Lixu End
+ setDiffuseColor(0.5, 0.5, 0.5, 1.0);
+ mTextureFileNames[TT_Diffuse] = textureFileName;
this->initialize(resourceCallback, shaderFileName, textureFileName, blendMode);
}
+RenderMaterial::RenderMaterial(const char* materialName, ResourceManager& resourceCallback, const char* shaderFileName, float r, float g, float b, float a, BlendMode blendMode)
+{
+ mMaterialName = materialName;
+ setDiffuseColor(r, g, b, a);
+ this->initialize(resourceCallback, shaderFileName, "", blendMode);
+}
+
void RenderMaterial::initialize(ResourceManager& resourceCallback, const char* shaderFileName, const char* textureFileName, BlendMode blendMode)
{
std::vector<std::string> v;
@@ -40,10 +63,16 @@ void RenderMaterial::initialize(ResourceManager& resourceCallback, const char* s
void RenderMaterial::initialize(ResourceManager& resourceCallback, std::vector<std::string> shaderFileNames, const char* textureFileName, BlendMode blendMode)
{
- mTextureSRV = nullptr;
- mTexture = nullptr;
+ for (int i = 0; i < TT_Num; i++)
+ {
+ m_TextureSRVs[i] = nullptr;
+ mTextureResources[i] = nullptr;
+ }
mBlendState = nullptr;
+ memset(mSpecularColor, 0, sizeof(float) * 4);
+ mSpecularShininess = 20;
+
for (uint32_t i = 0; i < shaderFileNames.size(); i++)
{
const ShaderFileResource* resource = resourceCallback.requestShaderFile(shaderFileNames[i].c_str());
@@ -55,9 +84,9 @@ void RenderMaterial::initialize(ResourceManager& resourceCallback, std::vector<s
}
mShaderGroups.reserve(mShaderFilePathes.size());
- if (!mTextureFileName.empty())
+ if (!mTextureFileNames[TT_Diffuse].empty())
{
- mTexture = resourceCallback.requestTexture(mTextureFileName.c_str());
+ mTextureResources[TT_Diffuse] = resourceCallback.requestTexture(mTextureFileNames[TT_Diffuse].c_str());
}
setBlending(blendMode);
@@ -82,15 +111,14 @@ void RenderMaterial::releaseReloadableResources()
mRenderMeshToInstanceMap.clear();
// Add By Lixu End
- SAFE_RELEASE(mTextureSRV);
+ for (int i = 0; i < TT_Num; i++)
+ {
+ SAFE_RELEASE(m_TextureSRVs[i]);
+ }
}
RenderMaterial::~RenderMaterial()
{
-// Add By Lixu Begin
- SampleManager::ins()->removeRenderMaterial(mMaterialName);
-// Add By Lixu End
-
releaseReloadableResources();
SAFE_RELEASE(mBlendState);
}
@@ -160,10 +188,15 @@ void RenderMaterial::reload()
}
// load texture
- if (mTexture)
+ for (int i = 0; i < TT_Num; i++)
{
- V(DirectX::CreateShaderResourceView(device, mTexture->image.GetImages(), mTexture->image.GetImageCount(),
- mTexture->metaData, &mTextureSRV));
+ if (mTextureResources[i])
+ {
+ V(DirectX::CreateShaderResourceView(device,
+ mTextureResources[i]->image.GetImages(),
+ mTextureResources[i]->image.GetImageCount(),
+ mTextureResources[i]->metaData, &m_TextureSRVs[i]));
+ }
}
}
@@ -219,8 +252,12 @@ void RenderMaterial::Instance::bind(ID3D11DeviceContext& context, uint32_t slot,
{
mMaterial.mShaderGroups[mShaderNum]->Set(&context, !depthStencilOnly);
+ GPUShaderResource* pResource = Light::GetEnvTextureSRV();
+ ID3D11ShaderResourceView* pEnvTextureSRV = D3D11TextureResource::GetResource(pResource);
+
context.OMSetBlendState(mMaterial.mBlendState, nullptr, 0xFFFFFFFF);
- context.PSSetShaderResources(slot, 1, &(mMaterial.mTextureSRV));
+ context.PSSetShaderResources(slot, TT_Num, mMaterial.m_TextureSRVs);
+ context.PSSetShaderResources(TT_Num, 1, &pEnvTextureSRV);
context.IASetInputLayout(mInputLayout);
}
@@ -230,38 +267,72 @@ bool RenderMaterial::Instance::isValid()
}
// Add By Lixu Begin
-void RenderMaterial::setTextureFileName(std::string textureFileName)
+void RenderMaterial::setTextureFileName(std::string textureFileName, TextureType tt)
{
- if (mTextureFileName == textureFileName)
+ if (mTextureFileNames[tt] == textureFileName)
{
return;
}
+ mTextureFileNames[tt] = textureFileName;
- mTextureFileName = textureFileName;
- mTexture = nullptr;
- SAFE_RELEASE(mTextureSRV);
+ mTextureResources[tt] = nullptr;
+ SAFE_RELEASE(m_TextureSRVs[tt]);
- if (mTextureFileName.empty())
+ if (mTextureFileNames[tt].empty())
{
return;
}
- std::string searchDir = mTextureFileName;
+ std::string searchDir = mTextureFileNames[tt];
size_t ind = searchDir.find_last_of('/');
if (ind > 0)
searchDir = searchDir.substr(0, ind);
ResourceManager* pResourceManager = ResourceManager::ins();
pResourceManager->addSearchDir(searchDir.c_str());
- mTexture = pResourceManager->requestTexture(mTextureFileName.c_str());
- if (mTexture == nullptr)
+ mTextureResources[tt] = pResourceManager->requestTexture(mTextureFileNames[tt].c_str());
+ if (mTextureResources[tt] == nullptr)
{
return;
}
ID3D11Device* device = GetDeviceManager()->GetDevice();
- DirectX::CreateShaderResourceView(device, mTexture->image.GetImages(), mTexture->image.GetImageCount(),
- mTexture->metaData, &mTextureSRV);
+ DirectX::CreateShaderResourceView(device,
+ mTextureResources[tt]->image.GetImages(),
+ mTextureResources[tt]->image.GetImageCount(),
+ mTextureResources[tt]->metaData, &m_TextureSRVs[tt]);
+}
+
+void RenderMaterial::setDiffuseColor(float r, float g, float b, float a)
+{
+ mDiffuseColor[0] = r;
+ mDiffuseColor[1] = g;
+ mDiffuseColor[2] = b;
+ mDiffuseColor[3] = a;
+}
+
+void RenderMaterial::getDiffuseColor(float& r, float& g, float& b, float& a)
+{
+ r = mDiffuseColor[0];
+ g = mDiffuseColor[1];
+ b = mDiffuseColor[2];
+ a = mDiffuseColor[3];
+}
+
+void RenderMaterial::setSpecularColor(float r, float g, float b, float a)
+{
+ mSpecularColor[0] = r;
+ mSpecularColor[1] = g;
+ mSpecularColor[2] = b;
+ mSpecularColor[3] = a;
+}
+
+void RenderMaterial::getSpecularColor(float& r, float& g, float& b, float& a)
+{
+ r = mSpecularColor[0];
+ g = mSpecularColor[1];
+ b = mSpecularColor[2];
+ a = mSpecularColor[3];
}
RenderMaterial* g_DefaultRenderMaterial = nullptr;
@@ -270,8 +341,13 @@ RenderMaterial* RenderMaterial::getDefaultRenderMaterial()
if (g_DefaultRenderMaterial == nullptr)
{
ResourceManager* pResourceManager = ResourceManager::ins();
- g_DefaultRenderMaterial = new RenderMaterial("", *pResourceManager, "model_simple_ex");
+ g_DefaultRenderMaterial = new RenderMaterial("", *pResourceManager, "model_simple_textured_ex", 0.5, 0.5, 0.5);
}
return g_DefaultRenderMaterial;
}
+
+bool RenderMaterial::isBadTexture(TextureType tt)
+{
+ return (nullptr == m_TextureSRVs[tt]);
+}
// Add By Lixu End \ No newline at end of file
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderMaterial.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderMaterial.h
index e144a94..27f0672 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderMaterial.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderMaterial.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef RENDER_MATERIAL_H
#define RENDER_MATERIAL_H
@@ -38,7 +56,16 @@ class RenderMaterial
BLEND_ADDITIVE
};
+ enum TextureType
+ {
+ TT_Diffuse,
+ TT_Specular,
+ TT_Normal,
+ TT_Num
+ };
+
RenderMaterial(const char* materialName, ResourceManager& resourceProvider, const char* shaderFileName, const char* textureFileName = "", BlendMode blendMode = BLEND_NONE);
+ RenderMaterial(const char* materialName, ResourceManager& resourceProvider, const char* shaderFileName, float r, float g, float b, float a = 1.0, BlendMode blendMode = BLEND_NONE);
~RenderMaterial();
void setBlending(BlendMode blendMode);
@@ -65,11 +92,18 @@ class RenderMaterial
typedef Instance* InstancePtr;
std::string getMaterialName(){ return mMaterialName; }
void setMaterialName(std::string materialName){ mMaterialName = materialName; }
- std::string getTextureFileName(){ return mTextureFileName; }
- void setTextureFileName(std::string textureFileName);
+ std::string getTextureFileName(TextureType tt = TT_Diffuse){ return mTextureFileNames[tt]; }
+ void setTextureFileName(std::string textureFileName, TextureType tt = TT_Diffuse);
+ void getDiffuseColor(float& r, float& g, float& b, float& a);
+ void setDiffuseColor(float r, float g, float b, float a = 1.0);
+ void getSpecularColor(float& r, float& g, float& b, float& a);
+ void setSpecularColor(float r, float g, float b, float a = 1.0);
+ float getSpecularShininess() { return mSpecularShininess; }
+ void setSpecularShininess(float specularShininess) { mSpecularShininess = specularShininess; }
void addRelatedRenderable(Renderable* pRenderable){ mRelatedRenderables.push_back(pRenderable); }
std::vector<Renderable*>& getRelatedRenderables(){ return mRelatedRenderables; }
void clearRelatedRenderables(){ mRelatedRenderables.clear(); }
+ bool isBadTexture(TextureType tt = TT_Diffuse);
static RenderMaterial* getDefaultRenderMaterial();
// Add By Lixu End
@@ -84,7 +118,7 @@ class RenderMaterial
std::string mMaterialName;
std::string mShaderFileName;
- std::string mTextureFileName;
+// std::string mTextureFileName;
struct ShaderGroup
{
@@ -121,13 +155,24 @@ class RenderMaterial
// Add By Lixu Begin
std::map<const IRenderMesh*, Instance*> mRenderMeshToInstanceMap;
std::vector<Renderable*> mRelatedRenderables;
+// float mr;
+// float mg;
+// float mb;
+// float ma;
// Add By Lixu End
- const TextureResource* mTexture;
- ID3D11ShaderResourceView* mTextureSRV;
+// const TextureResource* mTexture;
+// ID3D11ShaderResourceView* mTextureSRV;
std::vector<std::string> mShaderFilePathes;
std::vector<ShaderGroup*> mShaderGroups;
ID3D11BlendState* mBlendState;
BlendMode mBlendMode;
+
+ std::string mTextureFileNames[TT_Num];
+ const TextureResource* mTextureResources[TT_Num];
+ ID3D11ShaderResourceView* m_TextureSRVs[TT_Num];
+ float mDiffuseColor[4];
+ float mSpecularColor[4];
+ float mSpecularShininess;
};
#endif \ No newline at end of file
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderUtils.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderUtils.h
index 12df9f2..098f7a9 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderUtils.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderUtils.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef RENDER_UTILS_H
#define RENDER_UTILS_H
@@ -75,4 +93,27 @@ static DirectX::XMFLOAT4 XMFLOAT4Lerp(const DirectX::XMFLOAT4 v0, const DirectX:
return v;
}
+static const physx::PxVec3 forwardVector = physx::PxVec3(0, 0, 1);
+static const physx::PxVec3 upVector = physx::PxVec3(0, 1, 0);
+static const physx::PxVec3 rightVector = physx::PxVec3(1, 0, 0);
+
+PX_INLINE physx::PxQuat quatLookAt(const physx::PxVec3 direction)
+{
+ float d = direction.dot(forwardVector);
+ if (physx::PxAbs(d + 1.0f) < 1e-5f)
+ {
+ return physx::PxQuat(physx::PxPi, upVector);
+ }
+ else if (physx::PxAbs(d - 1.0f) < 1e-5f)
+ {
+ return physx::PxQuat(physx::PxIdentity);
+ }
+ else
+ {
+ float angle = physx::PxAcos(d);
+ physx::PxVec3 axis = forwardVector.cross(direction).getNormalized();
+ return physx::PxQuat(angle, axis);
+ }
+}
+
#endif //RENDER_UTILS_H \ No newline at end of file
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderable.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderable.cpp
index 51569b7..5ce713d 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderable.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderable.cpp
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "Renderable.h"
#include "Renderer.h"
@@ -17,6 +35,8 @@ const DirectX::XMFLOAT4 DEFAULT_COLOR(0.5f, 0.5f, 0.5f, 1.0f);
Renderable::Renderable(IRenderMesh& mesh, RenderMaterial& material) : m_mesh(mesh), m_scale(1, 1, 1), m_color(DEFAULT_COLOR), m_hidden(false), m_transform(PxIdentity)
// Add By Lixu Begin
, m_selected(false)
+, m_depthTest(true)
+, m_highlight(false)
// Add By Lixu End
{
setMaterial(material);
@@ -37,17 +57,65 @@ void Renderable::render(Renderer& renderer, bool depthStencilOnly) const
}
m_materialInstance->bind(*renderer.m_context, 0, depthStencilOnly);
+
+ DirectX::XMFLOAT4 diffuseColor = getColor();
+ DirectX::XMFLOAT4 specularColor = diffuseColor;
+ float useDiffuseTexture = -1.0;
+ float useSpecularTexture = -1.0;
+ float useNormalTexture = -1.0;
+ float specularShininess = 1.0;
+ RenderMaterial& renderMaterial = m_materialInstance->getMaterial();
+ std::string mName = renderMaterial.getMaterialName();
+ if (mName != "")
+ {
+ float r, g, b, a;
+ std::string texName;
+
+ renderMaterial.getDiffuseColor(r, g, b, a);
+ diffuseColor = DirectX::XMFLOAT4(r, g, b, a);
+ renderMaterial.getSpecularColor(r, g, b, a);
+ specularColor = DirectX::XMFLOAT4(r, g, b, a);
+
+ texName = renderMaterial.getTextureFileName();
+ if (texName != "" && !renderMaterial.isBadTexture())
+ {
+ useDiffuseTexture = 1.0;
+ }
+
+ texName = renderMaterial.getTextureFileName(RenderMaterial::TT_Specular);
+ if (texName != "" && !renderMaterial.isBadTexture(RenderMaterial::TT_Specular))
+ {
+ useSpecularTexture = 1.0;
+ }
+
+ texName = renderMaterial.getTextureFileName(RenderMaterial::TT_Normal);
+ if (texName != "" && !renderMaterial.isBadTexture(RenderMaterial::TT_Normal))
+ {
+ useNormalTexture = 1.0;
+ }
+
+ specularShininess = renderMaterial.getSpecularShininess();
+ }
+
+ float selected = -1.0;
+ if (m_selected || m_highlight)
+ {
+ selected = 1.0;
+ }
// setup object CB
{
D3D11_MAPPED_SUBRESOURCE mappedResource;
renderer.m_context->Map(renderer.m_objectCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
Renderer::CBObject* objectBuffer = (Renderer::CBObject*)mappedResource.pData;
- objectBuffer->world = PxMat44ToXMMATRIX(getModelMatrix());
- objectBuffer->color = getColor();
-// Add By Lixu Begin
- objectBuffer->selected = m_selected ? 1.0 : -1.0;
-// Add By Lixu End
+ objectBuffer->worldMatrix = PxMat44ToXMMATRIX(getModelMatrix());
+ objectBuffer->diffuseColor = diffuseColor;
+ objectBuffer->specularColor = specularColor;
+ objectBuffer->useDiffuseTexture = useDiffuseTexture;
+ objectBuffer->useSpecularTexture = useSpecularTexture;
+ objectBuffer->useNormalTexture = useNormalTexture;
+ objectBuffer->specularShininess = specularShininess;
+ objectBuffer->selected = selected;
renderer.m_context->Unmap(renderer.m_objectCB, 0);
}
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderable.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderable.h
index 9e38e4f..2d2e37b 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderable.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderable.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef RENDERABLE_H
#define RENDERABLE_H
@@ -105,6 +123,26 @@ public:
{
m_mesh.setScale(scale, replace);
}
+
+ void setDepthTest(bool depthTest)
+ {
+ m_depthTest = depthTest;
+ }
+
+ bool isDepthTest() const
+ {
+ return m_depthTest;
+ }
+
+ void setHighlight(bool highlight)
+ {
+ m_highlight = highlight;
+ }
+
+ bool isHighlight() const
+ {
+ return m_highlight;
+ }
// Add By Lixu End
bool isTransparent() const
@@ -145,6 +183,8 @@ private:
bool m_hidden;
// Add By Lixu Begin
bool m_selected;
+ bool m_depthTest;
+ bool m_highlight;
// Add By Lixu End
};
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderer.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderer.cpp
index 49b1669..9fe5038 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderer.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderer.cpp
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "Renderer.h"
#include "RenderUtils.h"
@@ -16,6 +34,10 @@
#include "PxRenderBuffer.h"
#include <set>
+#include "SimpleScene.h"
+#include "GlobalSettings.h"
+#include "Light.h"
+#include "AppMainWindow.h"
const float CAMERA_CLIP_NEAR = 1.0f;
@@ -36,6 +58,7 @@ Renderer::Renderer()
, m_RSState(nullptr)
, m_opaqueRenderDSState(nullptr)
, m_transparencyRenderDSState(nullptr)
+, m_opaqueRenderNoDepthDSState(nullptr)
, m_DSTexture(nullptr)
, m_DSView(nullptr)
, m_DSTextureSRV(nullptr)
@@ -152,6 +175,18 @@ HRESULT Renderer::DeviceCreated(ID3D11Device* device)
V(device->CreateDepthStencilState(&desc, &m_transparencyRenderDSState));
}
+ // Opaque Render Depth-Stencil state Without Depth Test
+ {
+ D3D11_DEPTH_STENCIL_DESC desc;
+ ZeroMemory(&desc, sizeof(desc));
+ desc.StencilEnable = FALSE;
+ desc.DepthEnable = FALSE;
+ desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
+ desc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
+
+ V(device->CreateDepthStencilState(&desc, &m_opaqueRenderNoDepthDSState));
+ }
+
// Linear sampler
{
D3D11_SAMPLER_DESC desc;
@@ -210,6 +245,7 @@ void Renderer::DeviceDestroyed()
SAFE_RELEASE(m_RSState);
SAFE_RELEASE(m_opaqueRenderDSState);
SAFE_RELEASE(m_transparencyRenderDSState);
+ SAFE_RELEASE(m_opaqueRenderNoDepthDSState);
SAFE_RELEASE(m_pointSampler);
SAFE_RELEASE(m_linearSampler);
SAFE_RELEASE(m_debugPrimitiveVB);
@@ -226,12 +262,10 @@ void Renderer::DeviceDestroyed()
void Renderer::onInitialize()
{
// search paths
- m_resourceManager.addSearchDir("..\\..\\samples\\resources");
- m_resourceManager.addSearchDir("..\\..\\..\\samples\\resources");
- for (const std::string& d : getManager()->getConfig().additionalResourcesDir)
- {
- m_resourceManager.addSearchDir(d.c_str());
- }
+ m_resourceManager.addSearchDir("..\\resources");
+ m_resourceManager.addSearchDir("..\\..\\..\\..\\bin\\resources");
+ //m_resourceManager.addSearchDir("..\\..\\samples\\resources");
+ //m_resourceManager.addSearchDir("..\\..\\..\\samples\\resources");
// debug primitive render material and input layout
{
@@ -257,7 +291,8 @@ void Renderer::BackBufferResized(ID3D11Device* /*device*/, const DXGI_SURFACE_DE
m_screenWidth = sd->Width;
m_screenHeight = sd->Height;
float fAspectRatio = m_screenWidth / m_screenHeight;
- m_camera.SetProjParams(DirectX::XM_PIDIV4, fAspectRatio, CAMERA_CLIP_NEAR, CAMERA_CLIP_FAR);
+ float fov = (GlobalSettings::Inst().m_fovAngle / 360.0f) * 3.141592653589793;
+ m_camera.SetProjParams(fov, fAspectRatio, CAMERA_CLIP_NEAR, CAMERA_CLIP_FAR);
SAFE_RELEASE(m_DSTexture);
SAFE_RELEASE(m_DSView);
@@ -329,13 +364,12 @@ void Renderer::Render(ID3D11Device* /*device*/, ID3D11DeviceContext* ctx, ID3D11
m_context = ctx;
- ctx->ClearRenderTargetView(pRTV, CLEAR_SCENE_COLOR);
ctx->ClearDepthStencilView(m_DSView, D3D11_CLEAR_DEPTH, 1.0, 0);
ctx->RSSetViewports(1, &m_viewport);
// needed matrices
- DirectX::XMMATRIX viewMatrix = m_camera.GetViewMatrix();
- DirectX::XMMATRIX projMatrix = m_camera.GetProjMatrix();
+ DirectX::XMMATRIX viewMatrix = SimpleScene::Inst()->GetViewMatrix();
+ DirectX::XMMATRIX projMatrix = SimpleScene::Inst()->GetProjMatrix();
DirectX::XMMATRIX projMatrixInv = DirectX::XMMatrixInverse(NULL, projMatrix);
DirectX::XMMATRIX viewProjMatrix = viewMatrix * projMatrix;
@@ -346,7 +380,7 @@ void Renderer::Render(ID3D11Device* /*device*/, ID3D11DeviceContext* ctx, ID3D11
CBCamera* cameraBuffer = (CBCamera*)mappedResource.pData;
cameraBuffer->viewProjection = viewProjMatrix;
cameraBuffer->projectionInv = projMatrixInv;
- DirectX::XMStoreFloat3(&(cameraBuffer->viewPos), m_camera.GetEyePt());
+ DirectX::XMStoreFloat3(&(cameraBuffer->viewPos), SimpleScene::Inst()->GetEyePt());
ctx->Unmap(m_cameraCB, 0);
}
@@ -355,6 +389,7 @@ void Renderer::Render(ID3D11Device* /*device*/, ID3D11DeviceContext* ctx, ID3D11
D3D11_MAPPED_SUBRESOURCE mappedResource;
ctx->Map(m_worldCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
CBWorld* worldBuffer = (CBWorld*)mappedResource.pData;
+ Light::FillLightShaderParam(m_worldCBData.lightParam);
memcpy(worldBuffer, &m_worldCBData, sizeof(m_worldCBData));
//worldBuffer->ambientColor = m_CBWorldData.ambientColor;
//worldBuffer->pointLightPos = m_CBWorldData.pointLightPos;
@@ -388,12 +423,28 @@ void Renderer::Render(ID3D11Device* /*device*/, ID3D11DeviceContext* ctx, ID3D11
}
}
- // render shadow map
- m_shadow.renderShadowMaps(this);
+ m_shadow.clearBuffer();
+
+ std::vector<Light>& lights = Light::GetDefaultLights();
+ for (int l = 0; l < 3; l++)
+ {
+ if (!lights[l].m_useShadows)
+ {
+ continue;
+ }
+
+ atcore_float3 eye = lights[l].m_lightCamera._eye;
+ eye.x = -eye.x;
+ atcore_float3 at = lights[l].m_lightCamera._at;
+ at.x = -at.x;
- // render shadow buffer
- ctx->OMSetRenderTargets(0, nullptr, nullptr);
- m_shadow.renderShadowBuffer(m_DSTextureSRV, nullptr);
+ ctx->OMSetRenderTargets(0, nullptr, m_DSView);
+ m_shadow.renderShadowMaps(this, eye, at);
+ ctx->OMSetRenderTargets(0, nullptr, nullptr);
+ m_shadow.renderShadowBuffer(m_DSTextureSRV, nullptr);
+ }
+
+ m_shadow.finalizeBuffer();
}
// Opaque render
@@ -413,20 +464,38 @@ void Renderer::Render(ID3D11Device* /*device*/, ID3D11DeviceContext* ctx, ID3D11
CBCamera* cameraBuffer = (CBCamera*)mappedResource.pData;
cameraBuffer->viewProjection = viewProjMatrix;
cameraBuffer->projectionInv = projMatrixInv;
- DirectX::XMStoreFloat3(&(cameraBuffer->viewPos), m_camera.GetEyePt());
+ DirectX::XMStoreFloat3(&(cameraBuffer->viewPos), SimpleScene::Inst()->GetEyePt());
ctx->Unmap(m_cameraCB, 0);
}
+ std::vector<Renderable*> renderablesWithoutDepthTest;
+
// Render opaque renderables
m_visibleOpaqueRenderablesCount = 0;
for (auto it = m_renderables.begin(); it != m_renderables.end(); it++)
{
if (!(*it)->isTransparent() && !(*it)->isHidden())
{
+ if (!(*it)->isDepthTest())
+ {
+ renderablesWithoutDepthTest.push_back(*it);
+ continue;
+ }
(*it)->render(*this);
m_visibleOpaqueRenderablesCount++;
}
}
+
+ if (renderablesWithoutDepthTest.size() > 0)
+ {
+ ctx->OMSetDepthStencilState(m_opaqueRenderNoDepthDSState, 0xFF);
+ std::vector<Renderable*>::iterator itR;
+ for (itR = renderablesWithoutDepthTest.begin(); itR != renderablesWithoutDepthTest.end(); itR++)
+ {
+ (*itR)->render(*this);
+ }
+ ctx->OMSetDepthStencilState(m_opaqueRenderDSState, 0xFF);
+ }
}
// modulate shadows
@@ -444,6 +513,10 @@ void Renderer::Render(ID3D11Device* /*device*/, ID3D11DeviceContext* ctx, ID3D11
ctx->RSSetViewports(1, &m_viewport);
// render debug render buffers
+ if (!AppMainWindow::Inst().m_bGizmoWithDepthTest)
+ {
+ ctx->OMSetDepthStencilState(m_opaqueRenderNoDepthDSState, 0xFF);
+ }
while (m_queuedRenderBuffers.size() > 0)
{
render(m_queuedRenderBuffers.back());
@@ -496,6 +569,10 @@ LRESULT Renderer::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
}
}
+ UpdateCamera();
+
+ return 0;
+
// Camera events
return m_camera.HandleMessages(hWnd, uMsg, wParam, lParam);
}
@@ -600,7 +677,7 @@ void Renderer::renderDebugPrimitive(const Renderer::RenderDebugVertex *vertices,
m_context->Map(m_objectCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
CBObject* objectBuffer = (CBObject*)mappedResource.pData;
- objectBuffer->world = PxMat44ToXMMATRIX(PxMat44(PxIdentity));
+ objectBuffer->worldMatrix = PxMat44ToXMMATRIX(PxMat44(PxIdentity));
m_context->Unmap(m_objectCB, 0);
@@ -733,4 +810,13 @@ void Renderer::drawUI()
ImGui::TreePop();
}
+}
+
+void Renderer::UpdateCamera()
+{
+ Camera* pCamera = SimpleScene::Inst()->m_pCamera;
+ DirectX::XMVECTORF32 eyePt = { pCamera->_eye.x, pCamera->_eye.y, pCamera->_eye.z, 0 };
+ DirectX::XMVECTORF32 lookAtPt = { pCamera->_at.x, pCamera->_at.y, pCamera->_at.z, 0 };
+ m_camera.SetViewParams(eyePt, lookAtPt);
+ m_camera.SetProjParams(pCamera->_fov, pCamera->_aspectRatio, pCamera->_znear, pCamera->_zfar);
} \ No newline at end of file
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderer.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderer.h
index 58662a6..6981e15 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderer.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderer.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef RENDERER_H
#define RENDERER_H
@@ -23,6 +41,7 @@
#include "RendererShadow.h"
#include "RendererHBAO.h"
#include <unordered_set>
+#include "LightShaderParam.h"
class CFirstPersonCamera;
class PhysXPrimitive;
@@ -95,7 +114,12 @@ class Renderer : public ISampleController
m_queuedRenderBuffers.push_back(buffer);
}
- ResourceManager& getResourceManager()
+ void clearQueue()
+ {
+ m_queuedRenderBuffers.clear();
+ }
+
+ ResourceManager& getResourceManager()
{
return m_resourceManager;
}
@@ -120,7 +144,7 @@ class Renderer : public ISampleController
// for internal usage (used by RenderShadows)
void renderDepthOnly(DirectX::XMMATRIX* viewProjectionSubstitute);
-
+ void UpdateCamera();
protected:
//////// controller callbacks ////////
@@ -174,14 +198,18 @@ class Renderer : public ISampleController
float specularPower;
DirectX::XMFLOAT3 dirLightColor;
float specularIntensity; // TODO: actually it's per object property
+ LightShaderParam lightParam;
};
struct CBObject
{
- DirectX::XMMATRIX world;
- DirectX::XMFLOAT4 color;
-// Add By Lixu Begin
+ DirectX::XMMATRIX worldMatrix;
+ DirectX::XMFLOAT4 diffuseColor;
+ DirectX::XMFLOAT4 specularColor;
+ float useDiffuseTexture;
+ float useSpecularTexture;
+ float useNormalTexture;
+ float specularShininess;
float selected;
-// Add By Lixu End
};
@@ -210,6 +238,7 @@ class Renderer : public ISampleController
ID3D11RasterizerState* m_RSState;
ID3D11DepthStencilState* m_opaqueRenderDSState;
ID3D11DepthStencilState* m_transparencyRenderDSState;
+ ID3D11DepthStencilState* m_opaqueRenderNoDepthDSState;
// DX11 samplers
ID3D11SamplerState* m_pointSampler;
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererHBAO.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererHBAO.cpp
index 5e20a49..c674b2b 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererHBAO.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererHBAO.cpp
@@ -1,12 +1,29 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
#include "RendererHBAO.h"
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererHBAO.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererHBAO.h
index 2478628..3237ddf 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererHBAO.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererHBAO.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef RENDERER_HBAO_H
#define RENDERER_HBAO_H
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererShadow.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererShadow.cpp
index 28a79e5..c26358b 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererShadow.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererShadow.cpp
@@ -1,12 +1,29 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
#include "RendererShadow.h"
@@ -16,7 +33,7 @@
#include "DXUTCamera.h"
#include "Renderer.h"
#include "UIHelpers.h"
-
+#include "SimpleScene.h"
#define CASCADES 1
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -168,7 +185,10 @@ void RendererShadow::changeShadowSettings(UINT Width, UINT Height, UINT uSampleC
void RendererShadow::reloadBuffers()
{
{
- m_shadowLibContext->RemoveMap(&m_shadowMapHandle);
+ if(m_shadowMapHandle != nullptr)
+ {
+ m_shadowLibContext->RemoveMap(&m_shadowMapHandle);
+ }
if (m_SMDesc.eMapType == GFSDK_ShadowLib_MapType_Texture &&
m_SMDesc.eViewType == GFSDK_ShadowLib_ViewType_Single &&
@@ -192,7 +212,10 @@ void RendererShadow::reloadBuffers()
m_shadowLibContext->DevModeCreateTexture2D(&m_downsampledShadowMap);
}
- m_shadowLibContext->RemoveBuffer(&m_shadowBufferHandle);
+ if (m_shadowBufferHandle != nullptr)
+ {
+ m_shadowLibContext->RemoveBuffer(&m_shadowBufferHandle);
+ }
m_shadowLibContext->AddBuffer(&m_SBDesc, &m_shadowBufferHandle);
}
@@ -220,7 +243,7 @@ static void ShadowMapRenderFunction(void* pParams, gfsdk_float4x4* pViewProj)
pRP->renderer->renderDepthOnly(&viewProjection);
}
-void RendererShadow::renderShadowMaps(Renderer* renderer)
+void RendererShadow::renderShadowMaps(Renderer* renderer, atcore_float3& lightPos, atcore_float3& lightLookAt)
{
// select technique
GFSDK_ShadowLib_TechniqueType technique = m_SBRenderParams.eTechniqueType;
@@ -240,8 +263,8 @@ void RendererShadow::renderShadowMaps(Renderer* renderer)
m_SMRenderParams.v3WorldSpaceBBox[1] = m_worldSpaceBBox1;
m_SMRenderParams.LightDesc.eLightType = GFSDK_ShadowLib_LightType_Directional;
- memcpy(&m_SMRenderParams.LightDesc.v3LightPos, &m_lightPos.x, sizeof(gfsdk_float3));
- memcpy(&m_SMRenderParams.LightDesc.v3LightLookAt, &m_lightLookAt.x, sizeof(gfsdk_float3));
+ memcpy(&m_SMRenderParams.LightDesc.v3LightPos, &lightPos, sizeof(gfsdk_float3));
+ memcpy(&m_SMRenderParams.LightDesc.v3LightLookAt, &lightLookAt, sizeof(gfsdk_float3));
m_SMRenderParams.LightDesc.fLightSize = m_lightSize;
m_SMRenderParams.LightDesc.bLightFalloff = false;
@@ -268,13 +291,9 @@ void RendererShadow::renderShadowBuffer(ID3D11ShaderResourceView* pDepthStencilS
m_SBRenderParams.PCSSPenumbraParams = m_PCSSParams;
m_SBRenderParams.fSoftShadowTestScale = m_softShadowTestScale;
- m_shadowLibContext->ClearBuffer(m_shadowBufferHandle);
-
m_SBRenderParams.DepthBufferDesc.DepthStencilSRV.pSRV = pDepthStencilSRV;
m_shadowLibContext->RenderBuffer(m_shadowMapHandle, m_shadowBufferHandle, &m_SBRenderParams);
-
- m_shadowLibContext->FinalizeBuffer(m_shadowBufferHandle, &m_shadowBufferSRV);
}
@@ -414,4 +433,14 @@ void RendererShadow::drawUI()
ImGui::DragFloat("PCSS: fBlockerSearchDitherPercent", &(m_PCSSParams.fBlockerSearchDitherPercent), 0.001f, 0.0f, 100.0f);
ImGui::DragFloat("PCSS: fFilterDitherPercent", &(m_PCSSParams.fFilterDitherPercent), 0.001f, 0.0f, 100.0f);
}
+}
+
+void RendererShadow::clearBuffer()
+{
+ m_shadowLibContext->ClearBuffer(m_shadowBufferHandle);
+}
+
+void RendererShadow::finalizeBuffer()
+{
+ m_shadowLibContext->FinalizeBuffer(m_shadowBufferHandle, &m_shadowBufferSRV);
} \ No newline at end of file
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererShadow.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererShadow.h
index cc81c67..e16af1f 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererShadow.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererShadow.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef RENDERER_SHADOW_H
#define RENDERER_SHADOW_H
@@ -31,7 +49,7 @@ public:
void setScreenResolution(float FovyRad, UINT Width, UINT Height, UINT uSampleCount, ID3D11DepthStencilView* pReadOnlyDSV);
void changeShadowSettings(UINT Width, UINT Height, UINT uSampleCount, ID3D11DepthStencilView* pReadOnlyDSV);
- void renderShadowMaps(Renderer* renderer);
+ void renderShadowMaps(Renderer* renderer, atcore_float3& lightPos, atcore_float3& lightLookAt);
void renderShadowBuffer(ID3D11ShaderResourceView* pDepthStencilSRV, ID3D11ShaderResourceView* pResolvedDepthStencilSRV);
void modulateShadowBuffer(ID3D11RenderTargetView* pOutputRTV);
void displayShadowMaps(ID3D11RenderTargetView* pOutputRTV, UINT Width, UINT Height);
@@ -42,6 +60,9 @@ public:
void drawUI();
+ void clearBuffer();
+ void finalizeBuffer();
+
private:
void reloadBuffers();
void ReleaseResources();
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ResourceManager.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ResourceManager.cpp
index a051f96..6e4cc50 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ResourceManager.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ResourceManager.cpp
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "ResourceManager.h"
#include "PxAssert.h"
@@ -50,6 +68,19 @@ const TextureResource* ResourceManager::requestTexture(const char* name)
return resource != nullptr ? static_cast<const TextureResource*>(resource) : nullptr;
}
+void ResourceManager::releaseTexture(const char* name)
+{
+ std::pair<ResourceType, std::string> key(eTEXTURE, name);
+ auto val = m_loadedResources.find(key);
+ if (val != m_loadedResources.end())
+ {
+ Resource* pResource = val->second;
+ delete pResource;
+ pResource = nullptr;
+ m_loadedResources.erase(key);
+ }
+}
+
const Resource* ResourceManager::requestResource(ResourceType type, const char* name)
{
// search in loaded
@@ -57,17 +88,17 @@ const Resource* ResourceManager::requestResource(ResourceType type, const char*
auto val = m_loadedResources.find(key);
if (val != m_loadedResources.end())
{
- return val->second.get();
+ return val->second;
}
- std::shared_ptr<Resource> resource;
+ Resource* resource = nullptr;
if (type == eSHADER_FILE)
{
char path[PATH_MAX_LEN];
const char* exts[] = { "hlsl" };
if (findFile(name, std::vector<const char*>(exts, exts + sizeof(exts) / sizeof(exts[0])), path))
{
- resource = std::shared_ptr<Resource>(new ShaderFileResource(path));
+ resource = new ShaderFileResource(path);
}
else
{
@@ -78,33 +109,38 @@ const Resource* ResourceManager::requestResource(ResourceType type, const char*
{
char path[PATH_MAX_LEN];
// Add By Lixu Begin
- const char* exts[] = { "dds", "tga", "jpg", "png" };
+ const char* exts[] = { "dds", "tga", "jpg", "png", "bmp" };
// Add By Lixu End
if (findFile(name, std::vector<const char*>(exts, exts + sizeof(exts) / sizeof(exts[0])), path))
{
- std::shared_ptr<TextureResource> textureResource(new TextureResource());
+ TextureResource* textureResource(new TextureResource());
WCHAR wPath[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, path, -1, wPath, MAX_PATH);
wPath[MAX_PATH - 1] = 0;
const char* ext = strext(path);
- if (::strcmp(ext, "dds") == 0)
+ if (::stricmp(ext, "dds") == 0)
{
V(DirectX::LoadFromDDSFile(wPath, DirectX::DDS_FLAGS_NONE, &textureResource->metaData,
textureResource->image));
}
- else if (::strcmp(ext, "tga") == 0)
+ else if (::stricmp(ext, "tga") == 0)
{
V(DirectX::LoadFromTGAFile(wPath, &textureResource->metaData,
textureResource->image));
}
// Add By Lixu Begin
- else if (::strcmp(ext, "jpg") == 0)
+ else if (::stricmp(ext, "jpg") == 0)
{
V(DirectX::LoadFromWICFile(wPath, DirectX::TEX_FILTER_DEFAULT | DirectX::WIC_FLAGS_ALL_FRAMES, &textureResource->metaData,
textureResource->image));
}
- else if (::strcmp(ext, "png") == 0)
+ else if (::stricmp(ext, "png") == 0)
+ {
+ V(DirectX::LoadFromWICFile(wPath, DirectX::TEX_FILTER_DEFAULT | DirectX::WIC_FLAGS_ALL_FRAMES, &textureResource->metaData,
+ textureResource->image));
+ }
+ else if (::stricmp(ext, "bmp") == 0)
{
V(DirectX::LoadFromWICFile(wPath, DirectX::TEX_FILTER_DEFAULT | DirectX::WIC_FLAGS_ALL_FRAMES, &textureResource->metaData,
textureResource->image));
@@ -118,10 +154,10 @@ const Resource* ResourceManager::requestResource(ResourceType type, const char*
}
}
- if (resource.get())
+ if (resource)
{
m_loadedResources.emplace(key, resource);
- return resource.get();
+ return resource;
}
else
{
@@ -195,6 +231,15 @@ bool ResourceManager::findFileInDir(std::string fileNameFull, const char* path,
bool ResourceManager::findFile(std::string fileName, const std::vector<const char*>& exts, char* foundPath)
{
std::string fileNameOnly = fileName;
+
+ std::string::size_type pos = 0;
+ pos = fileNameOnly.find("\\", pos);
+ while ((pos != std::string::npos))
+ {
+ fileNameOnly.replace(pos, 1, "/");
+ pos = fileNameOnly.find("\\", (pos + 1));
+ }
+
size_t ind = fileNameOnly.find_last_of('/');
if (ind > 0)
fileNameOnly = fileNameOnly.substr(ind + 1);
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ResourceManager.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ResourceManager.h
index 0378438..697b16b 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ResourceManager.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ResourceManager.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef RESOURCE_MANAGER_H
#define RESOURCE_MANAGER_H
@@ -62,6 +80,8 @@ public:
const TextureResource* requestTexture(const char* name);
+ void releaseTexture(const char* name);
+
bool findFile(std::string fileName, std::string& foundPath);
bool findFile(std::string fileName, const std::vector<const char*>& exts, char* foundPath);
@@ -92,6 +112,6 @@ private:
//////// internal data ////////
std::vector<SearchDir> m_searchDirs;
- std::map<std::pair<ResourceType, std::string>, std::shared_ptr<Resource>> m_loadedResources;
+ std::map<std::pair<ResourceType, std::string>, Resource*> m_loadedResources;
};
#endif \ No newline at end of file
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ShaderUtils.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ShaderUtils.h
index 778c811..da9caa0 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ShaderUtils.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ShaderUtils.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef SHADER_UTILS_H
#define SHADER_UTILS_H
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/SkinnedRenderMesh.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/SkinnedRenderMesh.cpp
index c575d6c..ff121d6 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/SkinnedRenderMesh.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/SkinnedRenderMesh.cpp
@@ -1,12 +1,29 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
#include "SkinnedRenderMesh.h"
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/SkinnedRenderMesh.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/SkinnedRenderMesh.h
index 2f690d8..f3643d8 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/SkinnedRenderMesh.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/SkinnedRenderMesh.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef SKINNED_RENDER_MESH_H
#define SKINNED_RENDER_MESH_H
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/scene/SampleAssetListParser.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/scene/SampleAssetListParser.cpp
index 00cf4df..b58f9f1 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/scene/SampleAssetListParser.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/scene/SampleAssetListParser.cpp
@@ -1,18 +1,37 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "SampleAssetListParser.h"
#include <PsFastXml.h>
#include "Sample.h"
#include "PxVec4.h"
#include "PxInputDataFromPxFileBuf.h"
+#include <bitset>
using namespace physx;
@@ -104,11 +123,6 @@ protected:
{
m_boxTemp.name = std::string(attr.getValue(i));
}
- else if (::strcmp(attr.getKey(i), "staticHeight") == 0)
- {
- std::string str = attr.getValue(i);
- sscanf(&str[0], "%f", &m_boxTemp.staticHeight);
- }
else if (::strcmp(attr.getKey(i), "jointAllBonds") == 0)
{
std::string str = attr.getValue(i);
@@ -122,6 +136,12 @@ protected:
std::string str = attr.getValue(i);
sscanf(&str[0], "%f %f %f", &m_boxTemp.extents.x, &m_boxTemp.extents.y, &m_boxTemp.extents.z);
}
+ else if (::strcmp(attr.getKey(i), "bondFlagsMask") == 0)
+ {
+ std::string str = attr.getValue(i);
+ std::bitset<8> bondFlags(str);
+ m_boxTemp.bondFlags = static_cast<uint32_t>(bondFlags.to_ulong());
+ }
}
if (m_boxTemp.id.empty())
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/scene/SampleAssetListParser.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/scene/SampleAssetListParser.h
index b6303ec..5d22833 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/scene/SampleAssetListParser.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/scene/SampleAssetListParser.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef SAMPLEASSETLISTPARSER_H
#define SAMPLEASSETLISTPARSER_H
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/scene/SceneController.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/scene/SceneController.cpp
index ec000b3..05681d0 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/scene/SceneController.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/scene/SceneController.cpp
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "SceneController.h"
#include "RenderUtils.h"
@@ -35,8 +53,14 @@
#include <imgui.h>
#include <sstream>
#include <tuple>
+#include <map>
-
+#include "BlastSceneTree.h"
+#include "SimpleScene.h"
+#include "SampleManager.h"
+// Add By Lixu Begin
+#include "ProjectParams.h"
+// Add By Lixu End
//////// Simple hash function ////////
static NvBlastID generateIDFromString(const char* str)
@@ -78,7 +102,7 @@ public:
virtual void load() = 0;
virtual void unload() = 0;
virtual bool isLoaded() const = 0;
- virtual void spawn(PxVec3 shift) = 0;
+ virtual void spawn(PxTransform transform) = 0;
virtual ImVec4 getUIColor() const
{
@@ -94,6 +118,8 @@ protected:
class SceneActor
{
public:
+ SceneActor() : removeOnReload(false) {}
+
virtual ~SceneActor() {}
virtual const char* getName() const = 0;
virtual const char* getSubname(int subindex) const { return nullptr; }
@@ -104,6 +130,8 @@ public:
virtual PxVec3 getSpawnShift() const { return PxVec3(PxZero); }
virtual void reload() {}
virtual void removeSubactor(int subindex) {}
+
+ bool removeOnReload;
};
@@ -116,7 +144,7 @@ public:
int subindex;
ActorIndex() { reset(); }
- ActorIndex(int i, int s) : index(i), subindex(s) {}
+ ActorIndex(int i, int s = -1) : index(i), subindex(s) {}
bool operator==(const ActorIndex& other) const
{
@@ -152,10 +180,27 @@ public:
{
m_assets.push_back(asset);
asset->initialize(this);
- m_assetsByID[asset->getID()] = asset;
+ std::string id = asset->getID();
+ m_assetsByID[id] = asset;
}
// Add By Lixu Begin
+ void removeAsset(SceneAsset* asset)
+ {
+ std::string id = asset->getID();
+ m_assetsByID.erase(m_assetsByID.find(id));
+
+ std::vector<SceneAsset*>::iterator it;
+ for (it = m_assets.begin(); it != m_assets.end(); it++)
+ {
+ if (*it == asset)
+ {
+ m_assets.erase(it);
+ break;
+ }
+ }
+ }
+
std::vector<SceneAsset*>& getAssets()
{
return m_assets;
@@ -316,7 +361,7 @@ public:
return;
}
- PxVec3 shift(PxZero);
+ PxTransform transform(PxIdentity);
// Add By Lixu Begin
/*
for (SceneActor* a : m_sceneActors)
@@ -327,7 +372,7 @@ public:
// Add By Lixu End
SceneAsset* asset = m_assets[m_lastSpawnedAsset];
- asset->spawn(shift);
+ asset->spawn(transform);
}
void addSceneActor(SceneActor* actor)
@@ -339,6 +384,21 @@ public:
}
}
+// Add By Lixu Begin
+ void removeSceneActor(SceneActor* actor)
+ {
+ std::vector<SceneActor*>::iterator itActors;
+ for (itActors = m_sceneActors.begin(); itActors != m_sceneActors.end(); itActors++)
+ {
+ if (*itActors == actor)
+ {
+ m_sceneActors.erase(itActors);
+ break;
+ }
+ }
+ }
+// Add By Lixu End
+
void removeSceneActor(ActorIndex actorIndex)
{
SceneActor* actor = getActorByIndex(actorIndex.index);
@@ -411,6 +471,7 @@ public:
m_assets[i]->unload();
}
+ m_assets.clear();
const int currentAsset = m_lastSpawnedAsset;
m_lastSpawnedAsset = -1;
return currentAsset;
@@ -418,10 +479,28 @@ public:
void reloadAllActors()
{
- for (SceneActor* a : m_sceneActors)
+ SceneActor* selectedActor = getSelectedActor();
+ ActorIndex selectIndex(0);
+
+ for (uint32_t i = 0; i < m_sceneActors.size(); i++)
{
- a->reload();
+ if (m_sceneActors[i]->removeOnReload)
+ {
+ removeSceneActor(ActorIndex(i));
+ i--;
+ }
}
+
+ for (uint32_t i = 0; i < m_sceneActors.size(); i++)
+ {
+ if (m_sceneActors[i] == selectedActor)
+ {
+ selectIndex.index = i;
+ }
+ m_sceneActors[i]->reload();
+ }
+
+ setSelectedActor(selectIndex.index, selectIndex.subindex);
}
void registerTkAsset(const TkAsset& tkAsset, SingleSceneAsset* asset)
@@ -496,18 +575,19 @@ class SingleSceneActor;
class SingleSceneAsset : public SceneAsset
{
public:
- SingleSceneAsset() : m_asset(nullptr) {}
+ SingleSceneAsset(BlastAsset* pBlastAsset) : m_asset(pBlastAsset) {}
virtual ~SingleSceneAsset() { unload(); }
- virtual void spawn(PxVec3 shift) override;
+ virtual void spawn(PxTransform transform) override;
virtual void load() override
{
if (!m_asset)
{
m_asset = createAsset();
- m_scene->registerTkAsset(m_asset->getPxAsset()->getTkAsset(), this);
}
+
+ m_scene->registerTkAsset(m_asset->getPxAsset()->getTkAsset(), this);
}
virtual void unload() override
@@ -543,7 +623,7 @@ private:
class ModelSceneAsset : public SingleSceneAsset
{
public:
- ModelSceneAsset() {}
+ ModelSceneAsset(BlastAsset* pBlastAsset) : SingleSceneAsset(pBlastAsset) {}
virtual const char* getID() const override{ return desc.id.c_str(); }
virtual const char* getName() const override { return desc.name.c_str(); }
@@ -557,10 +637,12 @@ public:
class SimpleModelSceneAsset : public ModelSceneAsset
{
public:
+ SimpleModelSceneAsset(BlastAsset* pBlastAsset) : ModelSceneAsset(pBlastAsset) {}
+
virtual BlastAsset* createAsset()
{
return new BlastAssetModelSimple(m_scene->getBlastController().getTkFramework(), m_scene->getPhysXController().getPhysics(),
- m_scene->getPhysXController().getCooking(), m_scene->getRenderer(), desc.file.c_str());
+ m_scene->getPhysXController().getCooking(), *m_scene->getBlastController().getExtSerialization(), m_scene->getRenderer(), desc.file.c_str());
}
virtual ImVec4 getUIColor() const override
@@ -573,10 +655,12 @@ public:
class SkinnedModelSceneAsset : public ModelSceneAsset
{
public:
+ SkinnedModelSceneAsset(BlastAsset* pBlastAsset) : ModelSceneAsset(pBlastAsset) {}
+
virtual BlastAsset* createAsset()
{
return new BlastAssetModelSkinned(m_scene->getBlastController().getTkFramework(), m_scene->getPhysXController().getPhysics(),
- m_scene->getPhysXController().getCooking(), m_scene->getRenderer(), desc.file.c_str());
+ m_scene->getPhysXController().getCooking(), *m_scene->getBlastController().getExtSerialization(), m_scene->getRenderer(), desc.file.c_str());
}
virtual ImVec4 getUIColor() const override
@@ -589,8 +673,10 @@ public:
class BoxesSceneAsset : public SingleSceneAsset
{
public:
- BoxesSceneAsset(const AssetList::BoxAsset& d) : desc(d)
+ BoxesSceneAsset(const AssetList::BoxAsset& d) : SingleSceneAsset(nullptr)
{
+ desc = d;
+
for (uint32_t lv = 0; lv < desc.levels.size(); ++lv)
{
const AssetList::BoxAsset::Level& level = desc.levels[lv];
@@ -600,6 +686,7 @@ public:
assetDesc.generatorSettings.extents = GeneratorAsset::Vec3(desc.extents.x, desc.extents.y, desc.extents.z);
assetDesc.staticHeight = desc.staticHeight;
assetDesc.jointAllBonds = desc.jointAllBonds;
+ assetDesc.generatorSettings.bondFlags = (CubeAssetGenerator::BondFlags)desc.bondFlags;
}
virtual ImVec4 getUIColor() const override
@@ -642,7 +729,7 @@ public:
virtual const char* getID() const override { return m_desc.id.c_str(); }
virtual const char* getName() const override { return m_desc.name.c_str(); }
- virtual void spawn(PxVec3 shift) override;
+ virtual void spawn(PxTransform transform) override;
virtual void load() override
{
@@ -726,10 +813,10 @@ private:
class SingleSceneActor : public SceneActor
{
public:
- SingleSceneActor(Scene& scene, SingleSceneAsset* asset, PxVec3 shift)
+ SingleSceneActor(Scene& scene, SingleSceneAsset* asset, PxTransform transform)
: m_scene(scene)
, m_asset(asset)
- , m_shift(shift)
+ , m_transform(transform)
{
m_index = m_asset->spawnCount++;
spawn();
@@ -740,6 +827,13 @@ public:
remove();
}
+// Add By Lixu Begin
+ SingleSceneAsset* getSceneAsset()
+ {
+ return m_asset;
+ }
+// Add By Lixu End
+
virtual const char* getName() const override
{
return m_name.c_str();
@@ -772,12 +866,26 @@ public:
virtual void reload() override
{
+ BlastFamilyPtr oldFamily = m_actor;
auto settings = m_actor->getSettings();
+
+ RenderMaterial* pRenderMaterial[2];
+ m_actor->getMaterial(&pRenderMaterial[0], true);
+ m_actor->getMaterial(&pRenderMaterial[1], false);
+
+ m_transform = settings.transform;
remove();
spawn();
+
+ m_actor->setMaterial(pRenderMaterial[0], true);
+ m_actor->setMaterial(pRenderMaterial[1], false);
+
m_actor->setSettings(settings);
+ SampleManager::ins()->updateFamily(oldFamily, m_actor);
}
+ BlastFamily* getFamily() { return m_actor; }
+
private:
void remove()
{
@@ -793,8 +901,7 @@ private:
str << " (" << m_index << ")";
m_name = str.str();
- PxTransform pose = m_asset->getInitialTransform();
- pose.p += m_shift;
+ PxTransform pose = m_transform;
BlastAsset::ActorDesc actorDesc = {
actorDesc.id = generateIDFromString(m_name.c_str()),
@@ -803,12 +910,29 @@ private:
};
m_actor = m_scene.getBlastController().spawnFamily(m_asset->getAsset(), actorDesc);
+ // Add By Lixu Begin
+ BlastFamily::Settings settings = m_actor->getSettings();
+ std::map<BlastAsset*, AssetList::ModelAsset>& assetDescMap = SampleManager::ins()->getAssetDescMap();
+ AssetList::ModelAsset& assetDesc = assetDescMap[m_asset->getAsset()];
+ BPPAsset* bppAsset = BlastProject::ins().getAsset(assetDesc.name.c_str());
+ if (nullptr != bppAsset)
+ {
+ BPPStressSolver& stressSolver = bppAsset->stressSolver;
+ ExtStressSolverSettings & stressSolverSettings = settings.stressSolverSettings;
+ stressSolverSettings.hardness = stressSolver.hardness;
+ stressSolverSettings.stressLinearFactor = stressSolver.linearFactor;
+ stressSolverSettings.stressAngularFactor = stressSolver.angularFactor;
+ stressSolverSettings.bondIterationsPerFrame = stressSolver.bondIterationsPerFrame;
+ stressSolverSettings.graphReductionLevel = stressSolver.graphReductionLevel;
+ m_actor->setSettings(settings);
+ }
+ // Add By Lixu End
}
Scene& m_scene;
BlastFamilyPtr m_actor;
SingleSceneAsset* m_asset;
- PxVec3 m_shift;
+ PxTransform m_transform;
uint32_t m_index;
std::string m_name;
};
@@ -816,10 +940,10 @@ private:
class CompositeSceneActor : public SceneActor
{
public:
- CompositeSceneActor(Scene& scene, CompositeSceneAsset* asset, PxVec3 shift)
+ CompositeSceneActor(Scene& scene, CompositeSceneAsset* asset, PxTransform transform)
: m_scene(scene)
, m_asset(asset)
- , m_shift(shift)
+ , m_transform(transform)
{
m_index = m_asset->spawnCount++;
spawn();
@@ -937,8 +1061,7 @@ private:
ExtPxManager& pxManager = m_scene.getBlastController().getExtPxManager();
for (uint32_t i = 0; i < actorCount; ++i)
{
- PxTransform pose = m_asset->getInitialTransform();
- pose.p += m_shift;
+ PxTransform pose = m_transform;
pose = assetDesc.assetRefs[i].transform.transform(pose);
BlastAsset::ActorDesc actorDesc = {
@@ -981,7 +1104,7 @@ private:
Scene& m_scene;
std::vector<Subactor> m_actors;
CompositeSceneAsset* m_asset;
- PxVec3 m_shift;
+ PxTransform m_transform;
uint32_t m_index;
std::string m_name;
};
@@ -1003,7 +1126,9 @@ public:
virtual const char* getName() const override
{
- return m_name;
+ // Add By Lixu Begin
+ return m_name.c_str();
+ // Add By Lixu End
}
virtual ImVec4 getUIColor() const override
@@ -1011,11 +1136,16 @@ public:
return ImColor(255, 100, 100, 255);
}
+ // Add By Lixu Begin
+ PhysXController::Actor* getActor() { return m_actor; }
+ // Add By Lixu End
private:
PhysXController& m_physXController;
PhysXController::Actor* m_actor;
- const char* m_name;
+ // Add By Lixu Begin
+ std::string m_name;
+ // Add By Lixu End
};
@@ -1024,19 +1154,19 @@ private:
// Assets Implementation
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-void SingleSceneAsset::spawn(PxVec3 shift)
+void SingleSceneAsset::spawn(PxTransform transform)
{
load();
- SingleSceneActor* actor = new SingleSceneActor(*m_scene, this, shift);
+ SingleSceneActor* actor = new SingleSceneActor(*m_scene, this, transform);
m_scene->addSceneActor(actor);
}
-void CompositeSceneAsset::spawn(PxVec3 shift)
+void CompositeSceneAsset::spawn(PxTransform transform)
{
load();
if (isLoaded())
{
- CompositeSceneActor* actor = new CompositeSceneActor(*m_scene, this, shift);
+ CompositeSceneActor* actor = new CompositeSceneActor(*m_scene, this, transform);
m_scene->addSceneActor(actor);
}
}
@@ -1094,9 +1224,10 @@ protected:
// Controller
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-SceneController::SceneController() : m_cubeScale(1.0f)
+SceneController::SceneController() : m_cubeScale(1.0f), m_cubeThrowDownTime(-1.f)
{
m_scene = NULL;
+ BlastToSceneMap.clear();
}
SceneController::~SceneController()
@@ -1107,73 +1238,50 @@ void SceneController::onSampleStart()
{
// setup camera
CFirstPersonCamera* camera = &getRenderer().getCamera();
- DirectX::XMVECTORF32 lookAtPt = { 0, 10, 0, 0 };
- DirectX::XMVECTORF32 eyePt = { 0, 20, 60, 0 };
+ Camera* pCamera = SimpleScene::Inst()->m_pCamera;
+ DirectX::XMVECTORF32 eyePt = { pCamera->_eye.x, pCamera->_eye.y, pCamera->_eye.z, 0 };
+ DirectX::XMVECTORF32 lookAtPt = { pCamera->_at.x, pCamera->_at.y, pCamera->_at.z, 0 };
camera->SetViewParams(eyePt, lookAtPt);
- camera->SetRotateButtons(false, false, true, false);
+ camera->SetRotateButtons(false, false, false, false);
camera->SetEnablePositionMovement(true);
// setup scene
m_scene = new Scene(getRenderer(), getPhysXController(), getBlastController(), getCommonUIController());
- const SampleConfig& config = getManager()->getConfig();
-
- // add packman repo to search dirs
- bool packmanResourcesAdded = false;
- if (const char* packmanPath = std::getenv("PM_PACKAGES_ROOT"))
- {
- const char* RESOURCES_CONFIG_FILE = "resources.xml";
-
- std::string path;
- if (getRenderer().getResourceManager().findFile(RESOURCES_CONFIG_FILE, path))
- {
- physx::PsFileBuffer fileBuffer(path.c_str(), physx::general_PxIOStream2::PxFileBuf::OPEN_READ_ONLY);
- if (fileBuffer.isOpen())
- {
- PxInputDataFromPxFileBuf inputData(fileBuffer);
- PackmanConfigParser parser;
- physx::shdfnd::FastXml* xml = physx::shdfnd::createFastXml(&parser);
- xml->processXml(inputData, false);
- xml->release();
- for (auto& dep : parser.dependencies)
- {
- std::stringstream ss;
- ss << packmanPath << "\\" << dep.first << "\\" << dep.second;
- if (getRenderer().getResourceManager().addSearchDir(ss.str().c_str()))
- {
- packmanResourcesAdded = true;
- }
- }
- }
- }
- }
- if (!packmanResourcesAdded)
- {
- getManager()->getCommonUIController().addPopupMessage("Error", "BlastSampleResources package wasn't found. Consider running download_sample_resources.bat in root folder.", 5.0f);
- }
-
- // parse asset file
- AssetList assetList;
- if (!config.assetsFile.empty())
- {
- std::string path;
- if (getRenderer().getResourceManager().findFile(config.assetsFile, path))
- {
- parseAssetList(assetList, path);
- }
- }
-
- // add both asset file and asset list from config
- addAssets(config.additionalAssetList, packmanResourcesAdded);
- addAssets(assetList, packmanResourcesAdded);
-
-// Add By Lixu Begin
- int size = m_scene->getAssets().size();
- for (int i = 0; i < size; i++)
- {
- spawnAsset(i);
- }
-// Add By Lixu End
+ // commented by Jun Ma to prevent a crash. We do not need those demo resources. We only need shaders.
+ //// add packman repo to search dirs
+ //bool packmanResourcesAdded = false;
+ //if (const char* packmanPath = std::getenv("PM_PACKAGES_ROOT"))
+ //{
+ // const char* RESOURCES_CONFIG_FILE = "resources.xml";
+
+ // std::string path;
+ // if (getRenderer().getResourceManager().findFile(RESOURCES_CONFIG_FILE, path))
+ // {
+ // physx::PsFileBuffer fileBuffer(path.c_str(), physx::general_PxIOStream2::PxFileBuf::OPEN_READ_ONLY);
+ // if (fileBuffer.isOpen())
+ // {
+ // PxInputDataFromPxFileBuf inputData(fileBuffer);
+ // PackmanConfigParser parser;
+ // physx::shdfnd::FastXml* xml = physx::shdfnd::createFastXml(&parser);
+ // xml->processXml(inputData, false);
+ // xml->release();
+ // for (auto& dep : parser.dependencies)
+ // {
+ // std::stringstream ss;
+ // ss << packmanPath << "\\" << dep.first << "\\" << dep.second;
+ // if (getRenderer().getResourceManager().addSearchDir(ss.str().c_str()))
+ // {
+ // packmanResourcesAdded = true;
+ // }
+ // }
+ // }
+ // }
+ //}
+ //if (!packmanResourcesAdded)
+ //{
+ // getManager()->getCommonUIController().addPopupMessage("Error", "BlastSampleResources package wasn't found. Consider running download_sample_resources.bat in root folder.", 5.0f);
+ //}
}
void SceneController::addAssets(const AssetList& assetList, bool loadModels)
@@ -1185,11 +1293,11 @@ void SceneController::addAssets(const AssetList& assetList, bool loadModels)
ModelSceneAsset* asset;
if (!model.isSkinned)
{
- asset = new SimpleModelSceneAsset();
+ asset = new SimpleModelSceneAsset(nullptr);
}
else
{
- asset = new SkinnedModelSceneAsset();
+ asset = new SkinnedModelSceneAsset(nullptr);
}
asset->desc = model;
m_scene->addAsset(asset);
@@ -1208,6 +1316,141 @@ void SceneController::addAssets(const AssetList& assetList, bool loadModels)
}
}
+void SceneController::addBlastAsset(BlastAssetModelSimple* pBlastAsset, AssetList::ModelAsset modelAsset)
+{
+ // 1
+ ModelSceneAsset* asset = new SimpleModelSceneAsset(pBlastAsset);
+ asset->desc = modelAsset;
+ BlastToSceneMap[pBlastAsset] = asset;
+
+ // 2
+ m_scene->addAsset(asset);
+
+ // 3
+ asset->load();
+}
+
+void deleteSceneActors(Scene* scene, SceneAsset* asset)
+{
+ std::vector<SceneActor*> deleteActors;
+
+ std::vector<SceneActor*>& Actors = scene->getActors();
+ std::vector<SceneActor*>::iterator itActors;
+ for (itActors = Actors.begin(); itActors != Actors.end(); )
+ {
+ SingleSceneActor* pSceneActor = (SingleSceneActor*)*itActors;
+ SingleSceneAsset* pSingleSceneAsset = pSceneActor->getSceneAsset();
+ if (pSingleSceneAsset == asset)
+ {
+ deleteActors.push_back(pSceneActor);
+ itActors = Actors.erase(itActors);
+ }
+ else
+ {
+ itActors++;
+ }
+ }
+
+ for (itActors = deleteActors.begin(); itActors != deleteActors.end(); itActors++)
+ {
+ delete *itActors;
+ *itActors = nullptr;
+ }
+ deleteActors.clear();
+}
+
+void SceneController::removeBlastAsset(BlastAssetModelSimple* pBlastAsset)
+{
+ std::vector<SceneAsset*>& Assets = m_scene->getAssets();
+ std::vector<SceneAsset*>::iterator itAssets;
+ for (itAssets = Assets.begin(); itAssets != Assets.end(); itAssets++)
+ {
+ ModelSceneAsset* pSceneAsset = (ModelSceneAsset*)*itAssets;
+ BlastAsset* pAsset = pSceneAsset->getAsset();
+ if (pAsset == pBlastAsset)
+ {
+ deleteSceneActors(m_scene, pSceneAsset);
+
+ // 3
+ pSceneAsset->unload();
+
+ // 2
+ m_scene->removeAsset(pSceneAsset);
+
+ // 1
+ delete pSceneAsset;
+ std::map<BlastAsset*, ModelSceneAsset*>::iterator itBSM;
+ itBSM = BlastToSceneMap.find(pBlastAsset);
+ BlastToSceneMap.erase(itBSM);
+ break;
+ }
+ }
+}
+
+BlastFamily* SceneController::addBlastFamily(BlastAsset* pBlastAsset, physx::PxTransform transform)
+{
+ if (pBlastAsset == nullptr)
+ {
+ return nullptr;
+ }
+
+ std::map<BlastAsset*, ModelSceneAsset*>::iterator itBSM;
+ itBSM = BlastToSceneMap.find(pBlastAsset);
+ if (itBSM == BlastToSceneMap.end())
+ {
+ return nullptr;
+ }
+
+ ModelSceneAsset* asset = itBSM->second;
+ if (asset == nullptr)
+ {
+ return nullptr;
+ }
+
+ SingleSceneActor* actor = new SingleSceneActor(*m_scene, asset, transform);
+ m_scene->addSceneActor(actor);
+
+ BlastFamily* pBlastFamily = actor->getFamily();
+ if (pBlastFamily != nullptr)
+ {
+ pBlastFamily->updatePreSplit(0);
+ pBlastFamily->clearVisibleChangedChunks();
+ }
+ return pBlastFamily;
+}
+
+void SceneController::removeBlastFamily(BlastAsset* pBlastAsset, int nFamilyIndex)
+{
+ if (pBlastAsset == nullptr)
+ {
+ return;
+ }
+
+ std::map<BlastAsset*, ModelSceneAsset*>::iterator itBSM;
+ itBSM = BlastToSceneMap.find(pBlastAsset);
+ if (itBSM == BlastToSceneMap.end())
+ {
+ return;
+ }
+
+ ModelSceneAsset* asset = itBSM->second;
+ if (asset == nullptr)
+ {
+ return;
+ }
+
+ SceneActor* pSceneActor = m_scene->getActorByIndex(nFamilyIndex);
+ if (pSceneActor == nullptr)
+ {
+ return;
+ }
+
+ m_scene->removeSceneActor(pSceneActor);
+
+ delete pSceneActor;
+ pSceneActor = nullptr;
+}
+
void SceneController::onInitialize()
{
@@ -1241,12 +1484,28 @@ LRESULT SceneController::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa
m_scene->reloadAllActors();
return 0;
case 'F':
- throwCube();
+ if (m_cubeThrowDownTime == -1.f)
+ {
+ m_cubeThrowDownTime = ImGui::GetTime();
+ }
return 0;
default:
break;
}
}
+ else if (uMsg == WM_KEYUP)
+ {
+ int iKeyPressed = static_cast<int>(wParam);
+ switch (iKeyPressed)
+ {
+ case 'F':
+ throwCube();
+ m_cubeThrowDownTime = -1.f;
+ return 0;
+ default:
+ break;
+ }
+ }
return 1;
}
@@ -1346,6 +1605,7 @@ void SceneController::drawUI()
{
ImGui::Text("Thrown Cube Params (F)");
ImGui::DragFloat("Cube Size", &m_cubeScale, 1.0f, 0.0f, 100.0f);
+ ImGui::Text("Cube Speed (hold F): %1.f", getCubeSpeed());
}
}
@@ -1355,14 +1615,21 @@ void SceneController::drawStatsUI()
m_scene->drawStatsUI();
}
+float SceneController::getCubeSpeed()
+{
+ const float CUBE_VELOCITY_SPEED_MIN = 70;
+ const float CUBE_VELOCITY_CHARGE_PER_SECOND = 300;
+ return m_cubeThrowDownTime > 0 ? CUBE_VELOCITY_SPEED_MIN + (ImGui::GetTime() - m_cubeThrowDownTime) * CUBE_VELOCITY_CHARGE_PER_SECOND : 0.f;
+}
+
void SceneController::throwCube()
{
- const float CUBE_VELOCITY = 100;
+ const float CUBE_VELOCITY = 400;
const float CUBE_DENSITY = 20000.0f;
CFirstPersonCamera* camera = &getRenderer().getCamera();
- PxVec3 eyePos = XMVECTORToPxVec4(camera->GetEyePt()).getXYZ();
- PxVec3 lookAtPos = XMVECTORToPxVec4(camera->GetLookAtPt()).getXYZ();
+ PxVec3 eyePos = XMVECTORToPxVec4(SimpleScene::Inst()->GetEyePt()).getXYZ();
+ PxVec3 lookAtPos = XMVECTORToPxVec4(SimpleScene::Inst()->GetLookAtPt()).getXYZ();
PhysXController::Actor* cube = getPhysXController().spawnPhysXPrimitiveBox(PxTransform(eyePos), PxVec3(m_cubeScale, m_cubeScale, m_cubeScale), CUBE_DENSITY);
PxRigidDynamic* rigidDynamic = cube->getActor()->is<PxRigidDynamic>();
cube->setColor(DirectX::XMFLOAT4(1, 0, 0, 1));
@@ -1390,7 +1657,8 @@ void SceneController::throwCube()
m_Projectiles.push_back(p);
m_scene->addSceneActor(p);
- getManager()->m_bNeedRefreshTree = true;
+// BlastSceneTree::ins()->addProjectile(p);
+ SampleManager::ins()->m_bNeedRefreshTree = true;
// Add By Lixu End
}
@@ -1428,82 +1696,41 @@ void SceneController::clearProjectile()
m_Projectiles.clear();
m_UsedNames.clear();
m_ReusedNames.clear();
+
+// BlastSceneTree::ins()->clearProjectile();
+ SampleManager::ins()->m_bNeedRefreshTree = true;
+}
+
+std::string SceneController::getProjectileName(PhysXSceneActor* projectile)
+{
+ return projectile->getName();
+}
+
+bool SceneController::getProjectileVisible(PhysXSceneActor* projectile)
+{
+ return !(projectile->getActor()->isHidden());
+}
+
+void SceneController::setProjectileVisible(PhysXSceneActor* projectile, bool val)
+{
+ projectile->getActor()->setHidden(!val);
}
void SceneController::ResetScene()
{
clearProjectile();
+// BlastSceneTree::ins()->clearProjectile();
m_scene->reloadAllActors();
+ SampleManager::ins()->m_bNeedRefreshTree = true;
}
void SceneController::ClearScene()
{
clearProjectile();
+// BlastSceneTree::ins()->clearProjectile();
m_scene->releaseAll();
-// Add By Lixu Begin
PhysXController& pc = getPhysXController();
pc.ClearOldCOllisions();
-// Add By Lixu End
-}
-
-bool SceneController::GetAssetDesc(const BlastAsset* asset, AssetList::ModelAsset& desc)
-{
- SampleManager* pSampleManager = getManager();
- SampleConfig* config = (SampleConfig*)&(pSampleManager->getConfig());
- std::vector<AssetList::ModelAsset>& modelAssets = config->additionalAssetList.models;
- std::vector<AssetList::ModelAsset>::iterator itModelAssets;
- std::vector<SceneAsset*>& sceneAssets = m_scene->getAssets();
- std::vector<SceneAsset*>::iterator itSceneAssets;
-
- bool find = false;
- for (itSceneAssets = sceneAssets.begin(); itSceneAssets != sceneAssets.end(); itSceneAssets++)
- {
- SceneAsset* sceneAsset = *itSceneAssets;
- std::string id = sceneAsset->getID();
- for (itModelAssets = modelAssets.begin(); itModelAssets != modelAssets.end(); itModelAssets++)
- {
- AssetList::ModelAsset& modelAsset = *itModelAssets;
- if (modelAsset.id == id)
- {
- if (!modelAsset.isSkinned)
- {
- SimpleModelSceneAsset* pSimpleModelSceneAsset = (SimpleModelSceneAsset*)sceneAsset;
- if (pSimpleModelSceneAsset->getAsset() == asset)
- {
- desc = modelAsset;
- find = true;
- break;
- }
- }
- else
- {
- SkinnedModelSceneAsset* pSkinnedModelSceneAsset = (SkinnedModelSceneAsset*)sceneAsset;
- if (pSkinnedModelSceneAsset->getAsset() == asset)
- {
- desc = modelAsset;
- find = true;
- break;
- }
- }
- }
- }
-
- if (find)
- {
- break;
- }
- }
-
- return find;
-}
-
-void SceneController::GetProjectilesNames(std::vector<std::string>& projectilesNames)
-{
- projectilesNames.clear();
- std::vector<std::string>::iterator it = m_UsedNames.begin();
- for (; it != m_UsedNames.end(); it++)
- {
- projectilesNames.push_back(*it);
- }
+ SampleManager::ins()->m_bNeedRefreshTree = true;
}
// Add By Lixu End \ No newline at end of file
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/scene/SceneController.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/scene/SceneController.h
index 82f08d8..669ca40 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/scene/SceneController.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/scene/SceneController.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef SCENE_CONTROLLER_H
#define SCENE_CONTROLLER_H
@@ -23,6 +41,8 @@ class SingleSceneAsset;
class Scene;
// Add By Lixu Begin
class PhysXSceneActor;
+class BlastAssetModelSimple;
+class ModelSceneAsset;
// Add By Lixu End
class SceneController : public ISampleController
{
@@ -48,15 +68,22 @@ public:
// Add By Lixu Begin
void addProjectile();
void clearProjectile();
+ std::vector<PhysXSceneActor*> getPrejectiles() { return m_Projectiles; }
+ std::string getProjectileName(PhysXSceneActor* projectile);
+ bool getProjectileVisible(PhysXSceneActor* projectile);
+ void setProjectileVisible(PhysXSceneActor* projectile, bool val);
void ResetScene();
void ClearScene();
- bool GetAssetDesc(const BlastAsset* asset, AssetList::ModelAsset& desc);
- void GetProjectilesNames(std::vector<std::string>& projectilesNames);
+ void addBlastAsset(BlastAssetModelSimple* pBlastAsset, AssetList::ModelAsset modelAsset);
+ void removeBlastAsset(BlastAssetModelSimple* pBlastAsset);
+ BlastFamily* addBlastFamily(BlastAsset* pBlastAsset, physx::PxTransform transform);
+ void removeBlastFamily(BlastAsset* pBlastAsset, int nFamilyIndex);
// Add By Lixu End
private:
void addAssets(const AssetList& assetList, bool loadModels = true);
void throwCube();
+ float getCubeSpeed();
SceneController& operator= (SceneController&);
@@ -88,11 +115,14 @@ private:
Scene* m_scene;
float m_cubeScale;
+ float m_cubeThrowDownTime;
// Add By Lixu Begin
std::vector<std::string> m_UsedNames;
std::vector<std::string> m_ReusedNames;
std::vector<PhysXSceneActor*> m_Projectiles;
+
+ std::map<BlastAsset*, ModelSceneAsset*> BlastToSceneMap;
// Add By Lixu End
};
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/CommonUIController.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/CommonUIController.cpp
index e56a124..f9e218b 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/CommonUIController.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/CommonUIController.cpp
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "CommonUIController.h"
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/CommonUIController.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/CommonUIController.h
index da62674..4656203 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/CommonUIController.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/CommonUIController.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef COMMON_UI_CONTROLLER_H
#define COMMON_UI_CONTROLLER_H
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/DamageToolController.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/DamageToolController.cpp
index fba1227..7f426bd 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/DamageToolController.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/DamageToolController.cpp
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "DamageToolController.h"
#include "RenderUtils.h"
@@ -18,11 +36,16 @@
#include <imgui.h>
#include "NvBlastTkActor.h"
+#include "NvBlastTkFamily.h"
#include "NvBlastExtDamageShaders.h"
#include "NvBlastExtPxActor.h"
#include "PxRigidDynamic.h"
#include "PxScene.h"
+#include "SimpleScene.h"
+#include "BlastSceneTree.h"
+#include "DefaultDamagePanel.h"
+#include "ViewerOutput.h"
using namespace Nv::Blast;
@@ -32,44 +55,113 @@ using namespace physx;
// Setup
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
const DirectX::XMFLOAT4 PICK_POINTER_ACTIVE_COLOR(1.0f, 0.f, 0.f, 0.6f);
+static const PxVec3 WEAPON_POSITION_IN_VIEW(0, -7, 23);
+static const float SEGMENT_DAMAGE_MAX_DISTANCE = 100.0f;
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
+DamageToolController* gDamageToolController = nullptr;
+DamageToolController* DamageToolController::ins()
+{
+ return gDamageToolController;
+}
+void DamageToolController::setDamageAmount(float value)
+{
+ m_damage = value;
+}
+void DamageToolController::setExplosiveImpulse(float value)
+{
+ m_explosiveImpulse = value;
+}
+void DamageToolController::setStressForceFactor(float value)
+{
+ m_stressForceFactor = value;
+}
+void DamageToolController::setDamagerIndex(int index)
+{
+ m_damagerIndex = index;
+}
+void DamageToolController::setRadius(float value)
+{
+ m_damagers[m_damagerIndex].radius = value;
+}
+void DamageToolController::setDamageWhilePressed(bool value)
+{
+ m_damagers[m_damagerIndex].damageWhilePressed = value;
+}
DamageToolController::DamageToolController()
- : m_damageRadius(5.0f), m_compressiveDamage(1.0f), m_pickPointerColor(1.0f, 1.0f, 1.0f, 0.4f),
- m_pickPointerRenderMaterial(nullptr), m_pickPointerRenderable(nullptr), m_explosiveImpulse(100), m_damageProfile(0), m_stressForceFactor(1.0f)
+ : m_damage(100.0f), m_toolColor(1.0f, 1.0f, 1.0f, 0.4f),
+ m_toolRenderMaterial(nullptr), m_sphereToolRenderable(nullptr), m_lineToolRenderable(nullptr),
+ m_explosiveImpulse(100), m_damagerIndex(0), m_stressForceFactor(1.0f), m_isMousePressed(false), m_damageCountWhilePressed(0)
{
+ // damage amount calc using NvBlastExtMaterial
+ auto getDamageAmountFn = [](const float damage, ExtPxActor* actor)
+ {
+ const void* material = actor->getTkActor().getFamily().getMaterial();
+ return material ? reinterpret_cast<const NvBlastExtMaterial*>(material)->getNormalizedDamage(damage) : 0.f;
+ };
+
// Damage functions
- auto radialDamageExecute = [&](const Damager* damager, ExtPxActor* actor, PxVec3 position, PxVec3 normal)
+ auto radialDamageExecute = [&](const Damager* damager, ExtPxActor* actor, PxVec3 origin, PxVec3 position, PxVec3 normal)
{
- NvBlastExtRadialDamageDesc desc =
+ const float damage = getDamageAmountFn(m_damage, actor);
+ if (damage > 0.f)
{
- m_compressiveDamage,
- { position.x, position.y, position.z },
- m_damageRadius,
- m_damageRadius + 2.0f
- };
+ NvBlastExtRadialDamageDesc desc =
+ {
+ damage,
+ { position.x, position.y, position.z },
+ damager->radius,
+ damager->radius * 1.6f
+ };
- actor->getTkActor().damage(damager->program, &desc, sizeof(desc));
+ actor->getTkActor().damage(damager->program, &desc, sizeof(desc));
+ }
};
- auto shearDamageExecute = [&](const Damager* damager, ExtPxActor* actor, PxVec3 position, PxVec3 normal)
+ auto lineSegmentDamageExecute = [&](const Damager* damager, ExtPxActor* actor, PxVec3 origin, PxVec3 position, PxVec3 normal)
{
- PxVec3 force = -2 * normal;
+ const float damage = getDamageAmountFn(m_damage, actor);
+ if (damage > 0.f)
+ {
+ PxVec3 dir = (position - origin).getNormalized();
+ PxVec3 farEnd = origin + dir * 10000.0f;
- NvBlastExtShearDamageDesc desc =
+ NvBlastExtSegmentRadialDamageDesc desc =
+ {
+ damage,
+ { origin.x, origin.y, origin.z },
+ { farEnd.x, farEnd.y, farEnd.z },
+ damager->radius,
+ damager->radius * 1.6f
+ };
+
+ actor->getTkActor().damage(damager->program, &desc, sizeof(desc));
+ }
+ };
+ auto shearDamageExecute = [&](const Damager* damager, ExtPxActor* actor, PxVec3 origin, PxVec3 position, PxVec3 normal)
+ {
+ const float damage = getDamageAmountFn(m_damage, actor);
+ if (damage > 0.f)
{
- { force.x, force.y, force.z },
- { position.x, position.y, position.z }
- };
+ PxVec3 impactNormal = -normal;
- actor->getTkActor().damage(damager->program, &desc, sizeof(desc));
+ NvBlastExtShearDamageDesc desc =
+ {
+ damage,
+ { impactNormal.x, impactNormal.y, impactNormal.z },
+ { position.x, position.y, position.z },
+ damager->radius,
+ damager->radius * 1.6f
+ };
+
+ actor->getTkActor().damage(damager->program, &desc, sizeof(desc));
+ }
};
- auto stressDamageExecute = [&](const Damager* damager, ExtPxActor* actor, PxVec3 position, PxVec3 normal)
+ auto stressDamageExecute = [&](const Damager* damager, ExtPxActor* actor, PxVec3 origin, PxVec3 position, PxVec3 normal)
{
PxVec3 force = -m_stressForceFactor * normal * actor->getPhysXActor().getMass();
@@ -81,41 +173,96 @@ DamageToolController::DamageToolController()
Damager dam;
dam.uiName = "Radial Damage (Falloff)";
dam.program = NvBlastDamageProgram { NvBlastExtFalloffGraphShader, NvBlastExtFalloffSubgraphShader };
+ dam.pointerType = Damager::PointerType::Sphere;
dam.pointerColor = DirectX::XMFLOAT4(1.0f, 1.0f, 1.0f, 0.4f);
dam.executeFunction = radialDamageExecute;
- m_armory.push_back(dam);
+ m_damagers.push_back(dam);
}
{
Damager dam;
dam.uiName = "Radial Damage (Cutter)";
dam.program = NvBlastDamageProgram { NvBlastExtCutterGraphShader, NvBlastExtCutterSubgraphShader };
+ dam.pointerType = Damager::PointerType::Sphere;
dam.pointerColor = DirectX::XMFLOAT4(0.5f, 0.5f, 1.0f, 0.4f);
dam.executeFunction = radialDamageExecute;
- m_armory.push_back(dam);
+ m_damagers.push_back(dam);
+ }
+
+ {
+ Damager dam;
+ dam.uiName = "Segment Damage (Falloff)";
+ dam.program = NvBlastDamageProgram{ NvBlastExtSegmentFalloffGraphShader, NvBlastExtSegmentFalloffSubgraphShader };
+ dam.pointerType = Damager::PointerType::Line;
+ dam.pointerColor = DirectX::XMFLOAT4(0.1f, 1.0f, 0.1f, 0.4f);
+ dam.executeFunction = lineSegmentDamageExecute;
+ dam.damageWhilePressed = true;
+ dam.radius = .2f;
+ dam.radiusLimit = 20.0f;
+ m_damagers.push_back(dam);
}
{
Damager dam;
dam.uiName = "Shear Damage";
dam.program = NvBlastDamageProgram { NvBlastExtShearGraphShader, NvBlastExtShearSubgraphShader };
+ dam.pointerType = Damager::PointerType::Sphere;
dam.pointerColor = DirectX::XMFLOAT4(0.5f, 1.0f, 0.5f, 0.4f);
dam.executeFunction = shearDamageExecute;
- m_armory.push_back(dam);
+ m_damagers.push_back(dam);
}
{
Damager dam;
dam.uiName = "Stress Damage";
dam.program = { nullptr, nullptr };
+ dam.pointerType = Damager::PointerType::Sphere;
dam.pointerColor = DirectX::XMFLOAT4(0.5f, 0.5f, 1.0f, 0.4f);
dam.executeFunction = stressDamageExecute;
- m_armory.push_back(dam);
+ m_damagers.push_back(dam);
}
- for (const Damager& d : m_armory)
+ // UI
+ DefaultDamagePanel* pDefaultDamagePanel = DefaultDamagePanel::ins();
+ pDefaultDamagePanel->setUpdateData(false);
+ QComboBox* comboBoxDamageProfile = pDefaultDamagePanel->getDamageProfile();
+ comboBoxDamageProfile->clear();
+
+ // project
+ BPPDefaultDamage& damage = BlastProject::ins().getParams().defaultDamage;
+ damage.damageAmount = m_damage;
+ damage.explosiveImpulse = m_explosiveImpulse;
+ damage.stressDamageForce = m_stressForceFactor;
+ int count = m_damagers.size();
+ if (damage.damageStructs.buf != nullptr && damage.damageStructs.arraySizes[0] != count)
+ {
+ delete[] damage.damageStructs.buf;
+ damage.damageStructs.buf = nullptr;
+ damage.damageStructs.arraySizes[0] = 0;
+ }
+ if (damage.damageStructs.buf == nullptr)
{
- m_armoryNames.push_back(d.uiName);
+ damage.damageStructs.buf = new BPPDamageStruct[count];
+ damage.damageStructs.arraySizes[0] = count;
}
+ damage.damageProfile = 0;
+ int damageIndex = 0;
+
+ for (const Damager& d : m_damagers)
+ {
+ m_damagerNames.push_back(d.uiName);
+
+ // UI
+ comboBoxDamageProfile->addItem(d.uiName);
+
+ // project
+ BPPDamageStruct& damageStruct = damage.damageStructs.buf[damageIndex++];
+ damageStruct.damageRadius = d.radius;
+ damageStruct.continuously = d.damageWhilePressed;
+ }
+
+ pDefaultDamagePanel->updateValues();
+
+ gDamageToolController = this;
}
DamageToolController::~DamageToolController()
@@ -124,19 +271,22 @@ DamageToolController::~DamageToolController()
void DamageToolController::onSampleStart()
{
- // pick pointer
-// Add By Lixu Begin
- m_pickPointerRenderMaterial = new RenderMaterial("", getRenderer().getResourceManager(), "physx_primitive_transparent", "", RenderMaterial::BLEND_ALPHA_BLENDING);
-// Add By Lixu End
- IRenderMesh* mesh = getRenderer().getPrimitiveRenderMesh(PrimitiveRenderMeshType::Sphere);
- m_pickPointerRenderable = getRenderer().createRenderable(*mesh, *m_pickPointerRenderMaterial);
- m_pickPointerRenderable->setScale(PxVec3(m_damageRadius));
+ // damage tool pointer
+ m_toolRenderMaterial = new RenderMaterial("", getRenderer().getResourceManager(), "physx_primitive_transparent", "", RenderMaterial::BLEND_ALPHA_BLENDING);
+ {
+ IRenderMesh* mesh = getRenderer().getPrimitiveRenderMesh(PrimitiveRenderMeshType::Sphere);
+ m_sphereToolRenderable = getRenderer().createRenderable(*mesh, *m_toolRenderMaterial);
+ }
+ {
+ IRenderMesh* mesh = getRenderer().getPrimitiveRenderMesh(PrimitiveRenderMeshType::Box);
+ m_lineToolRenderable = getRenderer().createRenderable(*mesh, *m_toolRenderMaterial);
+ }
// default tool
- setDamageProfile(0);
+ m_damagerIndex = 0;
// start with damage mode by default
- setDamageMode(true);
+ setDamageMode(false);
}
void DamageToolController::onInitialize()
@@ -146,64 +296,139 @@ void DamageToolController::onInitialize()
void DamageToolController::onSampleStop()
{
- getRenderer().removeRenderable(m_pickPointerRenderable);
- SAFE_DELETE(m_pickPointerRenderMaterial);
+ getRenderer().removeRenderable(m_sphereToolRenderable);
+ getRenderer().removeRenderable(m_lineToolRenderable);
+ SAFE_DELETE(m_toolRenderMaterial);
}
+
void DamageToolController::Animate(double dt)
{
PROFILER_SCOPED_FUNCTION();
- m_pickPointerColor = XMFLOAT4Lerp(m_pickPointerColor, m_armory[m_damageProfile].pointerColor, dt * 5.0f);
- m_pickPointerRenderable->setColor(m_pickPointerColor);
-}
+ m_toolColor = XMFLOAT4Lerp(m_toolColor, m_damagers[m_damagerIndex].pointerColor, dt * 5.0f);
+ m_sphereToolRenderable->setHidden(true);
+ m_lineToolRenderable->setHidden(true);
-LRESULT DamageToolController::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- PROFILER_SCOPED_FUNCTION();
-
- if (uMsg == WM_LBUTTONDOWN || uMsg == WM_MOUSEMOVE || uMsg == WM_LBUTTONUP)
+ // damage mode
+ if (m_damageMode)
{
- float mouseX = (short)LOWORD(lParam) / getRenderer().getScreenWidth();
- float mouseY = (short)HIWORD(lParam) / getRenderer().getScreenHeight();
- bool press = uMsg == WM_LBUTTONDOWN;
+ // ray cast according to camera + mouse ray
+ PxVec3 eyePos, pickDir;
+ getPhysXController().getEyePoseAndPickDir(m_lastMousePos.x, m_lastMousePos.y, eyePos, pickDir);
+ pickDir = pickDir.getNormalized();
+
+ PxRaycastHit hit; hit.shape = NULL;
+ PxRaycastBuffer hit1;
+ getPhysXController().getPhysXScene().raycast(eyePos, pickDir, PX_MAX_F32, hit1, PxHitFlag::ePOSITION | PxHitFlag::eNORMAL);
+ hit = hit1.block;
- // damage mode
- if (m_damageMode && m_pickPointerRenderable)
+ if (hit.shape)
{
- PxVec3 eyePos, pickDir;
- getPhysXController().getEyePoseAndPickDir(mouseX, mouseY, eyePos, pickDir);
- pickDir = pickDir.getNormalized();
+ PxMat44 cameraViewInv = XMMATRIXToPxMat44(getRenderer().getCamera().GetViewMatrix()).inverseRT();
+ PxVec3 weaponOrigin = eyePos + cameraViewInv.rotate(WEAPON_POSITION_IN_VIEW);
- PxRaycastHit hit; hit.shape = NULL;
- PxRaycastBuffer hit1;
- getPhysXController().getPhysXScene().raycast(eyePos, pickDir, PX_MAX_F32, hit1, PxHitFlag::ePOSITION | PxHitFlag::eNORMAL);
- hit = hit1.block;
+ // damage function
+ const Damager& damager = m_damagers[m_damagerIndex];
+ auto damageFunction = [&](ExtPxActor* actor)
+ {
+ auto t0 = actor->getPhysXActor().getGlobalPose();
+ PxTransform t(t0.getInverse());
+ PxVec3 localNormal = t.rotate(hit.normal);
+ PxVec3 localPosition = t.transform(hit.position);
+ PxVec3 localOrigin = t.transform(weaponOrigin);
+ damager.executeFunction(&damager, actor, localOrigin, localPosition, localNormal);
+ };
+
+ // should damage?
+ bool shouldDamage = false;
+ if (m_isMousePressed)
+ {
+ shouldDamage = damager.damageWhilePressed || m_damageCountWhilePressed == 0;
+ m_damageCountWhilePressed++;
+ }
+ else
+ {
+ m_damageCountWhilePressed = 0;
+ }
- if (hit.shape)
+ // Update tool pointer and do damage with specific overlap
+ if (damager.pointerType == Damager::Sphere)
{
- PxRigidActor* actor = hit.actor;
- m_pickPointerRenderable->setHidden(false);
- m_pickPointerRenderable->setTransform(PxTransform(hit.position));
+ m_sphereToolRenderable->setHidden(false);
+ m_sphereToolRenderable->setColor(m_toolColor);
+ m_sphereToolRenderable->setScale(PxVec3(damager.radius));
+ m_sphereToolRenderable->setTransform(PxTransform(hit.position));
- if (press)
+ if (shouldDamage)
{
- damage(hit.position, hit.normal);
- m_pickPointerColor = PICK_POINTER_ACTIVE_COLOR;
+ if (getBlastController().overlap(PxSphereGeometry(damager.radius), PxTransform(hit.position), damageFunction))
+ {
+ m_toolColor = PICK_POINTER_ACTIVE_COLOR;
+ }
+ getPhysXController().explodeDelayed(hit.position, damager.radius, m_explosiveImpulse);
+ }
+ }
+ else if (damager.pointerType == Damager::Line)
+ {
+ m_lineToolRenderable->setHidden(false);
+ m_lineToolRenderable->setColor(m_toolColor);
+
+ PxVec3 scale(damager.radius, damager.radius, SEGMENT_DAMAGE_MAX_DISTANCE);
+ PxVec3 direction = (hit.position - weaponOrigin).getNormalized();
+ PxVec3 position = weaponOrigin + direction * SEGMENT_DAMAGE_MAX_DISTANCE;
+
+ m_lineToolRenderable->setScale(scale);
+ PxTransform t(position, quatLookAt(direction));
+ m_lineToolRenderable->setTransform(t);
+
+ if (shouldDamage)
+ {
+ if (this->getBlastController().overlap(PxBoxGeometry(scale), t, damageFunction))
+ {
+ m_toolColor = PICK_POINTER_ACTIVE_COLOR;
+ }
}
}
else
{
- m_pickPointerRenderable->setHidden(true);
+ PX_ASSERT(false);
}
}
}
+}
+
+
+LRESULT DamageToolController::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ PROFILER_SCOPED_FUNCTION();
+
+ if (uMsg == WM_LBUTTONDOWN || uMsg == WM_MOUSEMOVE || uMsg == WM_LBUTTONUP)
+ {
+ m_lastMousePos.x = (short)LOWORD(lParam) / getRenderer().getScreenWidth();
+ if (!SimpleScene::Inst()->m_pCamera->_lhs)
+ {
+ m_lastMousePos.x = 1 - m_lastMousePos.x;
+ }
+ m_lastMousePos.y = (short)HIWORD(lParam) / getRenderer().getScreenHeight();
+ }
+
+ if (uMsg == WM_LBUTTONDOWN || uMsg == WM_LBUTTONUP)
+ {
+ m_isMousePressed = (uMsg == WM_LBUTTONDOWN);
+ if (m_isMousePressed && !m_damageMode)
+ {
+ viewer_warn("damage mode is disable, please enable it first !");
+ }
+ }
if (uMsg == WM_MOUSEWHEEL)
{
+ /*
int delta = int((short)HIWORD(wParam)) / WHEEL_DELTA;
changeDamageRadius(delta * 0.3f);
+ */
}
if (uMsg == WM_KEYDOWN)
@@ -219,14 +444,12 @@ LRESULT DamageToolController::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
}
else if (iKeyPressed >= '1' && iKeyPressed <= '9')
{
- uint32_t num = PxClamp<uint32_t>(iKeyPressed - '1', 0, (uint32_t)m_armory.size() - 1);
- setDamageProfile(num);
+ m_damagerIndex = PxClamp<uint32_t>(iKeyPressed - '1', 0, (uint32_t)m_damagers.size() - 1);
}
else if (iKeyPressed == VK_SPACE)
{
- setDamageMode(!isDamageMode());
+ //setDamageMode(!isDamageMode());
}
-
}
return 1;
@@ -234,61 +457,36 @@ LRESULT DamageToolController::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
void DamageToolController::drawUI()
{
- ImGui::DragFloat("Compressive Damage", &m_compressiveDamage, 0.05f);
+ ImGui::DragFloat("Damage Amount", &m_damage, 1.0f);
ImGui::DragFloat("Explosive Impulse", &m_explosiveImpulse);
- ImGui::DragFloat("Damage Radius (Mouse WH)", &m_damageRadius);
ImGui::DragFloat("Stress Damage Force", &m_stressForceFactor);
// - - - - - - - -
ImGui::Spacing();
// Armory
- if (ImGui::Combo("Damage Profile", (int*)&m_damageProfile, m_armoryNames.data(), (int)m_armoryNames.size(), -1))
- {
- setDamageProfile(m_damageProfile);
- }
+ ImGui::Combo("Damage Profile", (int*)&m_damagerIndex, m_damagerNames.data(), (int)m_damagerNames.size(), -1);
+ Damager& damager = m_damagers[m_damagerIndex];
+ ImGui::DragFloat("Damage Radius (Mouse WH)", &damager.radius);
+ ImGui::Checkbox("Damage Continuously", &damager.damageWhilePressed);
}
-
void DamageToolController::setDamageMode(bool enabled)
{
m_damageMode = enabled;
- getPhysXController().setDraggingEnabled(!m_damageMode);
+ //getPhysXController().setDraggingEnabled(!m_damageMode);
if (!m_damageMode)
{
- m_pickPointerRenderable->setHidden(true);
+ m_sphereToolRenderable->setHidden(true);
+ m_lineToolRenderable->setHidden(true);
}
}
-
-void DamageToolController::setDamageProfile(uint32_t profile)
-{
- m_damageProfile = profile;
-}
-
-
void DamageToolController::changeDamageRadius(float dr)
{
- m_damageRadius += dr;
- m_damageRadius = PxMax(1.0f, m_damageRadius);
- m_pickPointerRenderable->setScale(PxVec3(m_damageRadius));
-}
-
-
-void DamageToolController::damage(physx::PxVec3 position, physx::PxVec3 normal)
-{
- auto damageFunction = [&](ExtPxActor* actor)
- {
- auto t0 = actor->getPhysXActor().getGlobalPose();
- PxTransform t(t0.getInverse());
- PxVec3 localNormal = t.rotate(normal);
- PxVec3 localPosition = t.transform(position);
- Damager& damager = m_armory[m_damageProfile];
- damager.execute(actor, localPosition, localNormal);
- };
-
- this->getBlastController().blast(position, m_damageRadius, m_explosiveImpulse, damageFunction);
-
+ Damager& damager = m_damagers[m_damagerIndex];
+ damager.radius += dr;
+ damager.radius = PxClamp<float>(damager.radius, 0.05f, damager.radiusLimit);
}
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/DamageToolController.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/DamageToolController.h
index b6712f2..0aeb0d7 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/DamageToolController.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/DamageToolController.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef DAMAGE_TOOL_CONTROLLER_H
#define DAMAGE_TOOL_CONTROLLER_H
@@ -15,6 +33,7 @@
#include "NvBlastTypes.h"
#include <DirectXMath.h>
#include <functional>
+#include "PxVec2.h"
#include "PxVec3.h"
@@ -37,6 +56,14 @@ public:
DamageToolController();
virtual ~DamageToolController();
+ static DamageToolController* ins();
+ void setDamageAmount(float value);
+ void setExplosiveImpulse(float value);
+ void setStressForceFactor(float value);
+ void setDamagerIndex(int index);
+ void setRadius(float value);
+ void setDamageWhilePressed(bool value);
+
virtual LRESULT MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
virtual void Animate(double dt);
void drawUI();
@@ -54,8 +81,10 @@ public:
// Add By Lixu Begin
Renderable* getPickPointer()
{
- return m_pickPointerRenderable;
+ return m_sphereToolRenderable;
}
+
+ void setDamageMode(bool enabled);
// Add By Lixu End
private:
@@ -64,17 +93,9 @@ private:
//////// private methods ////////
- void damage(physx::PxVec3 position, physx::PxVec3 normal);
-
- void setDamageProfile(uint32_t profile);
- uint32_t getDamageProfile() const
- {
- return m_damageProfile;
- }
-
void changeDamageRadius(float dr);
- void setDamageMode(bool enabled);
+
//////// used controllers ////////
@@ -97,33 +118,48 @@ private:
//////// internal data ////////
- Renderable* m_pickPointerRenderable;
- RenderMaterial* m_pickPointerRenderMaterial;
- DirectX::XMFLOAT4 m_pickPointerColor;
+ RenderMaterial* m_toolRenderMaterial;
+ Renderable* m_sphereToolRenderable;
+ DirectX::XMFLOAT4 m_toolColor;
+ Renderable* m_lineToolRenderable;
- float m_damageRadius;
- float m_compressiveDamage;
- float m_explosiveImpulse;
- float m_stressForceFactor;
- uint32_t m_damageProfile;
+ float m_damage;
+ float m_explosiveImpulse;
+ float m_stressForceFactor;
struct Damager
{
- const char* uiName;
- NvBlastDamageProgram program;
- DirectX::XMFLOAT4 pointerColor;
- std::function<void(const Damager* damager, Nv::Blast::ExtPxActor* actor, physx::PxVec3 position, physx::PxVec3 normal)> executeFunction;
-
- void execute(Nv::Blast::ExtPxActor* actor, physx::PxVec3 position, physx::PxVec3 normal)
+ Damager() : damageWhilePressed(false), radius(5.0f), radiusLimit(1000.0f)
{
- executeFunction(this, actor, position, normal);
}
+
+ enum PointerType
+ {
+ Sphere,
+ Line
+ };
+
+ typedef std::function<void(const Damager* damager, Nv::Blast::ExtPxActor* actor, physx::PxVec3 origin, physx::PxVec3 position, physx::PxVec3 normal)> ExecuteFn;
+
+ const char* uiName;
+ NvBlastDamageProgram program;
+ PointerType pointerType;
+ DirectX::XMFLOAT4 pointerColor;
+ float radius;
+ float radiusLimit;
+ bool damageWhilePressed;
+ ExecuteFn executeFunction;
};
- std::vector<Damager> m_armory;
- std::vector<const char*> m_armoryNames;
+ std::vector<Damager> m_damagers;
+ std::vector<const char*> m_damagerNames;
+ uint32_t m_damagerIndex;
+
+ bool m_damageMode;
- bool m_damageMode;
+ physx::PxVec2 m_lastMousePos;
+ bool m_isMousePressed;
+ uint32_t m_damageCountWhilePressed;
};
#endif \ No newline at end of file
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/EditionToolController.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/EditionToolController.cpp
index 244f121..b2533a6 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/EditionToolController.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/EditionToolController.cpp
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "EditionToolController.h"
#include "BlastController.h"
@@ -76,7 +94,7 @@ LRESULT EditionToolController::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR
PxRaycastHit hit; hit.shape = NULL;
PxRaycastBuffer hit1;
- getPhysXController().getPhysXScene().raycast(eyePos, pickDir, PX_MAX_F32, hit1, PxHitFlag::ePOSITION | PxHitFlag::eNORMAL);
+ getPhysXController().getEditPhysXScene().raycast(eyePos, pickDir, PX_MAX_F32, hit1, PxHitFlag::ePOSITION | PxHitFlag::eNORMAL);
hit = hit1.block;
PxRigidActor* actor = NULL;
@@ -109,19 +127,8 @@ void EditionToolController::fracture(PxActor* actor)
return;
}
- ExtPxActor* extActor = NULL;
PxRigidDynamic* rigidDynamic = actor->is<PxRigidDynamic>();
- if (NULL != rigidDynamic)
- {
- extActor = blastController.getExtPxManager().getActorFromPhysXActor(*rigidDynamic);
- }
- if (NULL == extActor)
- {
- return;
- }
-
- uint32_t chunkCount = extActor->getChunkCount();
- if (chunkCount <= 0)
+ if (NULL == rigidDynamic)
{
return;
}
@@ -131,7 +138,7 @@ void EditionToolController::fracture(PxActor* actor)
for (; it != families.end(); it++)
{
BlastFamilyPtr f = *it;
- if (f->find(extActor))
+ if (f->find(*actor))
{
pBlastFamily = f;
break;
@@ -142,17 +149,13 @@ void EditionToolController::fracture(PxActor* actor)
return;
}
- const uint32_t* chunkIndices = extActor->getChunkIndices();
+ const uint32_t chunkIndex = pBlastFamily->getChunkIndexByPxActor(*actor);
const BlastAsset& blastAsset = pBlastFamily->getBlastAsset();
- const BlastAsset* pBlastAsset = &blastAsset;
-
- SceneController& sceneController = getManager()->getSceneController();
- AssetList::ModelAsset desc;
- sceneController.GetAssetDesc(pBlastAsset, desc);
+ BlastAsset* pBlastAsset = (BlastAsset*)&blastAsset;
- std::string assetname = desc.id;
- GlobalSettings& globalSettings = GlobalSettings::Inst();
- getManager()->fractureAsset(globalSettings.m_projectFileDir, assetname, pBlastAsset, chunkIndices[0]);
- getManager()->addModelAsset(globalSettings.m_projectFileDir, assetname, desc.isSkinned, desc.transform, false);
+ VoronoiFractureExecutor executor;
+ executor.setSourceAsset(pBlastAsset);
+ executor.setTargetChunk(chunkIndex);
+ executor.execute();
} \ No newline at end of file
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/EditionToolController.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/EditionToolController.h
index b1e88d1..5f71b58 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/EditionToolController.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/EditionToolController.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef EDITION_TOOL_CONTROLLER_H
#define EDITION_TOOL_CONTROLLER_H
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/ExplodeToolController.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/ExplodeToolController.cpp
new file mode 100644
index 0000000..28ac182
--- /dev/null
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/ExplodeToolController.cpp
@@ -0,0 +1,256 @@
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
+
+#include "ExplodeToolController.h"
+#include "RenderUtils.h"
+#include "BlastController.h"
+#include "Renderer.h"
+#include "PhysXController.h"
+#include "SampleProfiler.h"
+#include "GizmoToolController.h"
+
+#include <imgui.h>
+
+#include "NvBlastTkActor.h"
+#include "NvBlastExtDamageShaders.h"
+
+#include "PxRigidDynamic.h"
+#include "PxScene.h"
+#include "BlastSceneTree.h"
+#include "SimpleScene.h"
+#include "ViewerOutput.h"
+
+using namespace Nv::Blast;
+using namespace physx;
+
+const float EXPLODE_MIN = 0.0f;
+const float EXPLODE_MAX = 2.0f;
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Setup
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+ExplodeToolController::ExplodeToolController()
+ : m_previousExplodeValue(0.0f)
+ , m_starDrag(false)
+{
+}
+
+ExplodeToolController::~ExplodeToolController()
+{
+}
+
+void ExplodeToolController::onSampleStart()
+{
+}
+
+void ExplodeToolController::onInitialize()
+{
+ m_previousExplodeValue = 0.0f;
+}
+
+
+void ExplodeToolController::onSampleStop()
+{
+}
+
+void ExplodeToolController::Animate(double dt)
+{
+ PROFILER_SCOPED_FUNCTION();
+}
+
+
+LRESULT ExplodeToolController::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ PROFILER_SCOPED_FUNCTION();
+
+ SampleManager* pSampleManager = SampleManager::ins();
+ if (pSampleManager->IsSimulating())
+ {
+ return 1;
+ }
+
+ if (uMsg == WM_LBUTTONDOWN)
+ {
+ m_mouseStartPoint.x = (short)LOWORD(lParam);
+ m_mouseStartPoint.y = (short)HIWORD(lParam);
+ m_starDrag = true;
+ }
+ else if (uMsg == WM_MOUSEMOVE)
+ {
+ if (!m_starDrag)
+ return 1;
+
+ float theDragDistance = (short)LOWORD(lParam) - m_mouseStartPoint.x;
+ // ignore shorter mouse move
+ if (fabs(theDragDistance) <= 3.0)
+ return 1;
+
+ theDragDistance /= getRenderer().getScreenWidth();
+ theDragDistance *= EXPLODE_MAX;
+ float theNewExplodeValue = m_previousExplodeValue + (float)theDragDistance;
+
+ if (theNewExplodeValue < 0)
+ theNewExplodeValue = 0;
+ else if (theNewExplodeValue > EXPLODE_MAX)
+ theNewExplodeValue = EXPLODE_MAX;
+
+ _explode(theNewExplodeValue);
+ }
+ else if (uMsg == WM_LBUTTONUP)
+ {
+ m_previousExplodeValue = 0.0f;
+ m_starDrag = false;
+ }
+ return 1;
+}
+
+void ExplodeToolController::drawUI()
+{
+}
+
+void ExplodeToolController::_explode(float value)
+{
+ SampleManager* pSampleManager = SampleManager::ins();
+
+ BlastAsset* pBlastAsset = nullptr;
+ int nFamilyIndex = -1;
+ pSampleManager->getCurrentSelectedInstance(&pBlastAsset, nFamilyIndex);
+ if (pBlastAsset == nullptr)
+ {
+ std::map<BlastAsset*, AssetList::ModelAsset>& AssetDescMap = pSampleManager->getAssetDescMap();
+ if (AssetDescMap.size() == 1)
+ {
+ std::map<BlastAsset*, AssetList::ModelAsset>::iterator itAssetDescMap = AssetDescMap.begin();
+ pSampleManager->setCurrentSelectedInstance(itAssetDescMap->first, -1);
+ pBlastAsset = pSampleManager->getCurBlastAsset();
+ viewer_msg("no asset selected, use the only one in current scene.");
+ }
+ }
+ if (pBlastAsset == nullptr)
+ {
+ viewer_msg("please select one asset before explode.");
+ return;
+ }
+
+ std::map<BlastAsset*, std::vector<BlastFamily*>>& AssetFamiliesMap = pSampleManager->getAssetFamiliesMap();
+ std::map<BlastAsset*, std::vector<BlastFamily*>>::iterator itAFM = AssetFamiliesMap.find(pBlastAsset);
+ if (itAFM == AssetFamiliesMap.end())
+ {
+ return;
+ }
+
+ std::vector<BlastFamily*> families = itAFM->second;
+ int familySize = families.size();
+ if (familySize == 0)
+ {
+ viewer_msg("no instance for current asset.");
+ return;
+ }
+
+ if (nFamilyIndex == -1 || nFamilyIndex >= familySize)
+ {
+ nFamilyIndex = 0;
+ viewer_msg("no instance selected, use the first one of current asset.");
+ }
+
+ BlastFamily* pFamily = families[nFamilyIndex];
+
+ PxScene& scene = pSampleManager->getPhysXController().getEditPhysXScene();
+ const PxU32 actorsCountTotal = scene.getNbActors(PxActorTypeFlag::eRIGID_DYNAMIC);
+ if (actorsCountTotal == 0)
+ {
+ return;
+ }
+
+ std::vector<PxActor*> actorsTotal(actorsCountTotal);
+ PxU32 nbActors = scene.getActors(PxActorTypeFlag::eRIGID_DYNAMIC, &actorsTotal[0], actorsCountTotal, 0);
+ PX_ASSERT(actorsCountTotal == nbActors);
+
+ std::vector<PxActor*> actors;
+ PxActor* pRootActor = nullptr;
+ for (int act = 0; act < actorsCountTotal; act++)
+ {
+ if (pFamily->find(*actorsTotal[act]))
+ {
+ if (pRootActor == nullptr)
+ {
+ uint32_t chunkIndex = pFamily->getChunkIndexByPxActor(*actorsTotal[act]);
+ std::vector<uint32_t> chunkIndexes;
+ chunkIndexes.push_back(chunkIndex);
+ std::vector<BlastChunkNode*> chunkNodes = BlastTreeData::ins().getChunkNodeByBlastChunk(pBlastAsset, chunkIndexes);
+ if (chunkNodes.size() > 0 && BlastTreeData::isRoot(chunkNodes[0]))
+ {
+ pRootActor = actorsTotal[act];
+ }
+ else
+ {
+ actors.push_back(actorsTotal[act]);
+ }
+ }
+ else
+ {
+ actors.push_back(actorsTotal[act]);
+ }
+ }
+ }
+
+ if (pRootActor == nullptr)
+ {
+ return;
+ }
+
+ BlastController& blastController = pSampleManager->getBlastController();
+
+ PxVec3 origin = pRootActor->getWorldBounds().getCenter();
+
+ int actorsCount = actors.size();
+ for (int ac = 0; ac < actorsCount; ac++)
+ {
+ PxActor* actor = actors[ac];
+ PxRigidDynamic* dynamic = actor->is<PxRigidDynamic>();
+ PX_ASSERT(dynamic != nullptr);
+ PxTransform transformOld = dynamic->getGlobalPose();
+ PxTransform transformNew = transformOld;
+
+ PxBounds3 bound = actor->getWorldBounds();
+ PxVec3 target = bound.getCenter();
+
+ //PxVec3 tChange = (target - origin) * value;
+ //PxVec3 newTarget = target + tChange;
+ //transformNew.p = transformOld.p + tChange;
+ transformNew.p = (target - origin) * value;
+
+ dynamic->setGlobalPose(transformNew);
+ blastController.updateActorRenderableTransform(*actor, transformNew, false);
+ }
+}
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/ExplodeToolController.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/ExplodeToolController.h
new file mode 100644
index 0000000..9a417ca
--- /dev/null
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/ExplodeToolController.h
@@ -0,0 +1,100 @@
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
+
+#ifndef EXPLODE_TOOL_CONTROLLER_H
+#define EXPLODE_TOOL_CONTROLLER_H
+
+#include "SampleManager.h"
+#include "PxVec2.h"
+#include "PxVec3.h"
+#include "DebugRenderBuffer.h"
+#include "BlastFamily.h"
+#include "NvBlastExtPxManager.h"
+#include "BlastSceneTree.h"
+
+class Renderable;
+class RenderMaterial;
+
+namespace Nv
+{
+namespace Blast
+{
+class ExtPxActor;
+}
+}
+
+namespace physx
+{
+ class PxScene;
+}
+
+class ExplodeToolController : public ISampleController
+{
+public:
+ ExplodeToolController();
+ virtual ~ExplodeToolController();
+
+ virtual LRESULT MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+ virtual void Animate(double dt);
+ void drawUI();
+
+ virtual void onInitialize();
+ virtual void onSampleStart();
+ virtual void onSampleStop();
+
+private:
+ ExplodeToolController& operator= (ExplodeToolController&);
+
+ //////// private methods ////////
+
+ //////// used controllers ////////
+
+ Renderer& getRenderer() const
+ {
+ return getManager()->getRenderer();
+ }
+
+ PhysXController& getPhysXController() const
+ {
+ return getManager()->getPhysXController();
+ }
+
+ BlastController& getBlastController() const
+ {
+ return getManager()->getBlastController();
+ }
+
+ void _explode(float value);
+ //////// internal data ////////
+
+ float m_previousExplodeValue;
+ PxVec2 m_mouseStartPoint;
+ bool m_starDrag;
+};
+
+#endif // EXPLODE_TOOL_CONTROLLER_H \ No newline at end of file
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/GizmoToolController.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/GizmoToolController.cpp
index ff0ffa9..ea91766 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/GizmoToolController.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/GizmoToolController.cpp
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "GizmoToolController.h"
#include "RenderUtils.h"
@@ -15,6 +33,7 @@
#include "Renderer.h"
#include "PhysXController.h"
#include "SampleProfiler.h"
+#include "ViewerOutput.h"
#include <imgui.h>
@@ -23,9 +42,12 @@
#include "PxRigidDynamic.h"
#include "PxScene.h"
+#include "PxPhysics.h"
+#include "cooking/PxCooking.h"
+#include "NvBlastExtPxActor.h"
#include <AppMainWindow.h>
-
-
+#include "BlastSceneTree.h"
+#include "SimpleScene.h"
using namespace Nv::Blast;
using namespace physx;
@@ -43,65 +65,123 @@ const physx::PxU32 Y_DIRECTION_COLOR_U = XMFLOAT4ToU32Color(Y_DIRECTION_COLOR_F)
const physx::PxU32 Z_DIRECTION_COLOR_U = XMFLOAT4ToU32Color(Z_DIRECTION_COLOR_F);
const physx::PxU32 HIGHLIGHT_COLOR_U = XMFLOAT4ToU32Color(HIGHLIGHT_COLOR_F);
-const float defaultAxisLength = 10.0;
+float defaultAxisLength = 10.0;
const float defaultAxisModifier = -1.0;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-GizmoToolController::GizmoToolController()
+void modifyPxActorByLocalWay(PxScene& pxScene, PxRigidDynamic& actor, PxTransform& gp_old, PxTransform& gp_new)
{
- m_bGizmoFollowed = false;
+ uint32_t shapesCount = actor.getNbShapes();
+ if (shapesCount > 0)
+ {
+ PxTransform gp_newInv = gp_new.getInverse();
- int segment = 36;
- double span = PxTwoPi / segment;
- PxVec3* vertex = new PxVec3[segment];
+ PxTransform lp_old;
+ PxTransform lp_new;
- for (int i = 0; i < segment; i++)
- {
- vertex[i].x = 0;
- vertex[i].y = 10 * PxSin(i * span);
- vertex[i].z = 10 * PxCos(i * span);
- }
- // x
- for (int i = 0; i < segment - 1; i++)
- {
- m_CircleRenderData.push_back(PxDebugLine(vertex[i], vertex[i + 1], X_DIRECTION_COLOR_U));
- }
- m_CircleRenderData.push_back(PxDebugLine(vertex[segment - 1], vertex[0], X_DIRECTION_COLOR_U));
+ std::vector<PxShape*> shapes(shapesCount);
+ actor.getShapes(&shapes[0], shapesCount);
- for (int i = 0; i < segment; i++)
- {
- vertex[i].x = 10 * PxCos(i * span);
- vertex[i].y = 0;
- vertex[i].z = 10 * PxSin(i * span);
- }
- // y
- for (int i = 0; i < segment - 1; i++)
- {
- m_CircleRenderData.push_back(PxDebugLine(vertex[i], vertex[i + 1], Y_DIRECTION_COLOR_U));
+ pxScene.removeActor(actor);
+ for (uint32_t i = 0; i < shapesCount; i++)
+ {
+ PxShape* shape = shapes[i];
+
+ actor.detachShape(*shape);
+
+ lp_old = shape->getLocalPose();
+ lp_new = gp_newInv * gp_old * lp_old;
+ shape->setLocalPose(lp_new);
+
+ actor.attachShape(*shape);
+ }
+ pxScene.addActor(actor);
}
- m_CircleRenderData.push_back(PxDebugLine(vertex[segment - 1], vertex[0], Y_DIRECTION_COLOR_U));
+}
- for (int i = 0; i < segment; i++)
+void scalePxActor(PxScene& pxScene, PxRigidDynamic& actor, PxMat44& scale)
+{
+ uint32_t shapesCount = actor.getNbShapes();
+ if (shapesCount == 0)
{
- vertex[i].x = 10 * PxCos(i * span);
- vertex[i].y = 10 * PxSin(i * span);
- vertex[i].z = 0;
+ return;
}
- // z
- for (int i = 0; i < segment - 1; i++)
+
+ std::vector<PxShape*> shapes(shapesCount);
+ actor.getShapes(&shapes[0], shapesCount);
+
+ pxScene.removeActor(actor);
+
+ for (uint32_t i = 0; i < shapesCount; i++)
{
- m_CircleRenderData.push_back(PxDebugLine(vertex[i], vertex[i + 1], Z_DIRECTION_COLOR_U));
+ PxShape* shape = shapes[i];
+
+ PxConvexMeshGeometry mesh;
+ bool valid = shape->getConvexMeshGeometry(mesh);
+ if (!valid)
+ {
+ continue;
+ }
+
+ PxConvexMesh* pMesh = mesh.convexMesh;
+ if (NULL == pMesh)
+ {
+ continue;
+ }
+
+ PxU32 numVertex = pMesh->getNbVertices();
+ if (numVertex == 0)
+ {
+ continue;
+ }
+
+ const PxVec3* pVertex = pMesh->getVertices();
+ PxVec3* pVertexNew = new PxVec3[numVertex];
+ for (PxU32 v = 0; v < numVertex; v++)
+ {
+ pVertexNew[v] = scale.transform(pVertex[v]);
+ }
+
+ PxConvexMeshDesc convexMeshDesc;
+ convexMeshDesc.points.count = numVertex;
+ convexMeshDesc.points.data = pVertexNew;
+ convexMeshDesc.points.stride = sizeof(PxVec3);
+ convexMeshDesc.flags = PxConvexFlag::eCOMPUTE_CONVEX;
+ SampleManager* manager = SampleManager::ins();
+ PxPhysics& physics = manager->getPhysXController().getPhysics();
+ PxCooking& cooking = manager->getPhysXController().getCooking();
+ PxConvexMesh* convexMesh = cooking.createConvexMesh(convexMeshDesc, physics.getPhysicsInsertionCallback());
+ if (NULL == convexMesh)
+ {
+ delete[] pVertexNew;
+ continue;
+ }
+
+ mesh.convexMesh = convexMesh;
+
+ actor.detachShape(*shape);
+ shape->setGeometry(mesh);
+ actor.attachShape(*shape);
+
+ pMesh->release();
+ delete[] pVertexNew;
}
- m_CircleRenderData.push_back(PxDebugLine(vertex[segment - 1], vertex[0], Z_DIRECTION_COLOR_U));
- delete[] vertex;
- vertex = NULL;
+ pxScene.addActor(actor);
+}
+
+GizmoToolController::GizmoToolController()
+{
+ m_bGizmoFollowed = false;
+
+ UpdateCircleRenderData(defaultAxisLength);
resetPos();
+
+ BlastSceneTree::ins()->addObserver(this);
}
GizmoToolController::~GizmoToolController()
@@ -154,6 +234,37 @@ void GizmoToolController::onSampleStop()
{
}
+void GizmoToolController::dataSelected(std::vector<BlastNode*> selections)
+{
+ if (!IsEnabled())
+ return;
+
+ BlastController& blastController = getBlastController();
+ std::vector<BlastFamilyPtr>& families = blastController.getFamilies();
+
+ std::set<PxActor*> selectedActors;
+ PxActor* targetActor = nullptr;
+ for (BlastFamily* family : families)
+ {
+ std::vector<uint32_t> selectedChunks = family->getSelectedChunks();
+ for (uint32_t chunkIndex : selectedChunks)
+ {
+ PxActor* actor = nullptr;
+ family->getPxActorByChunkIndex(chunkIndex, &actor);
+
+ if (actor)
+ {
+ selectedActors.insert(actor);
+ targetActor = actor;
+ }
+ }
+ }
+
+ if (targetActor)
+ setTargetActor(targetActor);
+ getSelectionToolController().setTargetActors(selectedActors);
+}
+
void GizmoToolController::Animate(double dt)
{
PROFILER_SCOPED_FUNCTION();
@@ -170,6 +281,9 @@ void GizmoToolController::Animate(double dt)
return;
}
+ m_TargetPos = m_CurrentActor->getGlobalPose().p;
+ m_bNeedResetPos = true;
+
bool isTranslation = m_GizmoToolMode == GTM_Translate;
bool isScale = m_GizmoToolMode == GTM_Scale;
bool isRotation = m_GizmoToolMode == GTM_Rotation;
@@ -187,6 +301,8 @@ void GizmoToolController::Animate(double dt)
m_AxisBoxRenderable[AT_Y]->setHidden(!isScale);
m_AxisBoxRenderable[AT_Z]->setHidden(!isScale);
+ syncRenderableState();
+
if (showLine)
{
if (m_bNeedResetPos)
@@ -430,8 +546,6 @@ void GizmoToolController::Animate(double dt)
m_bNeedResetColor = false;
}
-#include "PxPhysics.h"
-#include "cooking/PxCooking.h"
LRESULT GizmoToolController::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
PROFILER_SCOPED_FUNCTION();
@@ -439,297 +553,338 @@ LRESULT GizmoToolController::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
if (uMsg == WM_LBUTTONDOWN || uMsg == WM_MOUSEMOVE || uMsg == WM_LBUTTONUP)
{
float mouseX = (short)LOWORD(lParam) / getRenderer().getScreenWidth();
+ if (!SimpleScene::Inst()->m_pCamera->_lhs)
+ {
+ mouseX = 1 - mouseX;
+ }
float mouseY = (short)HIWORD(lParam) / getRenderer().getScreenHeight();
- bool press = uMsg == WM_LBUTTONDOWN;
- if (m_GizmoToolMode == GTM_Translate)
+ PxVec3 eyePos, pickDir;
+ getPhysXController().getEyePoseAndPickDir(mouseX, mouseY, eyePos, pickDir);
+ pickDir = pickDir.getNormalized();
+
+ if (uMsg == WM_LBUTTONDOWN)
{
- if (uMsg == WM_LBUTTONDOWN)
+ if (m_AxisSelected == AT_Num)
{
- if (m_AxisSelected == AT_Num)
- {
- PxVec3 eyePos, pickDir;
- getPhysXController().getEyePoseAndPickDir(mouseX, mouseY, eyePos, pickDir);
- pickDir = pickDir.getNormalized();
+ PxRaycastBufferN<32> hits;
+ GetPhysXScene().raycast(eyePos, pickDir, PX_MAX_F32, hits, PxHitFlag::ePOSITION | PxHitFlag::eMESH_MULTIPLE);
- PxRaycastHit hit; hit.shape = NULL;
- PxRaycastBuffer hit1;
- getPhysXController().getPhysXScene().raycast(eyePos, pickDir, PX_MAX_F32, hit1, PxHitFlag::ePOSITION | PxHitFlag::eNORMAL);
- hit = hit1.block;
+ PxU32 nbThouches = hits.getNbTouches();
+ const PxRaycastHit* touches = hits.getTouches();
- if (hit.shape)
+ PxRigidActor* actor = NULL;
+ for (PxU32 u = 0; u < nbThouches; ++u)
+ {
+ const PxRaycastHit& t = touches[u];
+ if (t.shape && getBlastController().isActorVisible(*(t.actor)))
{
- PxRigidActor* actor = hit.actor;
- PxRigidDynamic* rigidDynamic = actor->is<PxRigidDynamic>();
- if (NULL != rigidDynamic)
- {
- m_CurrentActor = actor;
- getSelectionToolController().pointSelect(m_CurrentActor);
+ actor = t.actor;
+ }
+ }
- PxTransform gp = m_CurrentActor->getGlobalPose();
+ if (actor)
+ {
+ PxRigidDynamic* rigidDynamic = actor->is<PxRigidDynamic>();
+ if (NULL != rigidDynamic)
+ {
+ m_CurrentActor = rigidDynamic;
+ getSelectionToolController().pointSelect(m_CurrentActor);
- m_TargetPos = gp.p;
- m_Axis[AT_X] = gp.q.rotate(PxVec3(defaultAxisLength, 0, 0));
- m_Axis[AT_Y] = gp.q.rotate(PxVec3(0, defaultAxisLength, 0));
- m_Axis[AT_Z] = gp.q.rotate(PxVec3(0, 0, defaultAxisLength));
+ PxTransform gp = m_CurrentActor->getGlobalPose();
- m_bNeedResetPos = true;
- }
- else
- {
- m_CurrentActor = NULL;
- getSelectionToolController().clearSelect();
- }
+ m_TargetPos = gp.p;
+ m_Axis[AT_X] = gp.q.rotate(PxVec3(defaultAxisLength, 0, 0));
+ m_Axis[AT_Y] = gp.q.rotate(PxVec3(0, defaultAxisLength, 0));
+ m_Axis[AT_Z] = gp.q.rotate(PxVec3(0, 0, defaultAxisLength));
+
+ m_bNeedResetPos = true;
+ }
+ else
+ {
+ m_CurrentActor = NULL;
+ getSelectionToolController().clearSelect();
}
}
- else
+ }
+ else
+ {
+ m_bGizmoFollowed = (m_CurrentActor != NULL);
+
+ if (m_GizmoToolMode == GTM_Scale)
{
- m_bGizmoFollowed = (m_CurrentActor != NULL);
+ m_LastAxis[AT_X] = m_Axis[AT_X].getNormalized();
+ m_LastAxis[AT_Y] = m_Axis[AT_Y].getNormalized();
+ m_LastAxis[AT_Z] = m_Axis[AT_Z].getNormalized();
}
}
- else if (uMsg == WM_MOUSEMOVE)
+ }
+ else if (uMsg == WM_MOUSEMOVE)
+ {
+ if (m_bGizmoFollowed)
{
- if (m_bGizmoFollowed)
+ switch (m_GizmoToolMode)
{
- PxVec3 eyePos, pickDir;
- getPhysXController().getEyePoseAndPickDir(mouseX, mouseY, eyePos, pickDir);
- pickDir = pickDir.getNormalized();
-
- PxVec3 axis = m_Axis[m_AxisSelected];
- axis = axis.getNormalized();
- PxVec3 samplepoint = eyePos + pickDir;
- PxVec3 normal = m_LastEyeRay.cross(axis);
- normal = normal.getNormalized();
- PxVec3 foot;
- GetFootFromPointToPlane(samplepoint, eyePos, normal, foot);
- PxVec3 direction = foot - eyePos;
- direction = direction.getNormalized();
- PxVec3 target;
- GetIntersectBetweenLines(m_LastFoot, axis, eyePos, direction, target);
- PxVec3 delta = target - m_LastFoot;
-
- m_LastEyeRay = direction;
- m_LastFoot = target;
-
- PxTransform gp_old = m_CurrentActor->getGlobalPose();
- PxTransform gp_new(gp_old.p + delta, gp_old.q);;
- m_CurrentActor->setGlobalPose(gp_new);
-
- m_TargetPos = gp_new.p;
-
- bool local = AppMainWindow::Inst().m_bGizmoWithLocal;
- if (local)
+ case GTM_Translate:
{
- uint32_t shapesCount = m_CurrentActor->getNbShapes();
- if (shapesCount > 0)
+ if (AppMainWindow::Inst().m_bGizmoWithLocal && !CanModifyLocal(m_CurrentActor))
{
- PxTransform gp_newInv = gp_new.getInverse();
+ char message[1024];
+ sprintf(message, "Only unfractured model can be modify in local way in edit mode!");
+ viewer_warn(message);
+ return 1;
+ }
- PxTransform lp_old;
- PxTransform lp_new;
+ PxVec3 axis = m_Axis[m_AxisSelected];
+ axis = axis.getNormalized();
+ PxVec3 samplepoint = eyePos + pickDir;
+ PxVec3 normal = m_LastEyeRay.cross(axis);
+ normal = normal.getNormalized();
+ PxVec3 foot;
+ GetFootFromPointToPlane(samplepoint, eyePos, normal, foot);
+ PxVec3 direction = foot - eyePos;
+ direction = direction.getNormalized();
+ PxVec3 target;
+ GetIntersectBetweenLines(m_LastFoot, axis, eyePos, direction, target);
+ PxVec3 delta = target - m_LastFoot;
- std::vector<PxShape*> shapes(shapesCount);
- m_CurrentActor->getShapes(&shapes[0], shapesCount);
- getPhysXController().getPhysXScene().removeActor(*m_CurrentActor);
- for (uint32_t i = 0; i < shapesCount; i++)
- {
- PxShape* shape = shapes[i];
+ m_LastEyeRay = direction;
+ m_LastFoot = target;
- m_CurrentActor->detachShape(*shape);
+ PxTransform gp_old = m_CurrentActor->getGlobalPose();
+ PxTransform gp_new(gp_old.p + delta, gp_old.q);
+ m_CurrentActor->setGlobalPose(gp_new);
- lp_old = shape->getLocalPose();
- lp_new = gp_newInv * gp_old * lp_old;
- shape->setLocalPose(lp_new);
+ bool modifyLocal = AppMainWindow::Inst().m_bGizmoWithLocal && CanModifyLocal(m_CurrentActor);
- m_CurrentActor->attachShape(*shape);
- }
- getPhysXController().getPhysXScene().addActor(*m_CurrentActor);
+ if (!SampleManager::ins()->IsSimulating())
+ {
+ getBlastController().updateActorRenderableTransform(*m_CurrentActor, gp_new, modifyLocal);
+ if (CanMapToRootChunk(m_CurrentActor) && !modifyLocal)
+ UpdateAssetInstanceTransform(gp_new);
}
- }
- m_bNeedResetPos = true;
- m_bNeedResetColor = true;
- }
- else if(m_CurrentActor != NULL)
- {
- PxVec3 eyePos, pickDir;
- getPhysXController().getEyePoseAndPickDir(mouseX, mouseY, eyePos, pickDir);
- pickDir = pickDir.getNormalized();
+ m_TargetPos = gp_new.p;
- m_LastEyeRay = pickDir;
+ if (modifyLocal)
+ {
+ modifyPxActorByLocalWay(GetPhysXScene(), *m_CurrentActor, gp_old, gp_new);
+ }
- // get axis which intersect with this eye ray
- AxisType as = AT_Num;
+ m_bNeedResetPos = true;
+ m_bNeedResetColor = true;
+ }
+ break;
+ case GTM_Scale:
{
- double distanceMin = PX_MAX_F32;
- double tolerance = 1;
- int line_index = -1;
- PxVec3 foot;
- std::vector<PxDebugLine>& lines = m_AxisRenderBuffer.m_lines;
- int linesize = lines.size();
- for (int l = 0; l < linesize; l++)
+ if (AppMainWindow::Inst().m_bGizmoWithLocal && !CanModifyLocal(m_CurrentActor))
{
- PxVec3 start = lines[l].pos0;
- PxVec3 end = lines[l].pos1;
- PxVec3 dir = end - start;
- double length = dir.magnitude();
- // separate the line to 10 segment
- double delta = length * 0.1;
- for (int segment = 0; segment <= 10; segment++)
- {
- PxVec3 vertex = start + 0.1 * segment * dir;
- double distance = DistanceFromPointToLine(vertex, eyePos, pickDir, foot);
+ char message[1024];
+ sprintf(message, "Only unfractured model can be modify in local way in edit mode!");
+ viewer_warn(message);
+ return 1;
+ }
- if (distance < distanceMin)
- {
- distanceMin = distance;
- line_index = l;
- m_LastFoot = foot;
- }
- }
+ PxVec3 axis = m_LastAxis[m_AxisSelected];
+ PxVec3 samplepoint = eyePos + pickDir;
+ PxVec3 normal = m_LastEyeRay.cross(axis);
+ normal = normal.getNormalized();
+ PxVec3 foot;
+ GetFootFromPointToPlane(samplepoint, eyePos, normal, foot);
+ PxVec3 direction = foot - eyePos;
+ direction = direction.getNormalized();
+ PxVec3 target;
+ GetIntersectBetweenLines(m_LastFoot, axis, eyePos, direction, target);
+ PxVec3 delta = target - m_LastFoot;
+
+ if (m_AxisSelected == AT_X)
+ {
+ delta *= defaultAxisModifier;
}
- if (distanceMin < tolerance)
+ m_Axis[m_AxisSelected] = m_LastAxis[m_AxisSelected] * defaultAxisLength + delta;
+
+ bool isShift = (GetAsyncKeyState(VK_SHIFT) && 0x8000);
+ if (isShift)
{
- int axis_index = line_index * 3 / linesize;
- as = (AxisType)axis_index;
+ float length = m_Axis[m_AxisSelected].magnitude();
+ m_Axis[AT_X] = m_LastAxis[AT_X] * length;
+ m_Axis[AT_Y] = m_LastAxis[AT_Y] * length;
+ m_Axis[AT_Z] = m_LastAxis[AT_Z] * length;
}
- }
- setAxisSelected(as);
- }
- }
- else if (uMsg == WM_LBUTTONUP)
- {
- m_bNeedResetPos = true;
- m_bNeedResetColor = true;
- m_bGizmoFollowed = false;
- }
- }
- else if (m_GizmoToolMode == GTM_Scale)
- {
- if (uMsg == WM_LBUTTONDOWN)
- {
- if (m_AxisSelected == AT_Num)
- {
- PxVec3 eyePos, pickDir;
- getPhysXController().getEyePoseAndPickDir(mouseX, mouseY, eyePos, pickDir);
- pickDir = pickDir.getNormalized();
- PxRaycastHit hit; hit.shape = NULL;
- PxRaycastBuffer hit1;
- getPhysXController().getPhysXScene().raycast(eyePos, pickDir, PX_MAX_F32, hit1, PxHitFlag::ePOSITION | PxHitFlag::eNORMAL);
- hit = hit1.block;
+ ScaleActor(false);
+
+ m_bNeedResetPos = true;
+ m_bNeedResetColor = true;
+ }
+ break;
- if (hit.shape)
+ case GTM_Rotation:
{
- PxRigidActor* actor = hit.actor;
- PxRigidDynamic* rigidDynamic = actor->is<PxRigidDynamic>();
- if (NULL != rigidDynamic)
+ if (AppMainWindow::Inst().m_bGizmoWithLocal && !CanModifyLocal(m_CurrentActor))
+ {
+ char message[1024];
+ sprintf(message, "Only unfractured model can be modify in local way in edit mode!");
+ viewer_warn(message);
+ return 1;
+ }
+
+ PxVec3 planenormal = m_Axis[m_AxisSelected];
+ planenormal = planenormal.getNormalized();
+
+ PxVec3 from, to;
+ CalPlaneLineIntersectPoint(from, planenormal, m_TargetPos, m_LastEyeRay, eyePos);
+ CalPlaneLineIntersectPoint(to, planenormal, m_TargetPos, pickDir, eyePos);
+ from = from - m_TargetPos;
+ to = to - m_TargetPos;
+ from = from.getNormalized();
+ to = to.getNormalized();
+ float cosangle = from.dot(to);
+ float angle = PxAcos(cosangle);
+ PxVec3 cross = from.cross(to);
+ cross = cross.getNormalized();
+
+ PxQuat q(angle, cross);
+ if (m_AxisSelected == AT_X)
+ {
+ m_Axis[AT_Y] = q.rotate(m_Axis[AT_Y]);
+ m_Axis[AT_Z] = q.rotate(m_Axis[AT_Z]);
+ }
+ else if (m_AxisSelected == AT_Y)
+ {
+ m_Axis[AT_X] = q.rotate(m_Axis[AT_X]);
+ m_Axis[AT_Z] = q.rotate(m_Axis[AT_Z]);
+ }
+ else if (m_AxisSelected == AT_Z)
{
- m_CurrentActor = actor;
- getSelectionToolController().pointSelect(m_CurrentActor);
+ m_Axis[AT_X] = q.rotate(m_Axis[AT_X]);
+ m_Axis[AT_Y] = q.rotate(m_Axis[AT_Y]);
+ }
- PxTransform gp = m_CurrentActor->getGlobalPose();
+ m_LastEyeRay = pickDir;
- m_TargetPos = gp.p;
- m_Axis[AT_X] = gp.q.rotate(PxVec3(defaultAxisLength, 0, 0));
- m_Axis[AT_Y] = gp.q.rotate(PxVec3(0, defaultAxisLength, 0));
- m_Axis[AT_Z] = gp.q.rotate(PxVec3(0, 0, defaultAxisLength));
+ PxTransform gp_old = m_CurrentActor->getGlobalPose();
+ PxTransform gp_new = PxTransform(gp_old.p, CalConvertQuat());
+ m_CurrentActor->setGlobalPose(gp_new);
+ bool modifyLocal = AppMainWindow::Inst().m_bGizmoWithLocal && CanModifyLocal(m_CurrentActor);
- m_bNeedResetPos = true;
+ if (!SampleManager::ins()->IsSimulating())
+ {
+ getBlastController().updateActorRenderableTransform(*m_CurrentActor, gp_new, modifyLocal);
+ if (CanMapToRootChunk(m_CurrentActor))
+ UpdateAssetInstanceTransform(gp_new);
}
- else
+
+ if (modifyLocal)
{
- m_CurrentActor = NULL;
- getSelectionToolController().clearSelect();
+ modifyPxActorByLocalWay(GetPhysXScene(), *m_CurrentActor, gp_old, gp_new);
}
+
+ m_bNeedResetPos = true;
+ m_bNeedResetColor = true;
}
- }
- else
- {
- m_bGizmoFollowed = (m_CurrentActor != NULL);
- m_LastAxis[AT_X] = m_Axis[AT_X].getNormalized();
- m_LastAxis[AT_Y] = m_Axis[AT_Y].getNormalized();
- m_LastAxis[AT_Z] = m_Axis[AT_Z].getNormalized();
+ break;
}
}
- else if (uMsg == WM_MOUSEMOVE)
+ else if(m_CurrentActor != NULL)
{
- if (m_bGizmoFollowed)
+ m_LastEyeRay = pickDir;
+
+ // get axis which intersect with this eye ray
+ AxisType as = AT_Num;
{
- PxVec3 eyePos, pickDir;
- getPhysXController().getEyePoseAndPickDir(mouseX, mouseY, eyePos, pickDir);
- pickDir = pickDir.getNormalized();
-
- PxVec3 axis = m_LastAxis[m_AxisSelected];
- PxVec3 samplepoint = eyePos + pickDir;
- PxVec3 normal = m_LastEyeRay.cross(axis);
- normal = normal.getNormalized();
+ double distanceMin = PX_MAX_F32;
+ double tolerance = defaultAxisLength / 20.0f;
+ int line_index = -1;
PxVec3 foot;
- GetFootFromPointToPlane(samplepoint, eyePos, normal, foot);
- PxVec3 direction = foot - eyePos;
- direction = direction.getNormalized();
- PxVec3 target;
- GetIntersectBetweenLines(m_LastFoot, axis, eyePos, direction, target);
- PxVec3 delta = target - m_LastFoot;
-
- if (m_AxisSelected == AT_X)
- {
- delta *= defaultAxisModifier;
- }
- m_Axis[m_AxisSelected] = m_LastAxis[m_AxisSelected] * defaultAxisLength + delta;
-
- bool isShift = (GetAsyncKeyState(VK_SHIFT) && 0x8000);
- if (isShift)
+ switch (m_GizmoToolMode)
{
- float length = m_Axis[m_AxisSelected].magnitude();
- m_Axis[AT_X] = m_LastAxis[AT_X] * length;
- m_Axis[AT_Y] = m_LastAxis[AT_Y] * length;
- m_Axis[AT_Z] = m_LastAxis[AT_Z] * length;
- }
-
- ScaleActor(false);
-
- m_bNeedResetPos = true;
- m_bNeedResetColor = true;
- }
- else if (m_CurrentActor != NULL)
- {
- PxVec3 eyePos, pickDir;
- getPhysXController().getEyePoseAndPickDir(mouseX, mouseY, eyePos, pickDir);
- pickDir = pickDir.getNormalized();
-
- m_LastEyeRay = pickDir;
+ case GTM_Translate:
+ {
+ std::vector<PxDebugLine>& lines = m_AxisRenderBuffer.m_lines;
+ int linesize = lines.size();
+ for (int l = 0; l < linesize; l++)
+ {
+ PxVec3 start = lines[l].pos0;
+ PxVec3 end = lines[l].pos1;
+ PxVec3 dir = end - start;
- // get axis which intersect with this eye ray
- AxisType as = AT_Num;
- {
- double distanceMin = PX_MAX_F32;
- double tolerance = 1;
- int line_index = -1;
- std::vector<PxDebugLine>& lines = m_AxisRenderBuffer.m_lines;
- int linesize = lines.size();
- PxVec3 foot;
- for (int l = 0; l < linesize; l++)
+ // separate the line to 10 segment
+ for (int segment = 0; segment <= 10; segment++)
+ {
+ PxVec3 vertex = start + 0.1 * segment * dir;
+ double distance = DistanceFromPointToLine(vertex, eyePos, pickDir, foot);
+
+ if (distance < distanceMin)
+ {
+ distanceMin = distance;
+ line_index = l;
+ m_LastFoot = foot;
+ }
+ }
+ }
+ if (distanceMin < tolerance)
+ {
+ int axis_index = line_index * 3 / linesize;
+ as = (AxisType)axis_index;
+ }
+ }
+ break;
+ case GTM_Scale:
{
- PxVec3 vertex = lines[l].pos1;
- double distance = DistanceFromPointToLine(vertex, eyePos, pickDir, foot);
+ std::vector<PxDebugLine>& lines = m_AxisRenderBuffer.m_lines;
+ int linesize = lines.size();
+ for (int l = 0; l < linesize; l++)
+ {
+ PxVec3 vertex = lines[l].pos1;
+ double distance = DistanceFromPointToLine(vertex, eyePos, pickDir, foot);
- if (distance < distanceMin)
+ if (distance < distanceMin)
+ {
+ distanceMin = distance;
+ line_index = l;
+ m_LastFoot = foot;
+ }
+ }
+ if (distanceMin < tolerance)
{
- distanceMin = distance;
- line_index = l;
- m_LastFoot = foot;
+ as = (AxisType)line_index;
}
}
- if (distanceMin < tolerance)
+ break;
+ case GTM_Rotation:
{
- as = (AxisType)line_index;
+ std::vector<PxDebugLine>& lines = m_CircleRenderBuffer.m_lines;
+ int linesize = lines.size();
+ for (int l = 0; l < linesize; l++)
+ {
+ PxVec3 vertex = lines[l].pos0;
+ double distance = DistanceFromPointToLine(vertex, eyePos, pickDir, foot);
+
+ if (distance < distanceMin)
+ {
+ distanceMin = distance;
+ line_index = l;
+ m_LastFoot = foot;
+ }
+ }
+ if (distanceMin < tolerance)
+ {
+ int axis_index = line_index * 3 / linesize;
+ as = (AxisType)axis_index;
+ }
}
+ break;
+ default:
+ break;
}
- setAxisSelected(as);
}
+ setAxisSelected(as);
}
- else if (uMsg == WM_LBUTTONUP)
+ }
+ else if (uMsg == WM_LBUTTONUP)
+ {
+ if (m_GizmoToolMode == GTM_Scale)
{
if (m_AxisSelected != AT_Num)
{
@@ -742,180 +897,16 @@ LRESULT GizmoToolController::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
m_Axis[AT_Y] = m_LastAxis[AT_Y] * defaultAxisLength;
m_Axis[AT_Z] = m_LastAxis[AT_Z] * defaultAxisLength;
}
-
- m_bNeedResetPos = true;
- m_bNeedResetColor = true;
- m_bGizmoFollowed = false;
}
- }
- else if (m_GizmoToolMode == GTM_Rotation)
- {
- if (uMsg == WM_LBUTTONDOWN)
- {
- if (m_AxisSelected == AT_Num)
- {
- PxVec3 eyePos, pickDir;
- getPhysXController().getEyePoseAndPickDir(mouseX, mouseY, eyePos, pickDir);
- pickDir = pickDir.getNormalized();
-
- PxRaycastHit hit; hit.shape = NULL;
- PxRaycastBuffer hit1;
- getPhysXController().getPhysXScene().raycast(eyePos, pickDir, PX_MAX_F32, hit1, PxHitFlag::ePOSITION | PxHitFlag::eNORMAL);
- hit = hit1.block;
-
- if (hit.shape)
- {
- PxRigidActor* actor = hit.actor;
- PxRigidDynamic* rigidDynamic = actor->is<PxRigidDynamic>();
- if (NULL != rigidDynamic)
- {
- m_CurrentActor = actor;
- getSelectionToolController().pointSelect(m_CurrentActor);
- PxTransform gp = m_CurrentActor->getGlobalPose();
-
- m_TargetPos = gp.p;
- m_Axis[AT_X] = gp.q.rotate(PxVec3(defaultAxisLength, 0, 0));
- m_Axis[AT_Y] = gp.q.rotate(PxVec3(0, defaultAxisLength, 0));
- m_Axis[AT_Z] = gp.q.rotate(PxVec3(0, 0, defaultAxisLength));
-
- m_bNeedResetPos = true;
- }
- else
- {
- m_CurrentActor = NULL;
- getSelectionToolController().clearSelect();
- }
- }
- }
- else
- {
- m_bGizmoFollowed = (m_CurrentActor != NULL);
- }
- }
- else if (uMsg == WM_MOUSEMOVE)
+ if (m_AxisSelected != AT_Num && AppMainWindow::Inst().m_bGizmoWithLocal)
{
- if (m_bGizmoFollowed)
- {
- PxVec3 eyePos, pickDir;
- getPhysXController().getEyePoseAndPickDir(mouseX, mouseY, eyePos, pickDir);
- pickDir = pickDir.getNormalized();
-
- PxVec3 planenormal = m_Axis[m_AxisSelected];
- planenormal = planenormal.getNormalized();
-
- PxVec3 from, to;
- CalPlaneLineIntersectPoint(from, planenormal, m_TargetPos, m_LastEyeRay, eyePos);
- CalPlaneLineIntersectPoint(to, planenormal, m_TargetPos, pickDir, eyePos);
- from = from - m_TargetPos;
- to = to - m_TargetPos;
- from = from.getNormalized();
- to = to.getNormalized();
- float cosangle = from.dot(to);
- float angle = PxAcos(cosangle);
- PxVec3 cross = from.cross(to);
- cross = cross.getNormalized();
-
- PxQuat q(angle, cross);
- if (m_AxisSelected == AT_X)
- {
- m_Axis[AT_Y] = q.rotate(m_Axis[AT_Y]);
- m_Axis[AT_Z] = q.rotate(m_Axis[AT_Z]);
- }
- else if (m_AxisSelected == AT_Y)
- {
- m_Axis[AT_X] = q.rotate(m_Axis[AT_X]);
- m_Axis[AT_Z] = q.rotate(m_Axis[AT_Z]);
- }
- else if (m_AxisSelected == AT_Z)
- {
- m_Axis[AT_X] = q.rotate(m_Axis[AT_X]);
- m_Axis[AT_Y] = q.rotate(m_Axis[AT_Y]);
- }
-
- m_LastEyeRay = pickDir;
-
- PxTransform gp_old = m_CurrentActor->getGlobalPose();
- PxTransform gp_new = PxTransform(gp_old.p, CalConvertQuat());
- m_CurrentActor->setGlobalPose(gp_new);
-
- bool local = AppMainWindow::Inst().m_bGizmoWithLocal;
- if (local)
- {
- uint32_t shapesCount = m_CurrentActor->getNbShapes();
- if (shapesCount > 0)
- {
- PxTransform gp_newInv = gp_new.getInverse();
-
- PxTransform lp_old;
- PxTransform lp_new;
-
- std::vector<PxShape*> shapes(shapesCount);
- m_CurrentActor->getShapes(&shapes[0], shapesCount);
- getPhysXController().getPhysXScene().removeActor(*m_CurrentActor);
- for (uint32_t i = 0; i < shapesCount; i++)
- {
- PxShape* shape = shapes[i];
-
- m_CurrentActor->detachShape(*shape);
-
- lp_old = shape->getLocalPose();
- lp_new = gp_newInv * gp_old * lp_old;
- shape->setLocalPose(lp_new);
-
- m_CurrentActor->attachShape(*shape);
- }
- getPhysXController().getPhysXScene().addActor(*m_CurrentActor);
- }
- }
-
- m_bNeedResetPos = true;
- m_bNeedResetColor = true;
- }
- else if (m_CurrentActor != NULL)
- {
- PxVec3 eyePos, pickDir;
- getPhysXController().getEyePoseAndPickDir(mouseX, mouseY, eyePos, pickDir);
- pickDir = pickDir.getNormalized();
-
- m_LastEyeRay = pickDir;
-
- // get axis which intersect with this eye ray
- AxisType as = AT_Num;
- {
- double distanceMin = PX_MAX_F32;
- double tolerance = 1;
- int line_index = -1;
- std::vector<PxDebugLine>& lines = m_CircleRenderBuffer.m_lines;
- int linesize = lines.size();
- PxVec3 foot;
- for (int l = 0; l < linesize; l++)
- {
- PxVec3 vertex = lines[l].pos0;
- double distance = DistanceFromPointToLine(vertex, eyePos, pickDir, foot);
-
- if (distance < distanceMin)
- {
- distanceMin = distance;
- line_index = l;
- m_LastFoot = foot;
- }
- }
- if (distanceMin < tolerance)
- {
- int axis_index = line_index * 3 / linesize;
- as = (AxisType)axis_index;
- }
- }
- setAxisSelected(as);
- }
- }
- else if (uMsg == WM_LBUTTONUP)
- {
- m_bNeedResetPos = true;
- m_bNeedResetColor = true;
- m_bGizmoFollowed = false;
+ getBlastController().updateModelMeshToProjectParam(*m_CurrentActor);
}
+
+ m_bNeedResetPos = true;
+ m_bNeedResetColor = true;
+ m_bGizmoFollowed = false;
}
}
@@ -937,6 +928,8 @@ void GizmoToolController::setGizmoToolMode(GizmoToolMode mode)
m_bNeedResetPos = true;
m_bNeedResetColor = true;
+
+ showAxisRenderables(true);
}
void GizmoToolController::setAxisSelected(AxisType type)
@@ -950,6 +943,23 @@ void GizmoToolController::setAxisSelected(AxisType type)
m_bNeedResetColor = true;
}
+void GizmoToolController::setAxisLength(float axisLength)
+{
+ defaultAxisLength = axisLength;
+ UpdateCircleRenderData(axisLength);
+
+ float scale = axisLength / 10.f * 0.2f;
+ m_AxisConeRenderable[AT_X]->setScale(PxVec3(scale, 2 * scale, scale));
+ m_AxisConeRenderable[AT_Y]->setScale(PxVec3(scale, 2 * scale, scale));
+ m_AxisConeRenderable[AT_Z]->setScale(PxVec3(scale, 2 * scale, scale));
+
+ m_AxisBoxRenderable[AT_X]->setScale(PxVec3(scale, scale, scale));
+ m_AxisBoxRenderable[AT_Y]->setScale(PxVec3(scale, scale, scale));
+ m_AxisBoxRenderable[AT_Z]->setScale(PxVec3(scale, scale, scale));
+
+ m_bNeedResetPos = true;
+}
+
void GizmoToolController::showAxisRenderables(bool show)
{
bool isTranslate = m_GizmoToolMode == GTM_Translate;
@@ -974,6 +984,98 @@ void GizmoToolController::resetPos()
m_CurrentActor = NULL;
}
+void GizmoToolController::setTargetActor(PxActor* actor)
+{
+ m_bNeedResetPos = true;
+ m_CurrentActor = nullptr;
+ if (actor == nullptr)
+ {
+ return;
+ }
+ PxRigidDynamic* rigidDynamic = actor->is<PxRigidDynamic>();
+ if (rigidDynamic == nullptr)
+ {
+ return;
+ }
+
+ m_CurrentActor = rigidDynamic;
+ getSelectionToolController().pointSelect(m_CurrentActor);
+
+ PxTransform gp = m_CurrentActor->getGlobalPose();
+
+ m_TargetPos = gp.p;
+ m_Axis[AT_X] = gp.q.rotate(PxVec3(defaultAxisLength, 0, 0));
+ m_Axis[AT_Y] = gp.q.rotate(PxVec3(0, defaultAxisLength, 0));
+ m_Axis[AT_Z] = gp.q.rotate(PxVec3(0, 0, defaultAxisLength));
+}
+
+PxActor* GizmoToolController::getTargetActor()
+{
+ return m_CurrentActor;
+}
+
+physx::PxScene& GizmoToolController::GetPhysXScene()
+{
+ if (getManager()->IsSimulating())
+ {
+ return getPhysXController().getPhysXScene();
+ }
+ else
+ {
+ return getPhysXController().getEditPhysXScene();
+ }
+}
+
+void GizmoToolController::UpdateCircleRenderData(float axisLength)
+{
+ int segment = 36;
+ double span = PxTwoPi / segment;
+ PxVec3* vertex = new PxVec3[segment];
+ m_CircleRenderData.clear();
+
+ for (int i = 0; i < segment; i++)
+ {
+ vertex[i].x = 0;
+ vertex[i].y = axisLength * PxSin(i * span);
+ vertex[i].z = axisLength * PxCos(i * span);
+ }
+ // x
+ for (int i = 0; i < segment - 1; i++)
+ {
+ m_CircleRenderData.push_back(PxDebugLine(vertex[i], vertex[i + 1], X_DIRECTION_COLOR_U));
+ }
+ m_CircleRenderData.push_back(PxDebugLine(vertex[segment - 1], vertex[0], X_DIRECTION_COLOR_U));
+
+ for (int i = 0; i < segment; i++)
+ {
+ vertex[i].x = axisLength * PxCos(i * span);
+ vertex[i].y = 0;
+ vertex[i].z = axisLength * PxSin(i * span);
+ }
+ // y
+ for (int i = 0; i < segment - 1; i++)
+ {
+ m_CircleRenderData.push_back(PxDebugLine(vertex[i], vertex[i + 1], Y_DIRECTION_COLOR_U));
+ }
+ m_CircleRenderData.push_back(PxDebugLine(vertex[segment - 1], vertex[0], Y_DIRECTION_COLOR_U));
+
+ for (int i = 0; i < segment; i++)
+ {
+ vertex[i].x = axisLength * PxCos(i * span);
+ vertex[i].y = axisLength * PxSin(i * span);
+ vertex[i].z = 0;
+ }
+ // z
+ for (int i = 0; i < segment - 1; i++)
+ {
+ m_CircleRenderData.push_back(PxDebugLine(vertex[i], vertex[i + 1], Z_DIRECTION_COLOR_U));
+ }
+ m_CircleRenderData.push_back(PxDebugLine(vertex[segment - 1], vertex[0], Z_DIRECTION_COLOR_U));
+
+ delete[] vertex;
+ vertex = NULL;
+}
+
bool GizmoToolController::CalPlaneLineIntersectPoint(PxVec3& result, PxVec3 planeNormal, PxVec3 planePoint, PxVec3 linedirection, PxVec3 linePoint)
{
float dot = planeNormal.dot(linedirection);
@@ -1008,6 +1110,16 @@ bool GizmoToolController::GetFootFromPointToPlane(PxVec3& point, PxVec3& origin,
bool GizmoToolController::GetIntersectBetweenLines(PxVec3& origin1, PxVec3& direction1, PxVec3& origin2, PxVec3& direction2, PxVec3& intersect)
{
+ float test = ((origin2 - origin1).getNormalized()).dot(direction1.cross(direction2));
+ if (direction1.cross(direction2).isZero())
+ {// if two lines are parallel
+ return false;
+ }
+ else if (abs(test) >= 0.001)
+ {// if two lines aren't in the same plane
+ return false;
+ }
+
PxVec3 normal1 = direction1.cross(direction2);
PxVec3 normal2 = normal1.cross(direction1);
normal2 = normal2.getNormalized();
@@ -1062,38 +1174,22 @@ PxQuat GizmoToolController::CalConvertQuat()
void GizmoToolController::ScaleActor(bool replace)
{
- if (NULL == m_CurrentActor)
- {
- return;
- }
- ExtPxActor* extActor = NULL;
- PxRigidDynamic* rigidDynamic = m_CurrentActor->is<PxRigidDynamic>();
- if (NULL != rigidDynamic)
- {
- extActor = getBlastController().getExtPxManager().getActorFromPhysXActor(*rigidDynamic);
- }
- if (NULL == extActor)
+ if (nullptr == m_CurrentActor)
{
return;
}
- std::vector<BlastFamilyPtr>& families = getBlastController().getFamilies();
- if (families.size() == 0)
+ bool isLocal = AppMainWindow::Inst().m_bGizmoWithLocal;
+
+ if (isLocal && !CanModifyLocal(m_CurrentActor))
{
+ char message[1024];
+ sprintf(message, "Only unfractured model can be modify in local way in edit mode!");
+ viewer_warn(message);
return;
}
- BlastFamilyPtr pBlastFamily = NULL;
- std::vector<BlastFamilyPtr>::iterator it = families.begin();
- for (; it != families.end(); it++)
- {
- BlastFamilyPtr f = *it;
- if (f->find(extActor))
- {
- pBlastFamily = f;
- break;
- }
- }
+ BlastFamilyPtr pBlastFamily = getBlastController().getFamilyByPxActor(*m_CurrentActor);
if (NULL == pBlastFamily)
{
return;
@@ -1116,7 +1212,6 @@ void GizmoToolController::ScaleActor(bool replace)
}
PxMat44 scale = PxMat44(PxVec4(delta, 1));
- bool isLocal = AppMainWindow::Inst().m_bGizmoWithLocal;
if (!isLocal)
{
PxTransform gp = m_CurrentActor->getGlobalPose();
@@ -1134,77 +1229,87 @@ void GizmoToolController::ScaleActor(bool replace)
scale = world * scale * worldInv;
}
- pBlastFamily->setActorScale(*extActor, scale, replace);
+ pBlastFamily->setActorScale(*m_CurrentActor, scale, replace);
if (!replace)
{
return;
}
- uint32_t shapesCount = m_CurrentActor->getNbShapes();
- if (shapesCount == 0)
+ scalePxActor(GetPhysXScene(), *m_CurrentActor, scale);
+}
+
+bool GizmoToolController::CanMapToRootChunk(PxActor* actor)
+{
+ if (actor)
{
- return;
+ BlastFamily* family = getBlastController().getFamilyByPxActor(*actor);
+ if (family == nullptr)
+ return false;
+
+ const BlastAsset& asset = family->getBlastAsset();
+ uint32_t chunkIndex = family->getChunkIndexByPxActor(*actor);
+
+ std::vector<uint32_t> chunkIndexes;
+ chunkIndexes.push_back(chunkIndex);
+ std::vector<BlastChunkNode*> chunkNodes = BlastTreeData::ins().getChunkNodeByBlastChunk(&asset, chunkIndexes);
+ if (chunkNodes.size() > 0)
+ return BlastTreeData::isRoot(chunkNodes[0]);
}
+ return false;
+}
- std::vector<PxShape*> shapes(shapesCount);
- m_CurrentActor->getShapes(&shapes[0], shapesCount);
-
- getPhysXController().getPhysXScene().removeActor(*m_CurrentActor);
-
- for (uint32_t i = 0; i < shapesCount; i++)
+bool GizmoToolController::CanModifyLocal(PxActor* actor)
+{
+ if (nullptr != actor
+ && !SampleManager::ins()->IsSimulating()
+ && !getBlastController().isAssetFractrued(*actor))
{
- PxShape* shape = shapes[i];
-
- PxConvexMeshGeometry mesh;
- bool valid = shape->getConvexMeshGeometry(mesh);
- if (!valid)
- {
- continue;
- }
+ return true;
+ }
- PxConvexMesh* pMesh = mesh.convexMesh;
- if (NULL == pMesh)
- {
- continue;
- }
+ return false;
+}
- PxU32 numVertex = pMesh->getNbVertices();
- if (numVertex == 0)
- {
- continue;
- }
+void GizmoToolController::UpdateAssetInstanceTransform(const PxTransform& position)
+{
+ if (!m_CurrentActor)
+ return;
- const PxVec3* pVertex = pMesh->getVertices();
- PxVec3* pVertexNew = new PxVec3[numVertex];
- for (PxU32 v = 0; v < numVertex; v++)
- {
- pVertexNew[v] = scale.transform(pVertex[v]);
- }
+ BlastFamily* family = getBlastController().getFamilyByPxActor(*m_CurrentActor);
+ if (family)
+ {
+ BPPAssetInstance* bppInstance = SampleManager::ins()->getInstanceByFamily(family);
- PxConvexMeshDesc convexMeshDesc;
- convexMeshDesc.points.count = numVertex;
- convexMeshDesc.points.data = pVertexNew;
- convexMeshDesc.points.stride = sizeof(PxVec3);
- convexMeshDesc.flags = PxConvexFlag::eCOMPUTE_CONVEX;
- PxPhysics& physics = getManager()->getPhysXController().getPhysics();
- PxCooking& cooking = getManager()->getPhysXController().getCooking();
- PxConvexMesh* convexMesh = cooking.createConvexMesh(convexMeshDesc, physics.getPhysicsInsertionCallback());
- if (NULL == convexMesh)
+ if (bppInstance)
{
- delete[] pVertexNew;
- continue;
- }
+ bppInstance->transform.position = *((nvidia::NvVec3*)(&position.p));
+ bppInstance->transform.rotation = *((nvidia::NvVec4*)(&position.q));
- mesh.convexMesh = convexMesh;
+ family->initTransform(position);
+ // modify corresponding asset's transform, it's need to modify in future
+ {
+ const BlastAsset& asset = family->getBlastAsset();
+ SampleManager* sampleManager = SampleManager::ins();
+ std::map<BlastAsset*, std::vector<BlastFamily*>>& AssetFamiliesMap = sampleManager->getAssetFamiliesMap();
+ std::map<BlastAsset*, AssetList::ModelAsset>& AssetDescMap = sampleManager->getAssetDescMap();
- m_CurrentActor->detachShape(*shape);
- shape->setGeometry(mesh);
- m_CurrentActor->attachShape(*shape);
+ BlastAsset* pBlastAsset = (BlastAsset*)&asset;
- pMesh->release();
- delete[] pVertexNew;
+ AssetList::ModelAsset& m = AssetDescMap[pBlastAsset];
+ m.transform = position;
+ }
+ }
}
+}
- getPhysXController().getPhysXScene().addActor(*m_CurrentActor);
+void GizmoToolController::syncRenderableState()
+{
+ bool depthTest = AppMainWindow::Inst().m_bGizmoWithDepthTest;
+ m_AxisConeRenderable[AT_X]->setDepthTest(depthTest);
+ m_AxisConeRenderable[AT_Y]->setDepthTest(depthTest);
+ m_AxisConeRenderable[AT_Z]->setDepthTest(depthTest);
+ m_AxisBoxRenderable[AT_X]->setDepthTest(depthTest);
+ m_AxisBoxRenderable[AT_Y]->setDepthTest(depthTest);
+ m_AxisBoxRenderable[AT_Z]->setDepthTest(depthTest);
} \ No newline at end of file
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/GizmoToolController.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/GizmoToolController.h
index 215cde5..8586ad3 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/GizmoToolController.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/GizmoToolController.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef GIZMO_TOOL_CONTROLLER_H
#define GIZMO_TOOL_CONTROLLER_H
@@ -14,6 +32,7 @@
#include "SampleManager.h"
#include "DebugRenderBuffer.h"
#include "NvBlastExtPxManager.h"
+#include "BlastSceneTree.h"
class Renderable;
class RenderMaterial;
@@ -26,6 +45,11 @@ class ExtPhysicsActor;
}
}
+namespace physx
+{
+ class PxScene;
+}
+
enum AxisType
{
AT_X = 0,
@@ -41,7 +65,10 @@ enum GizmoToolMode
GTM_Rotation
};
-class GizmoToolController : public ISampleController
+void modifyPxActorByLocalWay(PxScene& pxScene, PxRigidDynamic& actor, PxTransform& gp_old, PxTransform& gp_new);
+void scalePxActor(PxScene& pxScene, PxRigidDynamic& actor, PxMat44& scale);
+
+class GizmoToolController : public ISampleController, public ISceneObserver
{
public:
GizmoToolController();
@@ -55,16 +82,26 @@ public:
virtual void onSampleStart();
virtual void onSampleStop();
+ virtual void dataSelected(std::vector<BlastNode*> selections);
+
void setGizmoToolMode(GizmoToolMode mode);
+ GizmoToolMode getGizmoToolMode() { return m_GizmoToolMode; }
void setAxisSelected(AxisType type);
+ void setAxisLength(float axisLength);
void showAxisRenderables(bool show);
void resetPos();
+ void setTargetActor(PxActor* actor);
+ PxActor* getTargetActor();
+ void syncRenderableState();
+ bool CanMapToRootChunk(PxActor* actor);
private:
GizmoToolController& operator= (GizmoToolController&);
//////// private methods ////////
+ physx::PxScene& GetPhysXScene();
+ void UpdateCircleRenderData(float axisLength);
bool CalPlaneLineIntersectPoint(PxVec3& result, PxVec3 planeNormal, PxVec3 planePoint, PxVec3 linedirection, PxVec3 linePoint);
float DistanceFromPointToLine(PxVec3& point, PxVec3& origin, PxVec3& direction, PxVec3& foot);
bool GetFootFromPointToPlane(PxVec3& point, PxVec3& origin, PxVec3& normal, PxVec3& foot);
@@ -72,6 +109,10 @@ private:
PxQuat CalDirectionQuat(AxisType type);
PxQuat CalConvertQuat();
void ScaleActor(bool replace);
+
+ bool CanModifyLocal(PxActor* actor);
+ void UpdateAssetInstanceTransform(const PxTransform& position);
+
//////// used controllers ////////
Renderer& getRenderer() const
@@ -103,7 +144,7 @@ private:
PxVec3 m_LastFoot;
PxVec3 m_LastAxis[AT_Num];
- PxRigidActor* m_CurrentActor;
+ PxRigidDynamic* m_CurrentActor;
bool m_bNeedResetPos;
bool m_bNeedResetColor;
@@ -119,6 +160,8 @@ private:
std::vector<PxDebugLine> m_CircleRenderData;
DebugRenderBuffer m_CircleRenderBuffer;
+
+ std::vector<BlastAssetInstanceNode*> m_assetInstances;
};
#endif // GIZMO_TOOL_CONTROLLER_H \ No newline at end of file
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/SelectionToolController.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/SelectionToolController.cpp
index 02a511f..458aec3 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/SelectionToolController.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/SelectionToolController.cpp
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#include "SelectionToolController.h"
#include "RenderUtils.h"
@@ -14,6 +32,7 @@
#include "Renderer.h"
#include "PhysXController.h"
#include "SampleProfiler.h"
+#include "GizmoToolController.h"
#include <imgui.h>
@@ -23,7 +42,7 @@
#include "PxRigidDynamic.h"
#include "PxScene.h"
#include "BlastSceneTree.h"
-
+#include "SimpleScene.h"
using namespace Nv::Blast;
using namespace physx;
@@ -39,6 +58,9 @@ using namespace physx;
SelectionToolController::SelectionToolController()
{
m_bRectSelecting = false;
+ m_bSelecting = false;
+
+ BlastSceneTree::ins()->addObserver(this);
}
SelectionToolController::~SelectionToolController()
@@ -58,6 +80,29 @@ void SelectionToolController::onSampleStop()
{
}
+void SelectionToolController::dataSelected(std::vector<BlastNode*> selections)
+{
+ m_actorsSelected.clear();
+
+ BlastController& blastController = getBlastController();
+ std::vector<BlastFamilyPtr>& families = blastController.getFamilies();
+
+ for (BlastFamily* family : families)
+ {
+ std::vector<uint32_t> selectedChunks = family->getSelectedChunks();
+ for (uint32_t chunkIndex : selectedChunks)
+ {
+ PxActor* actor = nullptr;
+ family->getPxActorByChunkIndex(chunkIndex, &actor);
+
+ if (actor)
+ {
+ m_actorsSelected.emplace(actor);
+ }
+ }
+ }
+}
+
void SelectionToolController::Animate(double dt)
{
PROFILER_SCOPED_FUNCTION();
@@ -76,6 +121,10 @@ LRESULT SelectionToolController::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LP
if (uMsg == WM_LBUTTONDOWN || uMsg == WM_RBUTTONDOWN || uMsg == WM_MOUSEMOVE || uMsg == WM_LBUTTONUP || uMsg == WM_RBUTTONUP)
{
float mouseX = (short)LOWORD(lParam) / getRenderer().getScreenWidth();
+ if (!SimpleScene::Inst()->m_pCamera->_lhs)
+ {
+ mouseX = 1 - mouseX;
+ }
float mouseY = (short)HIWORD(lParam) / getRenderer().getScreenHeight();
bool press = uMsg == WM_LBUTTONDOWN;
@@ -89,7 +138,18 @@ LRESULT SelectionToolController::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LP
m_RectSelectSpaceDir = pickDir.getNormalized();
m_RectRenderBuffer.clear();
- m_bRectSelecting = true;
+ bool isCtrl = (GetAsyncKeyState(VK_CONTROL) && 0x8000);
+ bool isAlt = (GetAsyncKeyState(VK_MENU) && 0x8000);
+ bool isLight = (GetAsyncKeyState('L') && 0x8000);
+ // ctrl+leftbutton is used for light changing
+ // alt+leftbutton is used for camera rotate movement in AppMainWindow.cpp
+ // so, we use rect select when ctrl and alt off
+ m_bRectSelecting = !(isAlt || isLight);// !(isCtrl || isAlt);
+ if (isAlt || isLight)
+ {
+ m_RectRenderBuffer.clear();
+ }
+ m_bSelecting = true;
}
else if (uMsg == WM_MOUSEMOVE)
{
@@ -161,8 +221,9 @@ LRESULT SelectionToolController::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LP
{
return 1;
}
-
- if (m_bRectSelecting)
+ bool isAlt = (GetAsyncKeyState(VK_MENU) && 0x8000);
+ bool isLight = (GetAsyncKeyState('L') && 0x8000);
+ if (m_bSelecting && !(isAlt || isLight))
{
bool isShift = (GetAsyncKeyState(VK_SHIFT) && 0x8000);
bool isCtrl = (GetAsyncKeyState(VK_CONTROL) && 0x8000);
@@ -180,15 +241,18 @@ LRESULT SelectionToolController::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LP
{
selectMode = SM_SUB;
}
-
int width = getRenderer().getScreenWidth();
int height = getRenderer().getScreenHeight();
int deltaX = (mouseX - m_RectSelectScreenPos.x) * width;
int deltaY = (mouseY - m_RectSelectScreenPos.y) * height;
float distance = deltaX * deltaX + deltaY * deltaY;
- // rect select mode
- if (distance > 1)
+ if (distance < 1)
+ {
+ m_bRectSelecting = false;
+ }
+ if (m_bRectSelecting)
{
+ // rect select mode
PxVec3 eyePos, pickDir[3];
getPhysXController().getEyePoseAndPickDir(mouseX, mouseY, eyePos, pickDir[0]);
getPhysXController().getEyePoseAndPickDir(m_RectSelectScreenPos.x, mouseY, eyePos, pickDir[1]);
@@ -243,23 +307,35 @@ LRESULT SelectionToolController::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LP
getPhysXController().getEyePoseAndPickDir(mouseX, mouseY, eyePos, pickDir);
pickDir = pickDir.getNormalized();
- PxRaycastHit hit; hit.shape = NULL;
- PxRaycastBuffer hit1;
- getPhysXController().getPhysXScene().raycast(eyePos, pickDir, PX_MAX_F32, hit1, PxHitFlag::ePOSITION | PxHitFlag::eNORMAL);
- hit = hit1.block;
+ PxRaycastBufferN<32> hits;
+
+ GetPhysXScene().raycast(eyePos, pickDir, PX_MAX_F32, hits, PxHitFlag::eDEFAULT | PxHitFlag::eMESH_MULTIPLE);
+
+ PxU32 nbThouches = hits.getNbTouches();
+ const PxRaycastHit* touches = hits.getTouches();
PxRigidActor* actor = NULL;
- if (hit.shape)
+ float fDistance = PX_MAX_F32;
+ for (PxU32 u = 0; u < nbThouches; ++u)
{
- actor = hit.actor;
+ const PxRaycastHit& t = touches[u];
+ if (t.shape && getBlastController().isActorVisible(*(t.actor)))
+ {
+ if (fDistance > t.distance)
+ {
+ fDistance = t.distance;
+ actor = t.actor;
+ }
+ }
}
+
pointSelect(actor, selectMode);
}
}
- BlastSceneTree::ins()->updateChunkItemSelection();
m_RectRenderBuffer.clear();
m_bRectSelecting = false;
+ m_bSelecting = false;
}
}
@@ -272,42 +348,35 @@ void SelectionToolController::drawUI()
void SelectionToolController::pointSelect(PxActor* actor, SelectMode selectMode)
{
- ExtPxActor* extActor = NULL;
- if (NULL != actor)
- {
- PxRigidDynamic* rigidDynamic = actor->is<PxRigidDynamic>();
- if (NULL != rigidDynamic)
- {
- extActor = getBlastController().getExtPxManager().getActorFromPhysXActor(*rigidDynamic);
- }
- }
-
if (selectMode == SM_RESET)
{
clearSelect();
- if (NULL != extActor)
+ if (NULL != actor)
{
- setActorSelected(*extActor, true);
- m_actorsSelected.emplace(extActor);
+ setActorSelected(*actor, true);
+ m_actorsSelected.emplace(actor);
}
}
else if (selectMode == SM_ADD)
{
- if (NULL != extActor)
+ if (NULL != actor)
{
- setActorSelected(*extActor, true);
- m_actorsSelected.emplace(extActor);
+ setActorSelected(*actor, true);
+ m_actorsSelected.emplace(actor);
}
}
else if (selectMode == SM_SUB)
{
- if (NULL != extActor)
+ if (NULL != actor)
{
- setActorSelected(*extActor, false);
- m_actorsSelected.erase(extActor);
+ setActorSelected(*actor, false);
+ m_actorsSelected.erase(actor);
}
}
+
+ BlastSceneTree::ins()->updateChunkItemSelection();
+ trySelectAssetInstanceNode(m_actorsSelected);
}
#include "PxPhysics.h"
@@ -316,8 +385,8 @@ void SelectionToolController::pointSelect(PxActor* actor, SelectMode selectMode)
class RectSelectionCallback : public PxOverlapCallback
{
public:
- RectSelectionCallback(ExtPxManager& physicsManager, std::set<ExtPxActor*>& actorBuffer)
- : m_physicsManager(physicsManager), m_actorBuffer(actorBuffer), PxOverlapCallback(m_hitBuffer, sizeof(m_hitBuffer) / sizeof(m_hitBuffer[0])) {}
+ RectSelectionCallback(std::set<PxActor*>& actorBuffer)
+ :m_actorBuffer(actorBuffer), PxOverlapCallback(m_hitBuffer, sizeof(m_hitBuffer) / sizeof(m_hitBuffer[0])) {}
PxAgain processTouches(const PxOverlapHit* buffer, PxU32 nbHits)
{
@@ -326,25 +395,20 @@ public:
PxRigidDynamic* rigidDynamic = buffer[i].actor->is<PxRigidDynamic>();
if (rigidDynamic)
{
- ExtPxActor* actor = m_physicsManager.getActorFromPhysXActor(*rigidDynamic);
- if (actor != nullptr)
- {
- m_actorBuffer.insert(actor);
- }
+ m_actorBuffer.insert(rigidDynamic);
}
}
return true;
}
private:
- ExtPxManager& m_physicsManager;
- std::set<ExtPxActor*>& m_actorBuffer;
- PxOverlapHit m_hitBuffer[1000];
+ std::set<PxActor*>& m_actorBuffer;
+ PxOverlapHit m_hitBuffer[1000];
};
void SelectionToolController::rectSelect(PxVec3 eyePos, PxVec3 lefttop, PxVec3 leftbottom, PxVec3 righttop, PxVec3 rightbottom, SelectMode selectMode)
{
- std::set<ExtPxActor*> actorsToSelect;
+ std::set<PxActor*> actorsToSelect;
float nearClip = 1;
PxVec3 nearlefttop = lefttop * nearClip;
@@ -373,8 +437,8 @@ void SelectionToolController::rectSelect(PxVec3 eyePos, PxVec3 lefttop, PxVec3 l
PxConvexMesh* convexMesh = cooking.createConvexMesh(convexMeshDesc, physics.getPhysicsInsertionCallback());
if (NULL != convexMesh)
{
- RectSelectionCallback overlapCallback(getBlastController().getExtPxManager(), actorsToSelect);
- getManager()->getPhysXController().getPhysXScene().overlap(PxConvexMeshGeometry(convexMesh), PxTransform(eyePos), overlapCallback);
+ RectSelectionCallback overlapCallback(actorsToSelect);
+ GetPhysXScene().overlap(PxConvexMeshGeometry(convexMesh), PxTransform(eyePos), overlapCallback);
convexMesh->release();
}
@@ -382,33 +446,42 @@ void SelectionToolController::rectSelect(PxVec3 eyePos, PxVec3 lefttop, PxVec3 l
{
clearSelect();
- for (ExtPxActor* actor : actorsToSelect)
+ for (PxActor* actor : actorsToSelect)
{
- setActorSelected(*actor, true);
- m_actorsSelected.emplace(actor);
+ if (getBlastController().isActorVisible(*actor))
+ {
+ setActorSelected(*actor, true);
+ m_actorsSelected.emplace(actor);
+ }
}
}
else if (selectMode == SM_ADD)
{
- for (ExtPxActor* actor : actorsToSelect)
+ for (PxActor* actor : actorsToSelect)
{
- setActorSelected(*actor, true);
- m_actorsSelected.emplace(actor);
+ if (getBlastController().isActorVisible(*actor))
+ {
+ setActorSelected(*actor, true);
+ m_actorsSelected.emplace(actor);
+ }
}
}
else if (selectMode == SM_SUB)
{
- for (ExtPxActor* actor : actorsToSelect)
+ for (PxActor* actor : actorsToSelect)
{
setActorSelected(*actor, false);
m_actorsSelected.erase(actor);
}
}
+
+ BlastSceneTree::ins()->updateChunkItemSelection();
+ trySelectAssetInstanceNode(m_actorsSelected);
}
void SelectionToolController::clearSelect()
{
- for (ExtPxActor* actor : m_actorsSelected)
+ for (PxActor* actor : m_actorsSelected)
{
setActorSelected(*actor, false);
}
@@ -417,7 +490,75 @@ void SelectionToolController::clearSelect()
SampleManager::ins()->clearChunksSelected();
}
-void SelectionToolController::setActorSelected(const ExtPxActor& actor, bool selected)
+void SelectionToolController::setTargetActor(PxActor* actor)
+{
+ if (actor == nullptr)
+ {
+ return;
+ }
+
+ setActorSelected(*actor, true);
+ m_actorsSelected.emplace(actor);
+
+ BlastSceneTree::ins()->updateChunkItemSelection();
+ trySelectAssetInstanceNode(m_actorsSelected);
+}
+
+PxActor* SelectionToolController::getTargetActor()
+{
+ PxActor* targetActor = nullptr;
+ if (m_actorsSelected.size() > 0)
+ {
+ targetActor = *m_actorsSelected.begin();
+ }
+ return targetActor;
+}
+
+void SelectionToolController::setTargetActors(std::set<PxActor*>& actors)
+{
+ for (PxActor* actor : actors)
+ {
+ setActorSelected(*actor, true);
+ m_actorsSelected.emplace(actor);
+ }
+
+ BlastSceneTree::ins()->updateChunkItemSelection();
+ trySelectAssetInstanceNode(m_actorsSelected);
+}
+
+std::set<PxActor*> SelectionToolController::getTargetActors()
+{
+ return m_actorsSelected;
+}
+
+void SelectionToolController::trySelectAssetInstanceNode(std::set<PxActor*>& selectedActors)
+{
+ BlastController& blastController = getBlastController();
+ GizmoToolController& gizmoToolController = getManager()->getGizmoToolController();
+
+ for (PxActor* actor : selectedActors)
+ {
+ if (gizmoToolController.CanMapToRootChunk(actor))
+ {
+ BlastFamily* family = getBlastController().getFamilyByPxActor(*actor);
+ BlastSceneTree::ins()->selectTreeItem(family);
+ }
+ }
+}
+
+physx::PxScene& SelectionToolController::GetPhysXScene()
+{
+ if (getManager()->IsSimulating())
+ {
+ return getPhysXController().getPhysXScene();
+ }
+ else
+ {
+ return getPhysXController().getEditPhysXScene();
+ }
+}
+
+void SelectionToolController::setActorSelected(const PxActor& actor, bool selected)
{
std::vector<BlastFamilyPtr>& families = getBlastController().getFamilies();
if (families.size() == 0)
@@ -430,7 +571,7 @@ void SelectionToolController::setActorSelected(const ExtPxActor& actor, bool sel
for (; it != families.end(); it++)
{
BlastFamilyPtr f = *it;
- if (f->find((ExtPxActor*)&actor))
+ if (f->find(actor))
{
pBlastFamily = f;
break;
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/SelectionToolController.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/SelectionToolController.h
index 5261b90..74220e7 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/SelectionToolController.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/ui/SelectionToolController.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef SELECTION_TOOL_CONTROLLER_H
#define SELECTION_TOOL_CONTROLLER_H
@@ -17,6 +35,8 @@
#include "DebugRenderBuffer.h"
#include "BlastFamily.h"
#include "NvBlastExtPxManager.h"
+#include "BlastSceneTree.h"
+
class Renderable;
class RenderMaterial;
@@ -28,7 +48,12 @@ class ExtPxActor;
}
}
-class SelectionToolController : public ISampleController
+namespace physx
+{
+ class PxScene;
+}
+
+class SelectionToolController : public ISampleController, public ISceneObserver
{
public:
SelectionToolController();
@@ -42,15 +67,27 @@ public:
virtual void onSampleStart();
virtual void onSampleStop();
+ virtual void dataSelected(std::vector<BlastNode*> selections);
+
void pointSelect(PxActor* actor, SelectMode selectMode = SM_RESET);
void rectSelect(PxVec3 eyePos, PxVec3 lefttop, PxVec3 leftbottom, PxVec3 righttop, PxVec3 rightbottom, SelectMode selectMode = SM_RESET);
void clearSelect();
+ void setTargetActor(PxActor* actor);
+ PxActor* getTargetActor();
+
+ void setTargetActors(std::set<PxActor*>& actors);
+ std::set<PxActor*> getTargetActors();
+
+ void trySelectAssetInstanceNode(std::set<PxActor*>& selectedActors);
+
private:
SelectionToolController& operator= (SelectionToolController&);
//////// private methods ////////
+ physx::PxScene& GetPhysXScene();
+
//////// used controllers ////////
Renderer& getRenderer() const
@@ -73,10 +110,11 @@ private:
PxVec2 m_RectSelectScreenPos;
PxVec3 m_RectSelectSpaceDir;
bool m_bRectSelecting;
+ bool m_bSelecting;
DebugRenderBuffer m_RectRenderBuffer;
- void setActorSelected(const ExtPxActor& actor, bool selected);
- std::set<ExtPxActor*> m_actorsSelected;
+ void setActorSelected(const PxActor& actor, bool selected);
+ std::set<PxActor*> m_actorsSelected;
};
#endif // SELECTION_TOOL_CONTROLLER_H \ No newline at end of file
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/PxInputDataFromPxFileBuf.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/PxInputDataFromPxFileBuf.h
index dfa8260..e309abd 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/PxInputDataFromPxFileBuf.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/PxInputDataFromPxFileBuf.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef PXINPUTDATAFROMPXFILEBUF_H
#define PXINPUTDATAFROMPXFILEBUF_H
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/SampleProfiler.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/SampleProfiler.cpp
index 4df23fd..cb63eeb 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/SampleProfiler.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/SampleProfiler.cpp
@@ -1,12 +1,29 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
#include "SampleProfiler.h"
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/SampleProfiler.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/SampleProfiler.h
index 1ea3663..5f8a326 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/SampleProfiler.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/SampleProfiler.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef SAMPLEPROFILER_H
#define SAMPLEPROFILER_H
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/SampleTime.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/SampleTime.h
index c62ced2..8226cd4 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/SampleTime.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/SampleTime.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef SAMPLE_TIME_H
#define SAMPLE_TIME_H
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/UIHelpers.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/UIHelpers.h
index b23eb84..cdd50ff 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/UIHelpers.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/UIHelpers.h
@@ -1,12 +1,30 @@
-/*
-* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
-*
-* NVIDIA CORPORATION and its licensors retain all intellectual property
-* and proprietary rights in and to this software, 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.
-*/
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
#ifndef UI_HELPERS_H
#define UI_HELPERS_H
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/Utils.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/Utils.cpp
index a271137..9eafabc 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/Utils.cpp
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/Utils.cpp
@@ -1,3 +1,31 @@
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
+
#include "Utils.h"
#include <string>
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/Utils.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/Utils.h
index 5d4addc..42bf713 100644
--- a/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/Utils.h
+++ b/tools/ArtistTools/source/BlastPlugin/SampleBase/utils/Utils.h
@@ -1,3 +1,31 @@
+// 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-2017 NVIDIA Corporation. All rights reserved.
+
+
#ifndef UTILS_H
#define UTILS_H