diff options
Diffstat (limited to 'tools/ArtistTools/source/BlastPlugin/SampleBase/blast')
26 files changed, 0 insertions, 5470 deletions
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAsset.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAsset.cpp deleted file mode 100644 index 7bb4f95..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAsset.cpp +++ /dev/null @@ -1,166 +0,0 @@ -// 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 - -std::set<int> ExistingAssetIds; -BlastAsset::BlastAsset(Renderer& renderer) - : m_renderer(renderer), m_bondHealthMax(1.0f), m_supportChunkHealthMax(1.0f) -{ - for (int id = 0; ; id++) - { - if (ExistingAssetIds.find(id) == ExistingAssetIds.end()) - { - ExistingAssetIds.emplace(id); - mUniqueId = id; - break; - } - } -} - -BlastAsset::~BlastAsset() -{ - ExistingAssetIds.erase(mUniqueId); -} - -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 -{ - return m_pxAsset->getTkAsset().getDataSize(); -} - -std::vector<uint32_t> BlastAsset::getChunkIndexesByDepth(uint32_t depth) const -{ - const TkAsset& tkAsset = m_pxAsset->getTkAsset(); - const NvBlastChunk* pNvBlastChunk = tkAsset.getChunks(); - uint32_t chunkCount = tkAsset.getChunkCount(); - - std::map<uint32_t, uint32_t> indexDepthMap; - indexDepthMap.insert(std::make_pair(0, 0)); - for (size_t i = 1; i < chunkCount; ++i) - { - int depth = 0; - const NvBlastChunk* curChunk = pNvBlastChunk + i; - while (-1 != curChunk->parentChunkIndex) - { - ++depth; - curChunk = pNvBlastChunk + curChunk->parentChunkIndex; - } - indexDepthMap.insert(std::make_pair(i, depth)); - } - - std::vector<uint32_t> indexes; - for (std::map<uint32_t, uint32_t>::iterator itr = indexDepthMap.begin(); itr != indexDepthMap.end(); ++itr) - { - if (itr->second == depth) - { - indexes.push_back(itr->first); - } - } - - return indexes; -} diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAsset.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAsset.h deleted file mode 100644 index feec9e3..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAsset.h +++ /dev/null @@ -1,132 +0,0 @@ -// 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 - -#include <memory> -#include <vector> -#include "PxTransform.h" -#include "NvBlastTypes.h" - - -using namespace physx; - -class Renderer; -class BlastFamily; -class PhysXController; - -namespace Nv -{ -namespace Blast -{ -class ExtPxFamily; -class ExtPxAsset; -class ExtPxManager; -class TkGroup; -} -} - -using namespace Nv::Blast; - -// Add By Lixu Begin -typedef BlastFamily* BlastFamilyPtr; -// Add By Lixu End - - -class BlastAsset -{ -public: - //////// ctor //////// - - BlastAsset(Renderer& renderer); - virtual ~BlastAsset(); - int mUniqueId; - - - //////// desc //////// - - /** - Descriptor with actor initial settings. - */ - struct ActorDesc - { - NvBlastID id; - PxTransform transform; - TkGroup* group; - }; - - - //////// abstract //////// - - virtual BlastFamilyPtr createFamily(PhysXController& physXConroller, ExtPxManager& pxManager, const ActorDesc& desc) = 0; - - - //////// data getters //////// - - const ExtPxAsset* getPxAsset() const - { - return m_pxAsset; - } - - 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 //////// - - - - //////// input data //////// - - Renderer& m_renderer; - - - //////// internal data //////// - - ExtPxAsset* m_pxAsset; - float m_bondHealthMax; - float m_supportChunkHealthMax; -}; - - - -#endif //BLAST_ASSET_H
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetBoxes.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetBoxes.cpp deleted file mode 100644 index 4bd9766..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetBoxes.cpp +++ /dev/null @@ -1,102 +0,0 @@ -// 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" -#include "NvBlastExtPxAsset.h" -#include "PxPhysics.h" -#include "cooking/PxCooking.h" - - -BlastAssetBoxes::BlastAssetBoxes(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, Renderer& renderer, const Desc& desc) - : BlastAsset(renderer) -{ - // generate boxes slices procedurally - CubeAssetGenerator::generate(m_generatorAsset, desc.generatorSettings); - - // asset desc / tk asset - ExtPxAssetDesc assetDesc; - assetDesc.chunkDescs = m_generatorAsset.solverChunks.data(); - assetDesc.chunkCount = (uint32_t)m_generatorAsset.solverChunks.size(); - assetDesc.bondDescs = m_generatorAsset.solverBonds.data(); - assetDesc.bondCount = (uint32_t)m_generatorAsset.solverBonds.size(); - std::vector<uint8_t> bondFlags(assetDesc.bondCount); - std::fill(bondFlags.begin(), bondFlags.end(), desc.jointAllBonds ? 1 : 0); - assetDesc.bondFlags = bondFlags.data(); - - // box convex - PxVec3 vertices[8] = { { -1, -1, -1 }, { -1, -1, 1 }, { -1, 1, -1 }, { -1, 1, 1 }, { 1, -1, -1 }, { 1, -1, 1 }, { 1, 1, -1 }, { 1, 1, 1 } }; - PxConvexMeshDesc convexMeshDesc; - convexMeshDesc.points.count = 8; - convexMeshDesc.points.data = vertices; - convexMeshDesc.points.stride = sizeof(PxVec3); - convexMeshDesc.flags = PxConvexFlag::eCOMPUTE_CONVEX; - m_boxMesh = cooking.createConvexMesh(convexMeshDesc, physics.getPhysicsInsertionCallback()); - - // prepare chunks - const uint32_t chunkCount = (uint32_t)m_generatorAsset.solverChunks.size(); - std::vector<ExtPxAssetDesc::ChunkDesc> pxChunks(chunkCount); - std::vector<ExtPxAssetDesc::SubchunkDesc> pxSubchunks; - pxSubchunks.reserve(chunkCount); - for (uint32_t i = 0; i < m_generatorAsset.solverChunks.size(); i++) - { - uint32_t chunkID = m_generatorAsset.solverChunks[i].userData; - GeneratorAsset::BlastChunkCube& cube = m_generatorAsset.chunks[chunkID]; - PxVec3 position = *reinterpret_cast<PxVec3*>(&cube.position); - PxVec3 extents = *reinterpret_cast<PxVec3*>(&cube.extents); - ExtPxAssetDesc::ChunkDesc& chunk = pxChunks[chunkID]; - ExtPxAssetDesc::SubchunkDesc subchunk = - { - PxTransform(position), - PxConvexMeshGeometry(m_boxMesh, PxMeshScale(extents / 2)) - }; - pxSubchunks.push_back(subchunk); - chunk.subchunks = &pxSubchunks.back(); - chunk.subchunkCount = 1; - chunk.isStatic = (position.y - (extents.y - desc.generatorSettings.extents.y) / 2) <= desc.staticHeight; - } - - // create asset - assetDesc.pxChunks = pxChunks.data(); - m_pxAsset = ExtPxAsset::create(assetDesc, framework); - - initialize(); -} - - -BlastAssetBoxes::~BlastAssetBoxes() -{ - m_boxMesh->release(); - m_pxAsset->release(); -} - - -BlastFamilyPtr BlastAssetBoxes::createFamily(PhysXController& physXConroller, ExtPxManager& pxManager, const ActorDesc& desc) -{ - return BlastFamilyPtr(new BlastFamilyBoxes(physXConroller, pxManager, m_renderer, *this, desc)); -} diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetBoxes.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetBoxes.h deleted file mode 100644 index d4f8dd2..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetBoxes.h +++ /dev/null @@ -1,74 +0,0 @@ -// 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 - -#include "BlastAsset.h" -#include "AssetGenerator.h" -#include "PxConvexMesh.h" - - -namespace physx -{ -class PxPhysics; -class PxCooking; -} - -namespace Nv -{ -namespace Blast -{ -class TkFramework; -} -} - - -class BlastAssetBoxes : public BlastAsset -{ -public: - struct Desc - { - CubeAssetGenerator::Settings generatorSettings; - float staticHeight; - bool jointAllBonds; - }; - - BlastAssetBoxes(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, Renderer& renderer, const Desc& desc); - virtual ~BlastAssetBoxes(); - - BlastFamilyPtr createFamily(PhysXController& physXConroller, ExtPxManager& pxManager, const ActorDesc& desc); - -private: - PxConvexMesh* m_boxMesh; - GeneratorAsset m_generatorAsset; -}; - - - -#endif //BLAST_ASSET_BOXES_H
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModel.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModel.cpp deleted file mode 100644 index 857cb9b..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModel.cpp +++ /dev/null @@ -1,252 +0,0 @@ -// 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 "ResourceManager.h" -#include "NvBlastExtPxAsset.h" -#include <sstream> -#include <fstream> -#include "NvBlastExtExporter.h" -#include "PxPhysics.h" -#include <NvBlastGlobals.h> -#include "NvBlastExtAssetUtils.h" -#include "NvBlastExtPxAsset.h" -#include "NvBlastTkAsset.h" -#include "NvBlastExtSerialization.h" -#include "NvBlastExtLlSerialization.h" -#include "NvBlastExtTkSerialization.h" -#include "NvBlastExtPxSerialization.h" -#include "NvBlastExtAuthoring.h" -#include "NvBlastExtAuthoringCollisionBuilder.h" - -BlastAssetModel::BlastAssetModel(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName, const char* modelPath) - : BlastAsset(renderer) -{ - if (modelPath == NULL) - { - GlobalSettings& globalSettings = GlobalSettings::Inst(); - modelPath = globalSettings.m_projectFileDir.c_str(); - assert(globalSettings.m_projectFileDir.length() > 0); - } - - const float unitConversion = 1.f; - - const NvcVec3 inputScale = { unitConversion, unitConversion, unitConversion }; - - std::string path; - - // load obj file - 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"); - } - } - - for (auto& chunk : m_model->chunks) - { - for (auto& mesh : chunk.meshes) - { - SimpleMesh& smesh = const_cast<SimpleMesh&>(mesh.mesh); - smesh.center *= unitConversion; - smesh.extents *= unitConversion; - for (auto& vertex : smesh.vertices) - { - vertex.position *= unitConversion; - } - } - } - - // Physics Asset - - // Read file into buffer - std::ostringstream blastFileName; - blastFileName << modelName << ".blast"; - 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())) - { - std::shared_ptr<IFbxFileReader> rdr(NvBlastExtExporterCreateFbxFileReader(), [](IFbxFileReader* p) {p->release(); }); - rdr->loadFromFile(path.c_str()); - if (rdr->isCollisionLoaded() == 0) - { - ASSERT_PRINT(false, "fbx doesn't contain collision geometry"); - } - uint32_t* hullsOffsets = nullptr; - CollisionHull** hulls = nullptr; - uint32_t meshCount = rdr->getCollision(hullsOffsets, hulls); - - /** - Create physics meshes; - */ - std::shared_ptr<Nv::Blast::ConvexMeshBuilder> collisionBuilder( - NvBlastExtAuthoringCreateConvexMeshBuilder(&cooking, &physics.getPhysicsInsertionCallback()), - [](Nv::Blast::ConvexMeshBuilder* cmb) {cmb->release(); }); - - physicsChunks.resize(meshCount); - physicsSubchunks.resize(meshCount); - - for (uint32_t i = 0; i < meshCount; ++i) - { - for (uint32_t sbHulls = hullsOffsets[i]; sbHulls < hullsOffsets[i+1]; ++sbHulls) - { - PxConvexMeshGeometry temp = physx::PxConvexMeshGeometry(collisionBuilder.get()->buildConvexMesh(*hulls[sbHulls])); - if (temp.isValid()) - { - physicsSubchunks[i].push_back(ExtPxAssetDesc::SubchunkDesc()); - physicsSubchunks[i].back().geometry = temp; - physicsSubchunks[i].back().transform = physx::PxTransform(physx::PxIdentity); - } - } - } - for (uint32_t i = 0; i < meshCount; ++i) - { - physicsChunks[i].isStatic = false; - physicsChunks[i].subchunkCount = (uint32_t)physicsSubchunks[i].size(); - physicsChunks[i].subchunks = physicsSubchunks[i].data(); - } - if (hullsOffsets) - { - NVBLAST_FREE(hullsOffsets); - } - if (hulls) - { - NVBLAST_FREE(hulls); - } - } - 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() -{ - m_pxAsset->release(); -} diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModel.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModel.h deleted file mode 100644 index 9e13674..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModel.h +++ /dev/null @@ -1,77 +0,0 @@ -// 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 - -#include "BlastAsset.h" -#include "BlastModel.h" - - -namespace physx -{ -class PxPhysics; -class PxCooking; -} - -namespace Nv -{ -namespace Blast -{ -class TkFramework; -class ExtSerialization; -} -} - - -class BlastAssetModel : public BlastAsset -{ -public: - //////// ctor //////// - - BlastAssetModel(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName, const char* modelPath = NULL); - BlastAssetModel(ExtPxAsset* pExtPxAsset, BlastModel* pBlastModel, Renderer& renderer); - virtual ~BlastAssetModel(); - - - //////// data getters //////// - - const BlastModel& getModel() const - { -// Add By Lixu Begin - return *m_model; -// Add By Lixu End - } - -private: - //////// private internal data //////// - - BlastModelPtr m_model; -}; - -#endif //BLAST_ASSET_MODEL_H
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSimple.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSimple.cpp deleted file mode 100644 index c3db31d..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSimple.cpp +++ /dev/null @@ -1,74 +0,0 @@ -// 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" -#include "BlastFamilyModelSimple.h" -#include "CustomRenderMesh.h" -#include "Renderer.h" - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// BlastAssetModelSimple -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -BlastAssetModelSimple::BlastAssetModelSimple(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName) - : BlastAssetModel(framework, physics, cooking, serialization, renderer, modelName) -{ - _init(renderer); -} - -BlastAssetModelSimple::BlastAssetModelSimple(ExtPxAsset* pExtPxAsset, BlastModel* pBlastModel, Renderer& renderer) - : BlastAssetModel(pExtPxAsset, pBlastModel, renderer) -{ - _init(renderer); -} - -BlastAssetModelSimple::~BlastAssetModelSimple() -{ - m_renderMaterialNames.clear(); -} - -void BlastAssetModelSimple::_init(Renderer& renderer) -{ - for (const BlastModel::Material& material : getModel().materials) - { - std::string name = material.name; - if (name != "" && !BlastProject::ins().isGraphicsMaterialNameExist(name.c_str())) - { - 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); - } - 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 deleted file mode 100644 index ca3d995..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSimple.h +++ /dev/null @@ -1,66 +0,0 @@ -// 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 - -#include "BlastAssetModel.h" - - - -class BlastAssetModelSimple : public BlastAssetModel -{ -public: - //////// ctor //////// - - BlastAssetModelSimple(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName); - BlastAssetModelSimple(ExtPxAsset* pExtPxAsset, BlastModel* pBlastModel, Renderer& renderer); - virtual ~BlastAssetModelSimple(); - - - //////// interface implementation //////// - - virtual BlastFamilyPtr createFamily(PhysXController& physXConroller, ExtPxManager& pxManager, const ActorDesc& desc); - - - //////// data getters //////// - - const std::vector<std::string>& getRenderMaterials() const - { - return m_renderMaterialNames; - } - - -private: - //////// private internal data //////// - void _init(Renderer& renderer); - - 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 deleted file mode 100644 index 747c2f4..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSkinned.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// 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" -#include "RenderMaterial.h" -#include "Renderer.h" - - -BlastAssetModelSkinned::BlastAssetModelSkinned(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName) - : BlastAssetModel(framework, physics, cooking, serialization, renderer, modelName) -{ -// Add By Lixu Begin - int index = 0; - char materialName[50]; - for (const BlastModel::Material& material : getModel().materials) - { - sprintf(materialName, "%s_Material%d", modelName, index++); - - if (material.diffuseTexture.empty()) - m_renderMaterials.push_back(new RenderMaterial(modelName, renderer.getResourceManager(), "model_skinned")); - else - m_renderMaterials.push_back(new RenderMaterial(modelName, renderer.getResourceManager(), "model_skinned_textured", material.diffuseTexture.c_str())); - } -// Add By Lixu End - initialize(); -} - -BlastAssetModelSkinned::~BlastAssetModelSkinned() -{ - for (RenderMaterial* r : m_renderMaterials) - { - SAFE_DELETE(r); - } -} - -BlastFamilyPtr BlastAssetModelSkinned::createFamily(PhysXController& physXConroller, ExtPxManager& pxManager, const ActorDesc& desc) -{ - return BlastFamilyPtr(new BlastFamilyModelSkinned(physXConroller, pxManager, m_renderer, *this, desc)); -} diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSkinned.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSkinned.h deleted file mode 100644 index e9c6784..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastAssetModelSkinned.h +++ /dev/null @@ -1,64 +0,0 @@ -// 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 - -#include "BlastAssetModel.h" - -class RenderMaterial; - -class BlastAssetModelSkinned : public BlastAssetModel -{ -public: - //////// ctor //////// - - BlastAssetModelSkinned(TkFramework& framework, PxPhysics& physics, PxCooking& cooking, ExtSerialization& serialization, Renderer& renderer, const char* modelName); - virtual ~BlastAssetModelSkinned(); - - - //////// interface implementation //////// - - BlastFamilyPtr createFamily(PhysXController& physXConroller, ExtPxManager& pxManager, const ActorDesc& desc); - - - //////// public getter //////// - - const std::vector<RenderMaterial*>& getRenderMaterials() const - { - return m_renderMaterials; - } - - -private: - //////// internal data //////// - - std::vector<RenderMaterial*> m_renderMaterials; -}; - -#endif //BLAST_ASSET_MODEL_SKINNED_H
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastController.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastController.cpp deleted file mode 100644 index 950b217..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastController.cpp +++ /dev/null @@ -1,611 +0,0 @@ -// 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" -#include "BlastAsset.h" -#include "BlastReplay.h" -#include "PhysXController.h" -#include "SampleTime.h" -#include "SampleProfiler.h" -#include "Utils.h" -#include "Renderer.h" - -#include "NvBlastExtPxTask.h" - -#include "NvBlast.h" -#include "NvBlastPxCallbacks.h" -#include "NvBlastExtPxManager.h" -#include "NvBlastExtPxFamily.h" -#include "NvBlastExtPxActor.h" -#include "NvBlastExtSerialization.h" -#include "NvBlastExtTkSerialization.h" -#include "NvBlastExtPxSerialization.h" - -#include "NvBlastTkFramework.h" - -#include "PsString.h" -#include "PxTaskManager.h" -#include "PxDefaultCpuDispatcher.h" -#include "PxRigidBody.h" -#include "PxScene.h" -#include "PxRigidDynamic.h" -#include "PxDistanceJoint.h" - -#include <sstream> -#include <numeric> -#include <cstdlib> - -#include "imgui.h" - -// Add By Lixu Begin -#include "BlastSceneTree.h" -// Add By Lixu End - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Joint creation -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -static physx::PxJoint* createPxJointCallback(ExtPxActor* actor0, const physx::PxTransform& localFrame0, ExtPxActor* actor1, const physx::PxTransform& localFrame1, physx::PxPhysics& physics, TkJoint& joint) -{ - PxDistanceJoint* pxJoint = PxDistanceJointCreate(physics, actor0 ? &actor0->getPhysXActor() : nullptr, localFrame0, actor1 ? &actor1->getPhysXActor() : nullptr, localFrame1); - pxJoint->setMaxDistance(1.0f); - return pxJoint; -} - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Controller -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -BlastController::BlastController() -: m_eventCallback(nullptr), debugRenderMode(BlastFamily::DEBUG_RENDER_DISABLED), m_impactDamageEnabled(true), -m_impactDamageToStressEnabled(false), m_rigidBodyLimitEnabled(true), m_rigidBodyLimit(40000), m_blastAssetsSize(0), debugRenderScale(0.01f), -m_taskManager(nullptr), m_extGroupTaskManager(nullptr) -{ - m_impactDamageToStressFactor = 0.01f; - m_draggingToStressFactor = 100.0f; -} - - -BlastController::~BlastController() -{ -} - -void BlastController::reinitialize() -{ - onSampleStop(); - onSampleStart(); -} - -void BlastController::onSampleStart() -{ - m_tkFramework = NvBlastTkFrameworkCreate(); - - m_replay = new BlastReplay(); - - m_taskManager = PxTaskManager::createTaskManager(NvBlastGetPxErrorCallback(), getPhysXController().getCPUDispatcher(), 0); - - TkGroupDesc gdesc; - gdesc.workerCount = m_taskManager->getCpuDispatcher()->getWorkerCount(); - m_tkGroup = m_tkFramework->createGroup(gdesc); - - m_extPxManager = ExtPxManager::create(getPhysXController().getPhysics(), *m_tkFramework, createPxJointCallback); - m_extPxManager->setActorCountLimit(m_rigidBodyLimitEnabled ? m_rigidBodyLimit : 0); - m_extImpactDamageManager = ExtImpactDamageManager::create(m_extPxManager, m_extImpactDamageManagerSettings); - m_eventCallback = new EventCallback(m_extImpactDamageManager); - - m_extGroupTaskManager = ExtGroupTaskManager::create(*m_taskManager); - m_extGroupTaskManager->setGroup(m_tkGroup); - - setImpactDamageEnabled(m_impactDamageEnabled, true); - - m_extSerialization = NvBlastExtSerializationCreate(); - if (m_extSerialization != nullptr) - { - NvBlastExtTkSerializerLoadSet(*m_tkFramework, *m_extSerialization); - NvBlastExtPxSerializerLoadSet(*m_tkFramework, getPhysXController().getPhysics(), getPhysXController().getCooking(), *m_extSerialization); - } -} - - -void BlastController::onSampleStop() -{ - getPhysXController().simualtionSyncEnd(); - - removeAllFamilies(); - - m_extImpactDamageManager->release(); - m_extPxManager->release(); - SAFE_DELETE(m_eventCallback); - - m_tkGroup->release(); - - delete m_replay; - - m_tkFramework->release(); - - if (m_extGroupTaskManager != nullptr) - { - m_extGroupTaskManager->release(); - m_extGroupTaskManager = nullptr; - } - - if (m_taskManager != nullptr) - { - m_taskManager->release(); - } -} - - -void BlastController::notifyPhysXControllerRelease() -{ - if (m_extGroupTaskManager != nullptr) - { - m_extGroupTaskManager->release(); - m_extGroupTaskManager = nullptr; - } - - if (m_taskManager != nullptr) - { - m_taskManager->release(); - m_taskManager = nullptr; - } -} - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Impact damage -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -void BlastController::updateImpactDamage() -{ - if (m_impactDamageUpdatePending) - { - getPhysXController().getPhysXScene().setSimulationEventCallback(m_impactDamageEnabled ? m_eventCallback : nullptr); - refreshImpactDamageSettings(); - m_impactDamageUpdatePending = false; - } -} - -void BlastController::setImpactDamageEnabled(bool enabled, bool forceUpdate) -{ - if (m_impactDamageEnabled != enabled || forceUpdate) - { - m_impactDamageEnabled = enabled; - m_impactDamageUpdatePending = true; - } -} - -bool BlastController::customImpactDamageFunction(void* data, ExtPxActor* actor, physx::PxShape* shape, physx::PxVec3 position, physx::PxVec3 force) -{ - return reinterpret_cast<BlastController*>(data)->stressDamage(actor, position, force); -} - -bool BlastController::stressDamage(ExtPxActor *actor, physx::PxVec3 position, physx::PxVec3 force) -{ - if (actor->getTkActor().getGraphNodeCount() > 1) - { - void* userData = actor->getFamily().userData; - if (userData) - { - ExtPxStressSolver* solver = reinterpret_cast<ExtPxStressSolver*>(userData); - solver->getSolver().addForce(*actor->getTkActor().getActorLL(), position, force * m_impactDamageToStressFactor); - return true; - } - } - - return false; -} - -void BlastController::refreshImpactDamageSettings() -{ - m_extImpactDamageManagerSettings.damageFunction = m_impactDamageToStressEnabled ? customImpactDamageFunction : nullptr; - m_extImpactDamageManagerSettings.damageFunctionData = this; - m_extImpactDamageManager->setSettings(m_extImpactDamageManagerSettings); -} - -// Add By Lixu Begin -BlastFamily* BlastController::getFamilyByPxActor(const PxActor& actor) -{ - for (BlastFamilyPtr family : m_families) - { - if (family->find(actor)) - { - return family; - } - } - return nullptr; -} - -BlastFamily* BlastController::getFamilyById(int familyId) -{ - BlastFamily* pBlastFamily = nullptr; - for (BlastFamilyPtr p : m_families) - { - if (p->mUniqueId == familyId) - { - pBlastFamily = p; - break; - } - } - return pBlastFamily; -} - -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 -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -void BlastController::updateDraggingStress() -{ - auto physxController = getPhysXController(); - auto actor = physxController.getDraggingActor(); - if (actor) - { - ExtPxActor* pxActor = m_extPxManager->getActorFromPhysXActor(*actor); - if (pxActor && pxActor->getTkActor().getGraphNodeCount() > 1 && pxActor->getPhysXActor().getRigidBodyFlags() & PxRigidBodyFlag::eKINEMATIC) - { - void* userData = pxActor->getFamily().userData; - if (userData) - { - ExtPxStressSolver* solver = reinterpret_cast<ExtPxStressSolver*>(userData); - PxTransform t(pxActor->getPhysXActor().getGlobalPose().getInverse()); - PxVec3 dragVector = t.rotate(physxController.getDragVector()); - const float factor = dragVector.magnitudeSquared() * m_draggingToStressFactor; - solver->getSolver().addForce(*pxActor->getTkActor().getActorLL(), physxController.getDragActorHookLocalPoint(), dragVector.getNormalized() * factor); - } - } - } -} - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Stats -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -uint32_t BlastController::getActorCount() const -{ - return std::accumulate(m_families.begin(), m_families.end(), (uint32_t)0, [](uint32_t sum, const BlastFamilyPtr& a) - { - return sum += a->getActorCount(); - }); -} - -uint32_t BlastController::getTotalVisibleChunkCount() const -{ - return std::accumulate(m_families.begin(), m_families.end(), (uint32_t)0, [](uint32_t sum, const BlastFamilyPtr& a) - { - return sum += a->getTotalVisibleChunkCount(); - }); -} - -size_t BlastController::getFamilySize() const -{ - return std::accumulate(m_families.begin(), m_families.end(), (size_t)0, [](size_t sum, const BlastFamilyPtr& a) - { - return sum += a->getFamilySize(); - }); -} - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Time -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -const double Time::s_secondsPerTick = Time::getTickDuration(); - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Controller events -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -void BlastController::Animate(double dt) -{ - PROFILER_SCOPED_FUNCTION(); - - PROFILER_BEGIN("Apply Impact Damage"); - m_extImpactDamageManager->applyDamage(); - PROFILER_END(); - - updateDraggingStress(); - - fillDebugRender(); - - getPhysXController().simualtionSyncEnd(); - - updateImpactDamage(); - - Time blastTime; - for (uint32_t i = 0; i < m_families.size(); ++i) - { - if (m_families[i]) - { - m_families[i]->updatePreSplit(dt); - } - } - - m_replay->update(); - - PROFILER_BEGIN("Tk Group Process/Sync"); - -#if 1 - - m_extGroupTaskManager->process(); - m_extGroupTaskManager->wait(); - -#else // process group on main thread - - m_tkGroup->process(); - -#endif - - PROFILER_END(); - - getPhysXController().simulationBegin(dt); - - TkGroupStats gstats; - m_tkGroup->getStats(gstats); - - this->m_lastBlastTimers.blastDamageMaterial = NvBlastTicksToSeconds(gstats.timers.material); - this->m_lastBlastTimers.blastDamageFracture = NvBlastTicksToSeconds(gstats.timers.fracture); - this->m_lastBlastTimers.blastSplitIsland = NvBlastTicksToSeconds(gstats.timers.island); - this->m_lastBlastTimers.blastSplitPartition = NvBlastTicksToSeconds(gstats.timers.partition); - this->m_lastBlastTimers.blastSplitVisibility = NvBlastTicksToSeconds(gstats.timers.visibility); - - for (uint32_t i = 0; i < m_families.size(); ++i) - { - if (m_families[i]) - { - m_families[i]->updateAfterSplit(dt); - } - } - -// Add By Lixu Begin - BlastSceneTree* pBlastSceneTree = BlastSceneTree::ins(); - bool needUpdateUI = false; - - std::map<BlastAsset*, std::vector<BlastFamily*>>& AssetFamiliesMap = getManager()->getAssetFamiliesMap(); - std::map<BlastAsset*, std::vector<BlastFamily*>>::iterator itAsset; - std::vector<BlastFamily*>::iterator itFamily; - uint32_t assetIndex = 0; - for (itAsset = AssetFamiliesMap.begin(); itAsset != AssetFamiliesMap.end(); itAsset++) - { - std::vector<BlastFamily*>& BlastFamilies = itAsset->second; - for (itFamily = BlastFamilies.begin(); itFamily != BlastFamilies.end(); itFamily++) - { - BlastFamily* pFamily = *itFamily; - - std::map<uint32_t, bool>& VisibleChangedChunks = pFamily->getVisibleChangedChunks(); - std::map<uint32_t, bool>::iterator itChunk; - for (itChunk = VisibleChangedChunks.begin(); itChunk != VisibleChangedChunks.end(); itChunk++) - { - pBlastSceneTree->updateVisible(assetIndex, itChunk->first, itChunk->second); - needUpdateUI = true; - } - pFamily->clearVisibleChangedChunks(); - } - - assetIndex++; - } - - if (needUpdateUI) - { - //pBlastSceneTree->updateValues(false); - SampleManager::ins()->m_bNeedRefreshTree = true; - } -// Add By Lixu End -} - - -void BlastController::drawUI() -{ - // impact damage - bool impactEnabled = getImpactDamageEnabled(); - if (ImGui::Checkbox("Impact Damage", &impactEnabled)) - { - setImpactDamageEnabled(impactEnabled); - } - { - bool refresh = false; - refresh |= ImGui::Checkbox("Use Shear Damage", &m_extImpactDamageManagerSettings.shearDamage); - refresh |= ImGui::DragFloat("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"); - ImGui::DragFloat("Dragging To Stress Factor", &m_draggingToStressFactor, 0.1f, 0.0f, 1000.0f, "%.3f"); - - ImGui::Checkbox("Limit Rigid Body Count", &m_rigidBodyLimitEnabled); - if (m_rigidBodyLimitEnabled) - { - ImGui::DragInt("Rigid Body Limit", (int*)&m_rigidBodyLimit, 100, 1000, 100000); - } - m_extPxManager->setActorCountLimit(m_rigidBodyLimitEnabled ? m_rigidBodyLimit : 0); -} - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// actor management -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -BlastFamilyPtr BlastController::spawnFamily(BlastAsset* blastAsset, const BlastAsset::ActorDesc& desc) -{ - BlastFamilyPtr actor = blastAsset->createFamily(getPhysXController(), *m_extPxManager, desc); - m_families.push_back(actor); - recalculateAssetsSize(); - m_replay->addFamily(&actor->getFamily()->getTkFamily()); - return actor; -} - -void BlastController::removeFamily(BlastFamilyPtr actor) -{ - m_replay->removeFamily(&actor->getFamily()->getTkFamily()); - m_families.erase(std::remove(m_families.begin(), m_families.end(), actor), m_families.end()); - recalculateAssetsSize(); - getPhysXController().resetDragging(); -// Add By Lixu Begin - delete actor; -// Add By Lixu End -} - -void BlastController::removeAllFamilies() -{ - while (!m_families.empty()) - { - removeFamily(m_families.back()); - } - m_replay->reset(); -} - -void BlastController::recalculateAssetsSize() -{ - std::set<const BlastAsset*> uniquedAssets; - m_blastAssetsSize = 0; - for (uint32_t i = 0; i < m_families.size(); ++i) - { - if (uniquedAssets.find(&m_families[i]->getBlastAsset()) == uniquedAssets.end()) - { - m_blastAssetsSize += m_families[i]->getBlastAsset().getBlastAssetSize(); - uniquedAssets.insert(&m_families[i]->getBlastAsset()); - } - } -} - -bool BlastController::overlap(const PxGeometry& geometry, const PxTransform& pose, std::function<void(ExtPxActor*)> hitCall) -{ - PROFILER_SCOPED_FUNCTION(); - - bool anyHit = false; - for (uint32_t i = 0; i < m_families.size(); ++i) - { - if (m_families[i]) - { - anyHit |= m_families[i]->overlap(geometry, pose, hitCall); - } - } - return anyHit; -} - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// debug render -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -void BlastController::fillDebugRender() -{ - PROFILER_SCOPED_FUNCTION(); - - m_debugRenderBuffer.clear(); - - if (debugRenderMode != BlastFamily::DEBUG_RENDER_DISABLED) - { - getPhysXController().getPhysXScene().setVisualizationParameter(PxVisualizationParameter::eSCALE, 1); - for (uint32_t i = 0; i < m_families.size(); ++i) - { - m_families[i]->fillDebugRender(m_debugRenderBuffer, debugRenderMode, debugRenderScale); - } - } - else - { - getPhysXController().getPhysXScene().setVisualizationParameter(PxVisualizationParameter::eSCALE, 0); - } - - getRenderer().queueRenderBuffer(&m_debugRenderBuffer); -} - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastController.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastController.h deleted file mode 100644 index 7a6bcf0..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastController.h +++ /dev/null @@ -1,287 +0,0 @@ -// 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 - -#include "SampleManager.h" -#include "BlastFamily.h" -#include "DebugRenderBuffer.h" -#include "PxSimulationEventCallback.h" -#include "NvBlastExtImpactDamageManager.h" - -using namespace physx; - -class BlastAsset; -class BlastReplay; - -namespace physx -{ -class PxTaskManager; -} -namespace Nv -{ -namespace Blast -{ -class TkFramework; -class ExtGroupTaskManager; -class ExtSerialization; -} -} - - -struct BlastTimers -{ - double blastDamageMaterial; - double blastDamageFracture; - double blastSplitIsland; - double blastSplitPartition; - double blastSplitVisibility; -}; - -/** -Blast Controller. Entry point for all blast related code, keeps blast actors and controls them. -*/ -class BlastController : public ISampleController -{ -public: - //////// ctor //////// - - BlastController(); - virtual ~BlastController(); - - void reinitialize(); - - //////// controller callbacks //////// - - virtual void onSampleStart(); - virtual void onSampleStop(); - - virtual void Animate(double dt); - void drawUI(); - - - //////// public API //////// - - bool overlap(const PxGeometry& geometry, const PxTransform& pose, std::function<void(ExtPxActor*)> hitCall); - - bool stressDamage(ExtPxActor *actor, PxVec3 position, PxVec3 force); - - BlastFamilyPtr spawnFamily(BlastAsset* blastAsset, const BlastAsset::ActorDesc& desc); - void removeFamily(BlastFamilyPtr actor); - void removeAllFamilies(); - - - //////// public getters/setters //////// - - TkFramework& getTkFramework() const - { - return *m_tkFramework; - } - - TkGroup* getTkGroup() const - { - return m_tkGroup; - } - - ExtPxManager& getExtPxManager() const - { - return *m_extPxManager; - } - - ExtImpactDamageManager* getExtImpactDamageManager() const - { - return m_extImpactDamageManager; - } - - BlastReplay* getReplay() const - { - return m_replay; - } - - uint32_t getActorCount() const; - - uint32_t getTotalVisibleChunkCount() const; - - size_t getFamilySize() const; - - size_t getBlastAssetsSize() const - { - return m_blastAssetsSize; - } - - const BlastTimers& getLastBlastTimers() const - { - return m_lastBlastTimers; - } - - bool getImpactDamageEnabled() const - { - return m_impactDamageEnabled; - } - - void setImpactDamageEnabled(bool enabled, bool forceUpdate = false); - - ExtStressSolverSettings& getStressSolverSettings() - { - return m_extStressSolverSettings; - } - -// Add By Lixu Begin - std::vector<BlastFamilyPtr>& getFamilies() - { - 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); - - BlastFamily* getFamilyById(int familyId); -// Add By Lixu End - - float getLastStressDelta() const; - - void notifyPhysXControllerRelease(); - - ExtSerialization* getExtSerialization() const - { - return m_extSerialization; - } - - //////// public variables for UI //////// - - BlastFamily::DebugRenderMode debugRenderMode; - float debugRenderScale; - - - //////// Filter shader enum //////// - - enum FilterDataAttributes - { - SUPPRESS_CONTACT_NOTIFY = 1, - }; - -private: - //////// impact damage event callback //////// - - class EventCallback : public PxSimulationEventCallback - { - public: - EventCallback(ExtImpactDamageManager* manager) : m_manager(manager) {} - - // implemented - virtual void onContact(const PxContactPairHeader& pairHeader, const PxContactPair* pairs, uint32_t nbPairs) - { - m_manager->onContact(pairHeader, pairs, nbPairs); - } - - private: - // unused - void onConstraintBreak(PxConstraintInfo*, PxU32) {} - void onWake(PxActor**, PxU32) {} - void onSleep(PxActor**, PxU32) {} - void onTrigger(PxTriggerPair*, PxU32) {} - void onAdvance(const PxRigidBody*const*, const PxTransform*, const PxU32) {} - - // data - ExtImpactDamageManager* m_manager; - }; - - - //////// private methods //////// - - void updateDraggingStress(); - - void updateImpactDamage(); - - void refreshImpactDamageSettings(); - - void fillDebugRender(); - - void recalculateAssetsSize(); - - static bool customImpactDamageFunction(void* data, ExtPxActor* actor, PxShape* shape, PxVec3 position, PxVec3 force); - - - //////// used controllers //////// - - Renderer& getRenderer() const - { - return getManager()->getRenderer(); - } - - PhysXController& getPhysXController() const - { - return getManager()->getPhysXController(); - } - - - //////// internal data //////// - - PxTaskManager* m_taskManager; - TkFramework* m_tkFramework; - TkGroup* m_tkGroup; - ExtPxManager* m_extPxManager; - ExtImpactDamageManager* m_extImpactDamageManager; - ExtImpactSettings m_extImpactDamageManagerSettings; - EventCallback* m_eventCallback; - ExtStressSolverSettings m_extStressSolverSettings; - ExtGroupTaskManager* m_extGroupTaskManager; - ExtSerialization* m_extSerialization; - - std::vector<BlastFamilyPtr> m_families; - DebugRenderBuffer m_debugRenderBuffer; - - bool m_impactDamageEnabled; - bool m_impactDamageUpdatePending; - bool m_impactDamageToStressEnabled; - - float m_impactDamageToStressFactor; - float m_draggingToStressFactor; - - bool m_rigidBodyLimitEnabled; - uint32_t m_rigidBodyLimit; - - BlastReplay* m_replay; - - BlastTimers m_lastBlastTimers; - - size_t m_blastAssetsSize; -}; - - -#endif diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamily.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamily.cpp deleted file mode 100644 index dff2d20..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamily.cpp +++ /dev/null @@ -1,617 +0,0 @@ -// 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" -#include "PhysXController.h" -#include "RenderUtils.h" -#include "SampleTime.h" -#include "UIHelpers.h" - -#include "NvBlast.h" -#include "NvBlastTkFamily.h" -#include "NvBlastTkActor.h" -#include "NvBlastTkAsset.h" -#include "NvBlastTkJoint.h" -#include "NvBlastExtPxAsset.h" -#include "NvBlastExtPxActor.h" -#include "NvBlastExtPxFamily.h" -#include "NvBlastExtPxManager.h" - -#include "PxRigidDynamic.h" -#include "PxScene.h" -#include "PxJoint.h" -// Add By Lixu Begin -#include "BlastSceneTree.h" -// Add By Lixu End - - -const float RIGIDBODY_DENSITY = 2000.0f; - -std::set<int> ExistingFamilyIds; -BlastFamily::BlastFamily(PhysXController& physXController, ExtPxManager& pxManager, const BlastAsset& blastAsset) - : m_physXController(physXController) - , m_pxManager(pxManager) - , m_blastAsset(blastAsset) - , m_listener(this) - , m_totalVisibleChunkCount(0) - , m_stressSolver(nullptr) - , m_spawned(false) -{ - m_settings.stressSolverEnabled = false; - m_settings.stressDamageEnabled = false; - - for (int id = 0; ; id++) - { - if (ExistingFamilyIds.find(id) == ExistingFamilyIds.end()) - { - ExistingFamilyIds.emplace(id); - mUniqueId = id; - break; - } - } -} - -BlastFamily::~BlastFamily() -{ - if (m_stressSolver) - { - m_stressSolver->release(); - } - - m_pxFamily->unsubscribe(m_listener); - - m_pxFamily->release(); - - ExistingFamilyIds.erase(mUniqueId); -} - -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 = (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); - - m_tkFamily = &m_pxFamily->getTkFamily(); - m_tkFamily->setID(desc.id); - m_tkFamily->setMaterial(&m_settings.material); - - m_familySize = NvBlastFamilyGetSize(m_tkFamily->getFamilyLL(), nullptr); - - m_pxFamily->subscribe(m_listener); - - m_initialTransform = desc.transform; - - updatePreSplit(0); - m_VisibleChangedChunks.clear(); -} - -void BlastFamily::updatePreSplit(float dt) -{ - if (!m_spawned) - { - ExtPxSpawnSettings spawnSettings = { - &m_physXController.getPhysXScene(), - m_physXController.getDefaultMaterial(), - RIGIDBODY_DENSITY - }; - - m_pxFamily->spawn(m_initialTransform, PxVec3(1.0f), spawnSettings); - reloadStressSolver(); - - m_spawned = true; - } - - // collect potential actors to health update - m_actorsToUpdateHealth.clear(); - for (const ExtPxActor* actor : m_actors) - { - if (actor->getTkActor().isPending()) - { - m_actorsToUpdateHealth.emplace(actor); - } - } -} - -void BlastFamily::updateAfterSplit(float dt) -{ - PROFILER_BEGIN("Actor Health Update"); - for (const ExtPxActor* actor : m_actors) - { - onActorUpdate(*actor); - - // update health if neccessary - if (m_actorsToUpdateHealth.find(actor) != m_actorsToUpdateHealth.end()) - { - onActorHealthUpdate(*actor); - } - } - PROFILER_END(); - - PROFILER_BEGIN("Stress Solver"); - // update stress - m_stressSolveTime = 0; - if (m_stressSolver) - { - Time t; - m_stressSolver->update(m_settings.stressDamageEnabled); - m_stressSolveTime += t.getElapsedSeconds(); - } - PROFILER_END(); - - PROFILER_BEGIN("Actor Misc Update"); - onUpdate(); - PROFILER_END(); - - m_pxFamily->postSplitUpdate(); -} - -void BlastFamily::processActorCreated(ExtPxFamily&, ExtPxActor& actor) -{ - m_totalVisibleChunkCount += actor.getChunkCount(); - m_actors.emplace(&actor); - - onActorCreated(actor); - onActorHealthUpdate(actor); -} - -void BlastFamily::processActorDestroyed(ExtPxFamily&, ExtPxActor& actor) -{ - m_totalVisibleChunkCount -= actor.getChunkCount(); - m_physXController.notifyRigidDynamicDestroyed(&actor.getPhysXActor()); - - onActorDestroyed(actor); - - m_actors.erase(m_actors.find(&actor)); -} - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Data Helpers -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -uint32_t BlastFamily::getActorCount() const -{ - return (uint32_t)m_tkFamily->getActorCount(); -} - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// UI -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -void BlastFamily::drawUI() -{ - // Blast Material - ImGui::Spacing(); - ImGui::Text("Blast Material:"); - ImGui::DragFloat("Health", &m_settings.material.health); - ImGui::DragFloat("Min Damage Threshold", &m_settings.material.minDamageThreshold, 0.01f, 0.f, m_settings.material.maxDamageThreshold); - ImGui::DragFloat("Max Damage Threshold", &m_settings.material.maxDamageThreshold, 0.01f, m_settings.material.minDamageThreshold, 1.f); - - ImGui::Spacing(); - - // Stress Solver Settings - if (ImGui::Checkbox("Stress Solver Enabled", &m_settings.stressSolverEnabled)) - { - reloadStressSolver(); - } - - if (m_settings.stressSolverEnabled) - { - // Settings - bool changed = false; - - changed |= ImGui::DragInt("Bond Iterations Per Frame", (int*)&m_settings.stressSolverSettings.bondIterationsPerFrame, 100, 0, 500000); - changed |= ImGui::DragFloat("Material Hardness", &m_settings.stressSolverSettings.hardness, 10.0f, 0.01f, 100000.0f, "%.2f"); - changed |= ImGui::DragFloat("Stress Linear Factor", &m_settings.stressSolverSettings.stressLinearFactor, 0.01f, 0.0f, 100.0f, "%.2f"); - changed |= ImGui::DragFloat("Stress Angular Factor", &m_settings.stressSolverSettings.stressAngularFactor, 0.01f, 0.0f, 100.0f, "%.2f"); - changed |= ImGui::SliderInt("Graph Reduction Level", (int*)&m_settings.stressSolverSettings.graphReductionLevel, 0, 32); - if (changed) - { - refreshStressSolverSettings(); - } - - ImGui::Checkbox("Stress Damage Enabled", &m_settings.stressDamageEnabled); - - if (ImGui::Button("Recalculate Stress")) - { - resetStress(); - } - } -} - -void BlastFamily::drawStatsUI() -{ - ImGui::PushStyleColor(ImGuiCol_Text, ImColor(10, 255, 10, 255)); - if (m_stressSolver) - { - const ExtStressSolver& stressSolver = m_stressSolver->getSolver(); - const float errorLinear = stressSolver.getStressErrorLinear(); - const float errorAngular = stressSolver.getStressErrorAngular(); - - ImGui::Text("Stress Bond Count: %d", stressSolver.getBondCount()); - ImGui::Text("Stress Frame Iter: %d", stressSolver.getIterationsPerFrame()); - ImGui::Text("Stress Frames: %d", stressSolver.getFrameCount()); - ImGui::Text("Stress Error Lin / Ang: %.4f / %.4f", errorLinear, errorAngular); - ImGui::Text("Stress Solve Time: %.3f ms", m_stressSolveTime * 1000); - - // plot errors - { - static float scale = 1.0f; - scale = stressSolver.getFrameCount() <= 1 ? 1.0f : scale; - scale = std::max<float>(scale, errorLinear); - scale = std::max<float>(scale, errorAngular); - - static PlotLinesInstance<> linearErrorPlot; - linearErrorPlot.plot("Stress Linear Error", errorLinear, "error/frame", 0.0f, 1.0f * scale); - static PlotLinesInstance<> angularErrorPlot; - angularErrorPlot.plot("Stress Angular Error", errorAngular, "error/frame", 0.0f, 1.0f * scale); - } - } - else - { - ImGui::Text("No Stress Solver"); - } - ImGui::PopStyleColor(); -} - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Stress Solver -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -void BlastFamily::setSettings(const Settings& settings) -{ - bool reloadStressSolverNeeded = (m_settings.stressSolverEnabled != settings.stressSolverEnabled); - - m_settings = settings; - refreshStressSolverSettings(); - - if (reloadStressSolverNeeded) - { - reloadStressSolver(); - } - - m_tkFamily->setMaterial(&m_settings.material); - initTransform(m_settings.transform); - m_initialTransform = m_settings.transform; -} - -void BlastFamily::refreshStressSolverSettings() -{ - if (m_stressSolver) - { - m_stressSolver->getSolver().setSettings(m_settings.stressSolverSettings); - } -} - -void BlastFamily::resetStress() -{ - if (m_stressSolver) - { - m_stressSolver->getSolver().reset(); - } -} - -void BlastFamily::reloadStressSolver() -{ - if (m_stressSolver) - { - m_stressSolver->release(); - m_stressSolver = nullptr; - } - - if (m_settings.stressSolverEnabled) - { - m_stressSolver = ExtPxStressSolver::create(*m_pxFamily, m_settings.stressSolverSettings); - m_pxFamily->userData = m_stressSolver; - } -} - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// debug render -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -const DirectX::XMFLOAT4 BOND_NORMAL_COLOR(0.0f, 0.8f, 1.0f, 1.0f); -const DirectX::XMFLOAT4 BOND_INVISIBLE_COLOR(0.65f, 0.16f, 0.16f, 1.0f); -const DirectX::XMFLOAT4 BOND_IMPULSE_LINEAR_COLOR(0.0f, 1.0f, 0.0f, 1.0f); -const DirectX::XMFLOAT4 BOND_IMPULSE_ANGULAR_COLOR(1.0f, 0.0f, 0.0f, 1.0f); -const DirectX::XMFLOAT4 JOINT_COLOR(0.5f, 0.6f, 7.0f, 1.0f); - - -inline void pushCentroid(std::vector<PxDebugLine>& lines, PxVec3 pos, PxU32 color, const float& area, const PxVec3& normal) -{ - // draw square of area 'area' rotated by normal - { - // build world rotation - PxVec3 n0(0, 0, 1); - PxVec3 n1 = normal; - PxVec3 axis = n0.cross(n1); - float d = n0.dot(n1); - PxQuat q(axis.x, axis.y, axis.z, 1.f + d); - q.normalize(); - float e = PxSqrt(1.0f / 2.0f); - float r = PxSqrt(area); - - // transform all 4 square points - PxTransform t(pos, q); - PxVec3 p0 = t.transform(PxVec3(-e, e, 0) * r); - PxVec3 p1 = t.transform(PxVec3( e, e, 0) * r); - PxVec3 p2 = t.transform(PxVec3( e, -e, 0) * r); - PxVec3 p3 = t.transform(PxVec3(-e, -e, 0) * r); - - // push square edges - lines.push_back(PxDebugLine(p0, p1, color)); - lines.push_back(PxDebugLine(p3, p2, color)); - lines.push_back(PxDebugLine(p1, p2, color)); - lines.push_back(PxDebugLine(p0, p3, color)); - } - - // draw normal - lines.push_back(PxDebugLine(pos, pos + normal * 0.5f, XMFLOAT4ToU32Color(BOND_NORMAL_COLOR))); -} - -inline DirectX::XMFLOAT4 bondHealthColor(float healthFraction) -{ - const DirectX::XMFLOAT4 BOND_HEALTHY_COLOR(0.0f, 1.0f, 0.0f, 1.0f); - const DirectX::XMFLOAT4 BOND_MID_COLOR(1.0f, 1.0f, 0.0f, 1.0f); - const DirectX::XMFLOAT4 BOND_BROKEN_COLOR(1.0f, 0.0f, 0.0f, 1.0f); - - return healthFraction < 0.5 ? XMFLOAT4Lerp(BOND_BROKEN_COLOR, BOND_MID_COLOR, 2.0f * healthFraction) : XMFLOAT4Lerp(BOND_MID_COLOR, BOND_HEALTHY_COLOR, 2.0f * healthFraction - 1.0f); -} - -void BlastFamily::fillDebugRender(DebugRenderBuffer& debugRenderBuffer, DebugRenderMode mode, float renderScale) -{ - const NvBlastChunk* chunks = m_tkFamily->getAsset()->getChunks(); - const NvBlastBond* bonds = m_tkFamily->getAsset()->getBonds(); - const NvBlastSupportGraph graph = m_tkFamily->getAsset()->getGraph(); - const float bondHealthMax = m_blastAsset.getBondHealthMax(); - const uint32_t chunkCount = m_tkFamily->getAsset()->getChunkCount(); - - for (const ExtPxActor* pxActor : m_actors) - { - TkActor& actor = pxActor->getTkActor(); - uint32_t lineStartIndex = (uint32_t)debugRenderBuffer.m_lines.size(); - - uint32_t nodeCount = actor.getGraphNodeCount(); - if (nodeCount == 0) // subsupport chunks don't have graph nodes - continue; - - std::vector<uint32_t> nodes(nodeCount); - actor.getGraphNodeIndices(nodes.data(), static_cast<uint32_t>(nodes.size())); - - if (DEBUG_RENDER_HEALTH_GRAPH <= mode && mode <= DEBUG_RENDER_HEALTH_GRAPH_CENTROIDS) - { - const float* bondHealths = actor.getBondHealths(); - - const ExtPxChunk* pxChunks = m_blastAsset.getPxAsset()->getChunks(); - - for (uint32_t node0 : nodes) - { - const uint32_t chunkIndex0 = graph.chunkIndices[node0]; - const NvBlastChunk& blastChunk0 = chunks[chunkIndex0]; - const ExtPxChunk& assetChunk0 = pxChunks[chunkIndex0]; - - for (uint32_t adjacencyIndex = graph.adjacencyPartition[node0]; adjacencyIndex < graph.adjacencyPartition[node0 + 1]; adjacencyIndex++) - { - uint32_t node1 = graph.adjacentNodeIndices[adjacencyIndex]; - const uint32_t chunkIndex1 = graph.chunkIndices[node1]; - const NvBlastChunk& blastChunk1 = chunks[chunkIndex1]; - const ExtPxChunk& assetChunk1 = pxChunks[chunkIndex1]; - if (node0 > node1) - continue; - - bool invisibleBond = chunkIndex0 >= chunkCount || chunkIndex1 >= chunkCount || assetChunk0.subchunkCount == 0 || assetChunk1.subchunkCount == 0; - - // health - uint32_t bondIndex = graph.adjacentBondIndices[adjacencyIndex]; - float healthVal = PxClamp(bondHealths[bondIndex] / bondHealthMax, 0.0f, 1.0f); - - DirectX::XMFLOAT4 color = bondHealthColor(healthVal); - - const NvBlastBond& solverBond = bonds[bondIndex]; - const PxVec3& centroid = reinterpret_cast<const PxVec3&>(solverBond.centroid); - - // centroid - if (mode == DEBUG_RENDER_HEALTH_GRAPH_CENTROIDS || mode == DEBUG_RENDER_CENTROIDS) - { - const PxVec3& normal = reinterpret_cast<const PxVec3&>(solverBond.normal); - pushCentroid(debugRenderBuffer.m_lines, centroid, XMFLOAT4ToU32Color(invisibleBond ? BOND_INVISIBLE_COLOR : color), solverBond.area, normal.getNormalized()); - } - - // chunk connection (bond) - if ((mode == DEBUG_RENDER_HEALTH_GRAPH || mode == DEBUG_RENDER_HEALTH_GRAPH_CENTROIDS) && !invisibleBond) - { - const PxVec3& c0 = reinterpret_cast<const PxVec3&>(blastChunk0.centroid); - const PxVec3& c1 = reinterpret_cast<const PxVec3&>(blastChunk1.centroid); - debugRenderBuffer.m_lines.push_back(PxDebugLine(c0, c1, XMFLOAT4ToU32Color(color))); - } - } - } - } - - // stress - if (DEBUG_RENDER_STRESS_GRAPH <= mode && mode <= DEBUG_RENDER_STRESS_GRAPH_BONDS_IMPULSES) - { - if (m_stressSolver) - { - const auto buffer = m_stressSolver->getSolver().fillDebugRender(nodes.data(), (uint32_t)nodes.size(), (ExtStressSolver::DebugRenderMode)(mode - DEBUG_RENDER_STRESS_GRAPH), renderScale); - if (buffer.lineCount) - { - const auto lines = reinterpret_cast<const PxDebugLine*>(buffer.lines); - debugRenderBuffer.m_lines.insert(debugRenderBuffer.m_lines.end(), lines, lines + buffer.lineCount); - } - } - } - - // transform all added lines from local to global - PxTransform localToGlobal = pxActor->getPhysXActor().getGlobalPose(); - for (uint32_t i = lineStartIndex; i < debugRenderBuffer.m_lines.size(); i++) - { - PxDebugLine& line = debugRenderBuffer.m_lines[i]; - line.pos0 = localToGlobal.transform(line.pos0); - line.pos1 = localToGlobal.transform(line.pos1); - } - } - - // joints debug render - if (mode == DEBUG_RENDER_JOINTS) - { - for (const ExtPxActor* pxActor : m_actors) - { - TkActor& actor = pxActor->getTkActor(); - const uint32_t jointCount = actor.getJointCount(); - if (jointCount > 0) - { - std::vector<TkJoint*> joints(jointCount); - actor.getJoints(joints.data(), jointCount); - for (auto joint : joints) - { - PxJoint* pxJoint = reinterpret_cast<PxJoint*>(joint->userData); - if (pxJoint) - { - PxRigidActor *actor0, *actor1; - pxJoint->getActors(actor0, actor1); - auto lp0 = pxJoint->getLocalPose(PxJointActorIndex::eACTOR0); - auto lp1 = pxJoint->getLocalPose(PxJointActorIndex::eACTOR1); - PxVec3 p0 = actor0 ? actor0->getGlobalPose().transform(lp0).p : lp0.p; - PxVec3 p1 = actor1 ? actor1->getGlobalPose().transform(lp1).p : lp1.p; - debugRenderBuffer.m_lines.push_back(PxDebugLine(p0, p1, XMFLOAT4ToU32Color(JOINT_COLOR))); - } - } - } - } - } -} - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// action!!! -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -class BlastOverlapCallback : public PxOverlapCallback -{ -public: - BlastOverlapCallback(ExtPxManager& pxManager, std::set<ExtPxActor*>& actorBuffer) - : m_pxManager(pxManager), m_actorBuffer(actorBuffer), PxOverlapCallback(m_hitBuffer, sizeof(m_hitBuffer) / sizeof(m_hitBuffer[0])) {} - - PxAgain processTouches(const PxOverlapHit* buffer, PxU32 nbHits) - { - for (PxU32 i = 0; i < nbHits; ++i) - { - PxRigidDynamic* rigidDynamic = buffer[i].actor->is<PxRigidDynamic>(); - if (rigidDynamic) - { - ExtPxActor* actor = m_pxManager.getActorFromPhysXActor(*rigidDynamic); - if (actor != nullptr) - { - m_actorBuffer.insert(actor); - } - } - } - return true; - } - -private: - ExtPxManager& m_pxManager; - std::set<ExtPxActor*>& m_actorBuffer; - PxOverlapHit m_hitBuffer[1000]; -}; - -bool BlastFamily::overlap(const PxGeometry& geometry, const PxTransform& pose, std::function<void(ExtPxActor*)> hitCall) -{ -// Add By Lixu Begin - /* - const ExtPxAsset* pExtPxAsset = m_blastAsset.getPxAsset(); - const TkAsset& tkAsset = pExtPxAsset->getTkAsset(); - uint32_t bondCount = tkAsset.getBondCount(); - if (bondCount == 0) - { - return false; - } - */ -// Add By Lixu End - - std::set<ExtPxActor*> actorsToDamage; -#if 1 - BlastOverlapCallback overlapCallback(m_pxManager, actorsToDamage); - m_physXController.getPhysXScene().overlap(geometry, pose, overlapCallback); -#else - for (std::map<NvBlastActor*, PhysXController::Actor*>::iterator it = m_actorsMap.begin(); it != m_actorsMap.end(); it++) - { - actorsToDamage.insert(it->first); - } -#endif - - for (auto actor : actorsToDamage) - { - hitCall(actor); - } - - return !actorsToDamage.empty(); -} - diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamily.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamily.h deleted file mode 100644 index 9978f20..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamily.h +++ /dev/null @@ -1,262 +0,0 @@ -// 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 "NvBlastExtPxStressSolver.h" -#include "NvBlastExtDamageShaders.h" -#include <functional> -#include <set> -#include <map> - - -class DebugRenderBuffer; -// Add By Lixu Begin -class RenderMaterial; -namespace physx -{ - class PxActor; -} -using namespace physx; -// Add By Lixu End - -namespace Nv -{ -namespace Blast -{ -class TkFamily; -class ExtPxManager; -} -} - -namespace physx -{ -class PxGeometry; -class PxTransform; -} - - - -/** -BlastFamily class represents 1 spawned BlastAsset, contains and manipulates all physx/blast actors spawned by fracturing it. -Abstract class, internal actor management functions are implementation dependent and so pure virtual. -*/ -class BlastFamily -{ -public: - - //////// public API //////// - - bool overlap(const PxGeometry& geometry, const PxTransform& pose, std::function<void(ExtPxActor*)> hitCall); - - void updatePreSplit(float dt); - void updateAfterSplit(float dt); - - void drawUI(); - void drawStatsUI(); - -// Add By Lixu Begin - 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 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) { 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 - { - DEBUG_RENDER_DISABLED, - DEBUG_RENDER_HEALTH_GRAPH, - DEBUG_RENDER_CENTROIDS, - DEBUG_RENDER_HEALTH_GRAPH_CENTROIDS, - DEBUG_RENDER_JOINTS, - DEBUG_RENDER_STRESS_GRAPH, - DEBUG_RENDER_STRESS_GRAPH_NODES_IMPULSES, - DEBUG_RENDER_STRESS_GRAPH_BONDS_IMPULSES, - - // count - DEBUG_RENDER_MODES_COUNT - }; - - void fillDebugRender(DebugRenderBuffer& debugRenderBuffer, DebugRenderMode mode, float renderScale); - - - //////// public getters //////// - - const ExtPxFamily* getFamily() const - { - return m_pxFamily; - } - - uint32_t getActorCount() const; - - uint32_t getTotalVisibleChunkCount() const - { - return m_totalVisibleChunkCount; - } - - size_t getFamilySize() const - { - return m_familySize; - } - - const BlastAsset& getBlastAsset() - { - return m_blastAsset; - } - - void resetStress(); - - void refreshStressSolverSettings(); - - void reloadStressSolver(); - - - //////// settings //////// - - struct Settings - { - bool stressSolverEnabled; - ExtStressSolverSettings stressSolverSettings; - bool stressDamageEnabled; - NvBlastExtMaterial material; - physx::PxTransform transform; - }; - - void setSettings(const Settings& settings); - - const Settings& getSettings() const - { - return m_settings; - } - - - //////// dtor //////// - - virtual ~BlastFamily(); - int mUniqueId; - -protected: - - //////// ctor //////// - - BlastFamily(PhysXController& physXController, ExtPxManager& pxManager, const BlastAsset& blastAsset); - - void initialize(const BlastAsset::ActorDesc& desc); - - - //////// internal virtual callbacks //////// - - virtual void onActorCreated(const ExtPxActor& actor) = 0; - virtual void onActorUpdate(const ExtPxActor& actor) = 0; - virtual void onActorDestroyed(const ExtPxActor& actor) = 0; - virtual void onActorHealthUpdate(const ExtPxActor& pxActor) {}; - - virtual void onUpdate() {} - - - //////// protected data //////// - - PhysXController& m_physXController; - ExtPxManager& m_pxManager; - const BlastAsset& m_blastAsset; - std::map<uint32_t, bool> m_VisibleChangedChunks; - -private: - - //////// physics listener //////// - - class PxManagerListener : public ExtPxListener - { - public: - PxManagerListener(BlastFamily* family) : m_family(family) {} - - virtual void onActorCreated(ExtPxFamily& family, ExtPxActor& actor) - { - m_family->processActorCreated(family, actor); - - } - - virtual void onActorDestroyed(ExtPxFamily& family, ExtPxActor& actor) - { - m_family->processActorDestroyed(family, actor); - } - private: - BlastFamily* m_family; - }; - - friend class PxManagerListener; - - //////// private methods //////// - - void processActorCreated(ExtPxFamily&, ExtPxActor& actor); - void processActorDestroyed(ExtPxFamily&, ExtPxActor& actor); - - - //////// private data //////// - - TkFamily* m_tkFamily; - ExtPxFamily* m_pxFamily; - PxManagerListener m_listener; - Settings m_settings; - PxTransform m_initialTransform; - bool m_spawned; - size_t m_familySize; - uint32_t m_totalVisibleChunkCount; - ExtPxStressSolver* m_stressSolver; - double m_stressSolveTime; - std::set<const ExtPxActor*> m_actorsToUpdateHealth; - // Add By Lixu Begin -protected: - std::set<ExtPxActor*> m_actors; - // Add By Lixu End -}; - - -#endif //BLAST_FAMILY_H
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyBoxes.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyBoxes.cpp deleted file mode 100644 index 7011612..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyBoxes.cpp +++ /dev/null @@ -1,109 +0,0 @@ -// 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" -#include "NvBlastExtPxAsset.h" -#include "NvBlastExtPxActor.h" -#include "BlastAssetBoxes.h" -#include "Renderer.h" -#include "PhysXController.h" -#include "RenderUtils.h" -#include "PxRigidDynamic.h" - -using namespace physx; - - -BlastFamilyBoxes::BlastFamilyBoxes(PhysXController& physXController, ExtPxManager& pxManager, Renderer& renderer, const BlastAssetBoxes& blastAsset, const BlastAsset::ActorDesc& desc) - : BlastFamily(physXController, pxManager, blastAsset), m_renderer(renderer) -{ - // prepare renderables - IRenderMesh* boxRenderMesh = renderer.getPrimitiveRenderMesh(PrimitiveRenderMeshType::Box); - RenderMaterial* primitiveRenderMaterial = physXController.getPrimitiveRenderMaterial(); - - const ExtPxAsset* pxAsset = m_blastAsset.getPxAsset(); - const uint32_t chunkCount = pxAsset->getChunkCount(); - const ExtPxChunk* chunks = pxAsset->getChunks(); - const ExtPxSubchunk* subChunks = pxAsset->getSubchunks(); - m_chunkRenderables.resize(chunkCount); - for (uint32_t i = 0; i < chunkCount; i++) - { - Renderable* renderable = renderer.createRenderable(*boxRenderMesh, *primitiveRenderMaterial); - renderable->setHidden(true); - renderable->setScale(subChunks[chunks[i].firstSubchunkIndex].geometry.scale.scale); - m_chunkRenderables[i] = renderable; - } - - // initialize in position - initialize(desc); -} - -BlastFamilyBoxes::~BlastFamilyBoxes() -{ - for (uint32_t i = 0; i < m_chunkRenderables.size(); i++) - { - m_renderer.removeRenderable(m_chunkRenderables[i]); - } -} - -void BlastFamilyBoxes::onActorCreated(const ExtPxActor& actor) -{ - DirectX::XMFLOAT4 color = getRandomPastelColor(); - - const uint32_t* chunkIndices = actor.getChunkIndices(); - uint32_t chunkCount = actor.getChunkCount(); - for (uint32_t i = 0; i < chunkCount; i++) - { - const uint32_t chunkIndex = chunkIndices[i]; - m_chunkRenderables[chunkIndex]->setHidden(false); - m_chunkRenderables[chunkIndex]->setColor(color); - } -} - -void BlastFamilyBoxes::onActorUpdate(const ExtPxActor& actor) -{ - const ExtPxChunk* chunks = m_blastAsset.getPxAsset()->getChunks(); - const ExtPxSubchunk* subChunks = m_blastAsset.getPxAsset()->getSubchunks(); - const uint32_t* chunkIndices = actor.getChunkIndices(); - uint32_t chunkCount = actor.getChunkCount(); - for (uint32_t i = 0; i < chunkCount; i++) - { - const uint32_t chunkIndex = chunkIndices[i]; - m_chunkRenderables[chunkIndex]->setTransform(actor.getPhysXActor().getGlobalPose() * subChunks[chunks[chunkIndex].firstSubchunkIndex].transform); - } -} - -void BlastFamilyBoxes::onActorDestroyed(const ExtPxActor& actor) -{ - const uint32_t* chunkIndices = actor.getChunkIndices(); - uint32_t chunkCount = actor.getChunkCount(); - for (uint32_t i = 0; i < chunkCount; i++) - { - m_chunkRenderables[chunkIndices[i]]->setHidden(true); - } - -} diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyBoxes.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyBoxes.h deleted file mode 100644 index b67ec31..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyBoxes.h +++ /dev/null @@ -1,55 +0,0 @@ -// 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 - -#include "BlastFamily.h" - -class BlastAssetBoxes; -class Renderable; - - -class BlastFamilyBoxes : public BlastFamily -{ -public: - BlastFamilyBoxes(PhysXController& physXController, ExtPxManager& pxManager, Renderer& renderer, const BlastAssetBoxes& blastAsset, const BlastAsset::ActorDesc& desc); - virtual ~BlastFamilyBoxes(); - -protected: - virtual void onActorCreated(const ExtPxActor& actor); - virtual void onActorUpdate(const ExtPxActor& actor); - virtual void onActorDestroyed(const ExtPxActor& actor); - -private: - Renderer& m_renderer; - std::vector<Renderable*> m_chunkRenderables; -}; - - -#endif //BLAST_FAMILY_BOXES
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSimple.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSimple.cpp deleted file mode 100644 index 4ca8b87..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSimple.cpp +++ /dev/null @@ -1,1071 +0,0 @@ -// 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" -#include "DeviceManager.h" -#include "Renderer.h" -#include "NvBlastExtPxAsset.h" -#include "NvBlastExtPxActor.h" -#include "NvBlastTkActor.h" -#include "NvBlastTkAsset.h" -#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 -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -class SimpleRenderMesh : public IRenderMesh -{ -public: - SimpleRenderMesh(const SimpleMesh* mesh, int renderableId) : m_mesh(mesh) - { - mUniqueId = renderableId; - - m_device = GetDeviceManager()->GetDevice(); - - m_inputDesc.push_back({ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }); - m_inputDesc.push_back({ "VERTEX_NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }); - m_inputDesc.push_back({ "FACE_NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 }); - m_inputDesc.push_back({ "TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 36, D3D11_INPUT_PER_VERTEX_DATA, 0 }); - m_inputDesc.push_back({ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 48, D3D11_INPUT_PER_VERTEX_DATA, 0 }); - m_inputDesc.push_back({ "TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }); - - m_numVertices = static_cast<uint32_t>(mesh->vertices.size()); - m_numFaces = static_cast<uint32_t>(mesh->indices.size()); - - // VB - { - D3D11_SUBRESOURCE_DATA vertexBufferData; - ZeroMemory(&vertexBufferData, sizeof(vertexBufferData)); - vertexBufferData.pSysMem = mesh->vertices.data(); - - D3D11_BUFFER_DESC bufferDesc; - memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC)); - bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; - bufferDesc.ByteWidth = sizeof(SimpleMesh::Vertex) * m_numVertices; - bufferDesc.CPUAccessFlags = 0; - bufferDesc.MiscFlags = 0; - bufferDesc.Usage = D3D11_USAGE_IMMUTABLE; - - V(m_device->CreateBuffer(&bufferDesc, &vertexBufferData, &m_vertexBuffer)); - } - - // Health Buffer - { - // fill with 1.0f initially - std::vector<float> healths(mesh->vertices.size()); - std::fill(healths.begin(), healths.end(), 1.0f); - - D3D11_SUBRESOURCE_DATA vertexBufferData; - ZeroMemory(&vertexBufferData, sizeof(vertexBufferData)); - vertexBufferData.pSysMem = healths.data(); - - D3D11_BUFFER_DESC bufferDesc; - memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC)); - bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; - bufferDesc.ByteWidth = (uint32_t)(sizeof(float) * m_numVertices); - bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - bufferDesc.MiscFlags = 0; - bufferDesc.Usage = D3D11_USAGE_DYNAMIC; - - V(m_device->CreateBuffer(&bufferDesc, &vertexBufferData, &m_healthBuffer)); - } - - // IB - if (m_numFaces) - { - D3D11_SUBRESOURCE_DATA indexBufferData; - - ZeroMemory(&indexBufferData, sizeof(indexBufferData)); - indexBufferData.pSysMem = mesh->indices.data(); - - D3D11_BUFFER_DESC bufferDesc; - - memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC)); - bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; - bufferDesc.ByteWidth = sizeof(uint16_t) * m_numFaces; - bufferDesc.CPUAccessFlags = 0; - bufferDesc.MiscFlags = 0; - bufferDesc.Usage = D3D11_USAGE_IMMUTABLE; - - V(m_device->CreateBuffer(&bufferDesc, &indexBufferData, &m_indexBuffer)); - } - } - - ~SimpleRenderMesh() - { - SAFE_RELEASE(m_healthBuffer); - SAFE_RELEASE(m_vertexBuffer); - SAFE_RELEASE(m_indexBuffer); - } - - - void render(ID3D11DeviceContext& context) const - { - context.IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - - UINT strides[2] = { sizeof(SimpleMesh::Vertex), sizeof(float) }; - UINT offsets[2] = { 0 }; - ID3D11Buffer* buffers[2] = { m_vertexBuffer, m_healthBuffer }; - context.IASetVertexBuffers(0, 2, buffers, strides, offsets); - - - context.IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R16_UINT, 0); - - if (m_indexBuffer) - context.DrawIndexed(m_numFaces, 0, 0); - else - context.Draw(m_numVertices, 0); - } - - const std::vector<D3D11_INPUT_ELEMENT_DESC>& getInputElementDesc() const { return m_inputDesc; } - - const SimpleMesh* getMesh() { return m_mesh; } - - void updateHealths(const std::vector<float>& healths) - { - ID3D11DeviceContext* context; - m_device->GetImmediateContext(&context); - - // update buffer - { - D3D11_MAPPED_SUBRESOURCE mappedRead; - V(context->Map(m_healthBuffer, 0, D3D11_MAP_WRITE_DISCARD, NULL, &mappedRead)); - memcpy(mappedRead.pData, healths.data(), sizeof(float) * healths.size()); - context->Unmap(m_healthBuffer, 0); - } - - } - -// Add By Lixu Begin - void setScale(PxMat44 scale, bool replace) - { - std::vector<SimpleMesh::Vertex> newVertex(m_numVertices); - for (int v = 0; v < m_numVertices; v++) - { - newVertex[v] = m_mesh->vertices[v]; - newVertex[v].position = scale.transform(newVertex[v].position); - } - - D3D11_SUBRESOURCE_DATA vertexBufferData; - ZeroMemory(&vertexBufferData, sizeof(vertexBufferData)); - vertexBufferData.pSysMem = newVertex.data(); - - D3D11_BUFFER_DESC bufferDesc; - memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC)); - bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; - bufferDesc.ByteWidth = sizeof(SimpleMesh::Vertex) * m_numVertices; - bufferDesc.CPUAccessFlags = 0; - bufferDesc.MiscFlags = 0; - bufferDesc.Usage = D3D11_USAGE_IMMUTABLE; - - ID3D11Buffer* pBuffer = m_vertexBuffer; - V(m_device->CreateBuffer(&bufferDesc, &vertexBufferData, &m_vertexBuffer)); - if (NULL != pBuffer) - { - pBuffer->Release(); - pBuffer = NULL; - } - - if (replace) - { - memcpy((void*)m_mesh->vertices.data(), newVertex.data(), bufferDesc.ByteWidth); - } - } -// Add By Lixu End - -private: - - ID3D11Device* m_device; - - ID3D11Buffer* m_vertexBuffer; - ID3D11Buffer* m_healthBuffer; - ID3D11Buffer* m_indexBuffer; - uint32_t m_numFaces; - uint32_t m_numVertices; - - std::vector<D3D11_INPUT_ELEMENT_DESC> m_inputDesc; - - const SimpleMesh* m_mesh; -}; - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// BlastFamilyModelSimple -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -BlastFamilyModelSimple::BlastFamilyModelSimple(PhysXController& physXController, ExtPxManager& pxManager, Renderer& renderer, const BlastAssetModelSimple& blastAsset, const BlastAsset::ActorDesc& desc) - : BlastFamily(physXController, pxManager, blastAsset), m_renderer(renderer) -{ - // 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(); - - // model - const BlastModel& model = blastAsset.getModel(); - - // create render mesh for every BlastModel::Chunk::Mesh and renderable with it - const std::vector<BlastModel::Chunk>& modelChunks = model.chunks; - m_chunks.resize(modelChunks.size()); - for (uint32_t chunkIndex = 0; chunkIndex < modelChunks.size(); chunkIndex++) - { - const std::vector<BlastModel::Chunk::Mesh>& meshes = modelChunks[chunkIndex].meshes; - std::vector<SimpleRenderMesh*>& renderMeshes = m_chunks[chunkIndex].renderMeshes; - std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables; -// Add By Lixu Begin - std::vector<Renderable*>& ex_Renderables = m_chunks[chunkIndex].ex_Renderables; - 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()); - - int renderableId = Renderable::getRenderableId(mUniqueId, chunkIndex); - - for (uint32_t i = 0; i < meshes.size(); i++) - { - renderMeshes[i] = new SimpleRenderMesh(&meshes[i].mesh, renderableId); - - uint32_t materialIndex = model.chunks[chunkIndex].meshes[i].materialIndex; - - 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) - { - ex_Renderables.push_back(renderable); - } - else if (materialIndex == 1) - { - in_Renderables.push_back(renderable); - } -// Add By Lixu End - } - } - -// Add By Lixu Begin - initTransform(desc.transform); -// Add By Lixu End - - // initialize in position - initialize(desc); -} - -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<std::string>& materials = blastAsset.getRenderMaterials(); - int materialSize = materials.size(); - for (int ms = 0; ms < materialSize; ms++) - { - RenderMaterial* pRenderMaterial = pSampleManager->getRenderMaterial(materials[ms]); - pRenderMaterial->clearRelatedRenderables(); - } - - // 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) - { - 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 - - // release all chunks - for (uint32_t chunkIndex = 0; chunkIndex < m_chunks.size(); chunkIndex++) - { - std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables; - for (uint32_t i = 0; i < m_chunks[chunkIndex].renderables.size(); i++) - { - m_renderer.removeRenderable(m_chunks[chunkIndex].renderables[i]); - SAFE_DELETE(m_chunks[chunkIndex].renderMeshes[i]); - } - } - // Add By Lixu Begin - //PrintActors(SampleManager::ins()->getPhysXController()); - // Add By Lixu End -} - -void BlastFamilyModelSimple::onActorCreated(const ExtPxActor& actor) -{ - // separate color for every material - std::vector<DirectX::XMFLOAT4> colors; - - const uint32_t* chunkIndices = actor.getChunkIndices(); - uint32_t chunkCount = actor.getChunkCount(); - for (uint32_t i = 0; i < chunkCount; i++) - { - uint32_t chunkIndex = chunkIndices[i]; - std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables; - for (uint32_t r = 0; r < renderables.size(); r++) - { - if (colors.size() <= r) - colors.push_back(getRandomPastelColor()); - if (SampleManager::ins()->IsSimulating()) - { - renderables[r]->setHidden(false); - } - else - { - renderables[r]->setHidden(!_getBPPChunkVisible(chunkIndex)); - } -// renderables[r]->setColor(colors[r]); - - m_VisibleChangedChunks[chunkIndex] = true; - } - } -} - -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) - { - std::vector<PxShape*> shapes(shapesCount); - actor.getPhysXActor().getShapes(&shapes[0], shapesCount); - PxShape* shape = shapes[0]; - lp = shape->getLocalPose(); - } -// Add By Lixu End - - const ExtPxChunk* chunks = m_blastAsset.getPxAsset()->getChunks(); - const ExtPxSubchunk* subChunks = m_blastAsset.getPxAsset()->getSubchunks(); - const uint32_t* chunkIndices = actor.getChunkIndices(); - uint32_t chunkCount = actor.getChunkCount(); - for (uint32_t i = 0; i < chunkCount; i++) - { - uint32_t chunkIndex = chunkIndices[i]; - std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables; - for (Renderable* r : renderables) - { -// Add By Lixu Begin - 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 - } -} - -void BlastFamilyModelSimple::onActorDestroyed(const ExtPxActor& actor) -{ - const uint32_t* chunkIndices = actor.getChunkIndices(); - uint32_t chunkCount = actor.getChunkCount(); - for (uint32_t i = 0; i < chunkCount; i++) - { - uint32_t chunkIndex = chunkIndices[i]; - std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables; - for (Renderable* r : renderables) - { - r->setHidden(true); - - m_VisibleChangedChunks[chunkIndex] = false; - } - } -} - -void BlastFamilyModelSimple::onActorHealthUpdate(const ExtPxActor& actor) -{ - TkActor& tkActor = actor.getTkActor(); - const TkAsset* tkAsset = tkActor.getAsset(); - - const float* bondHealths = tkActor.getBondHealths(); - uint32_t nodeCount = tkActor.getGraphNodeCount(); - if (nodeCount == 0) // subsupport chunks don't have graph nodes - return; - - std::vector<uint32_t> nodes(tkActor.getGraphNodeCount()); - tkActor.getGraphNodeIndices(nodes.data(), static_cast<uint32_t>(nodes.size())); - - const NvBlastChunk* chunks = tkAsset->getChunks(); - const NvBlastBond* bonds = tkAsset->getBonds(); - - const NvBlastSupportGraph graph = tkAsset->getGraph(); - const float bondHealthMax = m_blastAsset.getBondHealthMax(); - - std::vector<float> healthBuffer; - - for (uint32_t node0 : nodes) - { - uint32_t chunkIndex = graph.chunkIndices[node0]; - - if (chunkIndex >= m_chunks.size()) - continue; - - std::vector<SimpleRenderMesh*>& meshes = m_chunks[chunkIndex].renderMeshes; - const auto& renderables = m_chunks[chunkIndex].renderables; - for (uint32_t i = 0; i < meshes.size(); ++i) - { - if(renderables[i]->isHidden()) - continue; - - SimpleRenderMesh* renderMesh = meshes[i]; - - const SimpleMesh* mesh = renderMesh->getMesh(); - healthBuffer.resize(mesh->vertices.size()); - - for (uint32_t vertexIndex = 0; vertexIndex < mesh->vertices.size(); vertexIndex++) - { - PxVec3 position = mesh->vertices[vertexIndex].position; - float health = 0.0f; - float healthDenom = 0.0f; - - for (uint32_t adjacencyIndex = graph.adjacencyPartition[node0]; adjacencyIndex < graph.adjacencyPartition[node0 + 1]; adjacencyIndex++) - { - uint32_t node1 = graph.adjacentNodeIndices[adjacencyIndex]; - uint32_t bondIndex = graph.adjacentBondIndices[adjacencyIndex]; - float bondHealth = PxClamp(bondHealths[bondIndex] / bondHealthMax, 0.0f, 1.0f); - const NvBlastBond& solverBond = bonds[bondIndex]; - const PxVec3& centroid = reinterpret_cast<const PxVec3&>(solverBond.centroid); - - float factor = 1.0f / (centroid - position).magnitudeSquared(); - - health += bondHealth * factor; - healthDenom += factor; - } - - healthBuffer[vertexIndex] = healthDenom > 0.0f ? health / healthDenom : 1.0f; - } - - renderMesh->updateHealths(healthBuffer); - } - } -} - -// Add By Lixu Begin -bool BlastFamilyModelSimple::find(const PxActor& actor) -{ - 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) - { - 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 - { - 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(selected); - - if (!selectionDepthTest && selected) - { - r->setDepthTest(false); - } - else - { - r->setDepthTest(true); - } - } -} - -void BlastFamilyModelSimple::setChunkSelected(std::vector<uint32_t> depths, bool selected) -{ - for (size_t i = 0; i < depths.size(); ++i) - { - const std::vector<uint32_t> indexes = m_blastAsset.getChunkIndexesByDepth(depths[i]); - for (size_t j = 0; j < indexes.size(); ++j) - { - setChunkSelected(indexes[j], selected); - } - } -} - -void BlastFamilyModelSimple::clearChunksSelected() -{ - size_t count = m_chunks.size(); - for (size_t chunkIndex = 0; chunkIndex < count; ++chunkIndex) - { - std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables; - for (Renderable* r : renderables) - { - r->setSelected(false); - r->setDepthTest(true); - r->setHighlight(false); - } - } -} - -bool BlastFamilyModelSimple::isChunkSelected(uint32_t chunk) -{ - if (chunk > m_chunks.size()) - return false; - - std::vector<Renderable*>& renderables = m_chunks[chunk].renderables; - for (Renderable* r : renderables) - { - for (Renderable* r : renderables) - { - if (r->isSelected()) - { - return true; - } - } - } - - return false; -} - -std::vector<uint32_t> BlastFamilyModelSimple::getSelectedChunks() -{ - std::vector<uint32_t> selectedChunks; - size_t count = m_chunks.size(); - for (size_t chunkIndex = 0; chunkIndex < count; ++chunkIndex) - { - std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables; - for (Renderable* r : renderables) - { - if (r->isSelected()) - { - selectedChunks.push_back(chunkIndex); - break; - } - } - } - return selectedChunks; -} - -void BlastFamilyModelSimple::setActorScale(const PxActor& actor, PxMat44& scale, bool replace) -{ - uint32_t chunkIndex = getChunkIndexByPxActor(actor); - if (-1 == chunkIndex) - return; - 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) - { - 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); - } - } - } -} - -bool BlastFamilyModelSimple::isChunkVisible(uint32_t chunkIndex) -{ - if (chunkIndex < 0 || chunkIndex >= m_chunks.size()) - { - return false; - } - - bool bVisible = false; - std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables; - if (renderables.size() > 0) - { - bVisible = !renderables[0]->isHidden(); - } - return bVisible; -} - -void BlastFamilyModelSimple::setChunkVisible(uint32_t chunkIndex, bool bVisible) -{ - if (chunkIndex < 0 || chunkIndex >= m_chunks.size()) - { - return; - } - - std::vector<Renderable*>& renderables = m_chunks[chunkIndex].renderables; - for (Renderable* r : renderables) - { - r->setHidden(!bVisible); - } -} - -void BlastFamilyModelSimple::setChunkVisible(std::vector<uint32_t> depths, bool bVisible) -{ - for (size_t i = 0; i < depths.size(); ++i) - { - const std::vector<uint32_t> indexes = m_blastAsset.getChunkIndexesByDepth(depths[i]); - for (size_t j = 0; j < indexes.size(); ++j) - { - setChunkVisible(indexes[j], bVisible); - } - } -} - -void BlastFamilyModelSimple::initTransform(physx::PxTransform t) -{ - BlastFamily::initTransform(t); - int chunkSize = m_chunks.size(); - for (int i = 0; i < chunkSize; i++) - { - std::vector<Renderable*>& renderables = m_chunks[i].renderables; - for (Renderable* r : renderables) - { - 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) -{ - *ppRenderMaterial = nullptr; - - int chunkSize = m_chunks.size(); - if (chunkSize == 0) - { - return; - } - - if (externalSurface) - { - for (int i = 0; i < chunkSize; i++) - { - std::vector<Renderable*>& renderables = m_chunks[i].ex_Renderables; - if (renderables.size() > 0) - { - RenderMaterial& m = renderables[0]->getMaterial(); - *ppRenderMaterial = &m; - return; - } - } - } - else - { - for (int i = 0; i < chunkSize; i++) - { - std::vector<Renderable*>& renderables = m_chunks[i].in_Renderables; - if (renderables.size() > 0) - { - RenderMaterial& m = renderables[0]->getMaterial(); - *ppRenderMaterial = &m; - return; - } - } - } -} - -void BlastFamilyModelSimple::setMaterial(RenderMaterial* pRenderMaterial, bool externalSurface) -{ - RenderMaterial* p = pRenderMaterial; - if (p == nullptr) - { - p = RenderMaterial::getDefaultRenderMaterial(); - } - - int chunkSize = m_chunks.size(); - if (externalSurface) - { - for (int i = 0; i < chunkSize; i++) - { - std::vector<Renderable*>& renderables = m_chunks[i].ex_Renderables; - for (Renderable* r : renderables) - { - r->setMaterial(*p); - } - } - } - else - { - for (int i = 0; i < chunkSize; i++) - { - std::vector<Renderable*>& renderables = m_chunks[i].in_Renderables; - for (Renderable* r : renderables) - { - r->setMaterial(*p); - } - } - } -} - -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 deleted file mode 100644 index c86242a..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSimple.h +++ /dev/null @@ -1,111 +0,0 @@ -// 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 - -#include "BlastFamily.h" -#include "BlastAssetModelSimple.h" - -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 -{ -public: - //////// ctor //////// - - BlastFamilyModelSimple(PhysXController& physXController, ExtPxManager& pxManager, Renderer& renderer, const BlastAssetModelSimple& blastAsset, const BlastAsset::ActorDesc& desc); - virtual ~BlastFamilyModelSimple(); - -// Add By Lixu Begin - 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 isChunkSelected(uint32_t chunk); - virtual std::vector<uint32_t> getSelectedChunks(); - 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: - //////// abstract implementation //////// - - virtual void onActorCreated(const ExtPxActor& actor); - virtual void onActorUpdate(const ExtPxActor& actor); - virtual void onActorDestroyed(const ExtPxActor& actor); - virtual void onActorHealthUpdate(const ExtPxActor& pxActor); - -private: - // Add By Lixu Begin - bool _getBPPChunkVisible(uint32_t chunkIndex); - // Add By Lixu End - - //////// internal data //////// - - Renderer& m_renderer; - - struct Chunk - { - std::vector<SimpleRenderMesh*> renderMeshes; - std::vector<Renderable*> renderables; -// Add By Lixu Begin - std::vector<Renderable*> ex_Renderables; - std::vector<Renderable*> in_Renderables; -// Add By Lixu End - }; - - 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 -}; - - -#endif //BLAST_FAMILY_MODEL_SIMPLE_H
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSkinned.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSkinned.cpp deleted file mode 100644 index a0319ff..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSkinned.cpp +++ /dev/null @@ -1,185 +0,0 @@ -// 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" -#include "Renderer.h" -#include "SkinnedRenderMesh.h" -#include "NvBlastExtPxAsset.h" -#include "NvBlastExtPxActor.h" -#include "NvBlastTkActor.h" -#include "PxRigidDynamic.h" - -using namespace physx; - -BlastFamilyModelSkinned::BlastFamilyModelSkinned(PhysXController& physXController, ExtPxManager& pxManager, Renderer& renderer, const BlastAssetModelSkinned& blastAsset, const BlastAsset::ActorDesc& desc) - : BlastFamily(physXController, pxManager, blastAsset), m_renderer(renderer), m_visibleActorsDirty(true) -{ - // materials - auto materials = blastAsset.getRenderMaterials(); - - const BlastModel& model = blastAsset.getModel(); - - // finalize (create) sub model - auto finalizeSubModelFunction = [&](SubModel* subModel, std::vector<const SimpleMesh*>& subModelMeshes, RenderMaterial& renderMaterial) - { - subModel->skinnedRenderMesh = new SkinnedRenderMesh(subModelMeshes); - subModel->renderable = renderer.createRenderable(*subModel->skinnedRenderMesh, renderMaterial); - subModel->renderable->setColor(getRandomPastelColor()); - }; - - // create at least one submodel per every material (if mesh count is too high, more then one sub model per material to be created) - SubModel* subModel = nullptr; - std::vector<const SimpleMesh*> subModelMeshes; - subModelMeshes.reserve(model.chunks.size()); - for (uint32_t materialIndex = 0; materialIndex < model.materials.size(); materialIndex++) - { - for (uint32_t chunkIndex = 0; chunkIndex < model.chunks.size(); chunkIndex++) - { - const BlastModel::Chunk& chunk = model.chunks[chunkIndex]; - for (const BlastModel::Chunk::Mesh& mesh : chunk.meshes) - { - if (mesh.materialIndex == materialIndex) - { - // init new submodel? - if (subModel == nullptr) - { - m_subModels.push_back(SubModel()); - subModel = &m_subModels.back(); - subModel->chunkIdToBoneMap.resize(model.chunks.size()); - std::fill(subModel->chunkIdToBoneMap.begin(), subModel->chunkIdToBoneMap.end(), SubModel::INVALID_BONE_ID); - subModelMeshes.clear(); - } - - // add mesh to map and list - subModel->chunkIdToBoneMap[chunkIndex] = (uint32_t)subModelMeshes.size(); - subModelMeshes.push_back(&(mesh.mesh)); - - // mesh reached limit? - if (subModelMeshes.size() == SkinnedRenderMesh::MeshesCountMax) - { - finalizeSubModelFunction(subModel, subModelMeshes, *materials[materialIndex]); - subModel = nullptr; - } - } - } - } - - // finalize subModel for this material - if (subModel && subModelMeshes.size() > 0) - { - finalizeSubModelFunction(subModel, subModelMeshes, *materials[materialIndex]); - subModel = nullptr; - } - } - - // reserve for scratch - m_visibleBones.reserve(model.chunks.size()); - m_visibleBoneTransforms.reserve(model.chunks.size()); - - // initialize in position - initialize(desc); -} - -BlastFamilyModelSkinned::~BlastFamilyModelSkinned() -{ - for (uint32_t subModelIndex = 0; subModelIndex < m_subModels.size(); subModelIndex++) - { - m_renderer.removeRenderable(m_subModels[subModelIndex].renderable); - SAFE_DELETE(m_subModels[subModelIndex].skinnedRenderMesh); - } -} - -void BlastFamilyModelSkinned::onActorCreated(const ExtPxActor& actor) -{ - m_visibleActors.insert(&actor); - m_visibleActorsDirty = true; -} - -void BlastFamilyModelSkinned::onActorUpdate(const ExtPxActor& actor) -{ -} - -void BlastFamilyModelSkinned::onActorDestroyed(const ExtPxActor& actor) -{ - m_visibleActors.erase(&actor); - m_visibleActorsDirty = true; -} - -void BlastFamilyModelSkinned::onUpdate() -{ - // visible actors changed this frame? - if (m_visibleActorsDirty) - { - for (const SubModel& model : m_subModels) - { - // pass visible chunks list to render mesh - m_visibleBones.clear(); - for (const ExtPxActor* actor : m_visibleActors) - { - const uint32_t* chunkIndices = actor->getChunkIndices(); - uint32_t chunkCount = actor->getChunkCount(); - for (uint32_t i = 0; i < chunkCount; ++i) - { - uint32_t chunkIndex = chunkIndices[i]; - uint32_t boneIndex = model.chunkIdToBoneMap[chunkIndex]; - if (boneIndex != SubModel::INVALID_BONE_ID) - { - m_visibleBones.push_back(boneIndex); - } - } - } - model.skinnedRenderMesh->updateVisibleMeshes(m_visibleBones); - } - - m_visibleActorsDirty = false; - } - - // update and pass chunk transforms - const ExtPxChunk* chunks = m_blastAsset.getPxAsset()->getChunks(); - const ExtPxSubchunk* subChunks = m_blastAsset.getPxAsset()->getSubchunks(); - for (const SubModel& model : m_subModels) - { - m_visibleBoneTransforms.clear(); - for (const ExtPxActor* actor : m_visibleActors) - { - const uint32_t* chunkIndices = actor->getChunkIndices(); - uint32_t chunkCount = actor->getChunkCount(); - for (uint32_t i = 0; i < chunkCount; ++i) - { - uint32_t chunkIndex = chunkIndices[i]; - uint32_t boneIndex = model.chunkIdToBoneMap[chunkIndex]; - if (boneIndex != SubModel::INVALID_BONE_ID) - { - m_visibleBoneTransforms.push_back(PxMat44(actor->getPhysXActor().getGlobalPose() * subChunks[chunks[chunkIndex].firstSubchunkIndex].transform)); - } - } - } - model.skinnedRenderMesh->updateVisibleMeshTransforms(m_visibleBoneTransforms); - } -} diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSkinned.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSkinned.h deleted file mode 100644 index d76b18e..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFamilyModelSkinned.h +++ /dev/null @@ -1,81 +0,0 @@ -// 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 - -#include "BlastFamily.h" -#include "BlastAssetModelSkinned.h" - -class SkinnedRenderMesh; -class Renderable; - -class BlastFamilyModelSkinned : public BlastFamily -{ -public: - //////// ctor //////// - - BlastFamilyModelSkinned(PhysXController& physXController, ExtPxManager& pxManager, Renderer& renderer, const BlastAssetModelSkinned& blastAsset, const BlastAsset::ActorDesc& desc); - virtual ~BlastFamilyModelSkinned(); - -protected: - //////// abstract implementation //////// - - virtual void onActorCreated(const ExtPxActor& actor); - virtual void onActorUpdate(const ExtPxActor& actor); - virtual void onActorDestroyed(const ExtPxActor& actor); - - virtual void onUpdate(); - -private: - //////// internal data //////// - - Renderer& m_renderer; - - struct SubModel - { - static const uint32_t INVALID_BONE_ID = ~(uint32_t)0; - - Renderable* renderable = nullptr; - SkinnedRenderMesh* skinnedRenderMesh = nullptr; - std::vector<uint32_t> chunkIdToBoneMap; - }; - std::vector<SubModel> m_subModels; - - std::set<const ExtPxActor*> m_visibleActors; - bool m_visibleActorsDirty; - - //////// scratch buffers //////// - - std::vector<uint32_t> m_visibleBones; - std::vector<PxMat44> m_visibleBoneTransforms; - -}; - - -#endif //BLAST_FAMILY_MODEL_SKINNED_H
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFractureTool.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFractureTool.cpp deleted file mode 100644 index cbd299b..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFractureTool.cpp +++ /dev/null @@ -1,259 +0,0 @@ -// 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> -#include <BlastAsset.h> -#include <NvBlastExtPxAsset.h> -#include <NvBlastTkAsset.h> -#include "NvBlastExtAuthoring.h" -#include "NvBlastExtAuthoringMeshImpl.h" -void BlastFractureTool::free() -{ - std::vector<Nv::Blast::Mesh*>::iterator it; - for (it = chunkMeshes.begin(); it != chunkMeshes.end(); it++) - { - delete (*it); - (*it) = nullptr; - } - chunkMeshes.clear(); -} - -void BlastFractureTool::setSourceAsset(const BlastAsset* pBlastAsset) -{ - free(); - - BlastAssetModel* pBlastAssetModel = (BlastAssetModel*)pBlastAsset; - const BlastModel& blastModel = pBlastAssetModel->getModel(); - const std::vector<BlastModel::Chunk>& chunks = blastModel.chunks; - int chunkSize = chunks.size(); - if (chunkSize == 0) - { - return; - } - - chunkMeshes.resize(chunkSize, nullptr); - for (int cs = 0; cs < chunkSize; cs++) - { - const BlastModel::Chunk& chunk = chunks[cs]; - 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); - } - - PxVec3* nr = (!normals.empty()) ? normals.data() : 0; - PxVec2* uvp = (!uv.empty()) ? uv.data() : 0; - Nv::Blast::Mesh* pMesh = NvBlastExtAuthoringCreateMesh( - positions.data(), nr, uvp, static_cast<uint32_t>(positions.size()), - ind.data(), static_cast<uint32_t>(ind.size())); - - int curFaceIndex = 0; - int curFaceBreakPoint = faceBreakPoint[curFaceIndex]; - uint32_t curMaterialIndex = materialIndexes[curFaceIndex]; - for (int fc = 0; fc < pMesh->getFacetCount(); fc++) - { - if (fc >= curFaceBreakPoint) - { - curFaceIndex++; - curFaceBreakPoint += faceBreakPoint[curFaceIndex]; - curMaterialIndex = materialIndexes[curFaceIndex]; - } - - Facet* pFacet = const_cast<Facet*>(pMesh->getFacet(fc)); - pFacet->materialId = curMaterialIndex; - } - - chunkMeshes[cs] = pMesh; - } - - const ExtPxAsset* pExtPxAsset = pBlastAsset->getPxAsset(); - const TkAsset& tkAsset = pExtPxAsset->getTkAsset(); - - std::vector<int32_t> parentIds; - parentIds.resize(chunkSize); - parentIds.assign(chunkSize, -1); - { - const NvBlastChunk* pNvBlastChunk = tkAsset.getChunks(); - for (uint32_t i = 0; i < chunkSize; ++i) - { - parentIds[i] = pNvBlastChunk[i].parentChunkIndex; - } - } - std::vector<bool> isLeafs; - isLeafs.resize(chunkSize); - isLeafs.assign(chunkSize, false); - { - const NvBlastSupportGraph supportGraph = tkAsset.getGraph(); - for (uint32_t i = 0; i < supportGraph.nodeCount; ++i) - { - const uint32_t chunkIndex = supportGraph.chunkIndices[i]; - 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 MeshImpl(*reinterpret_cast<const MeshImpl*>(chunkMeshes[cs])); - mChunkData[cs].parent = parentIds[cs]; - mChunkData[cs].chunkId = mChunkIdCounter++; - mChunkData[cs].isLeaf = isLeafs[cs]; - - mesh = mChunkData[cs].meshData; - Nv::Blast::Vertex* verticesBuffer = const_cast<Nv::Blast::Vertex*>(mesh->getVertices()); - for (uint32_t i = 0; i < mesh->getVerticesCount(); ++i) - { - verticesBuffer[i].p = (verticesBuffer[i].p - mOffset) * (1.0f / mScaleFactor); - } - PxBounds3& bb = const_cast<PxBounds3&>(mesh->getBoundingBox()); - bb.minimum = (bb.minimum - mOffset) * (1.0f / mScaleFactor); - bb.maximum = (bb.maximum - mOffset) * (1.0f / mScaleFactor); - for (uint32_t i = 0; i < mesh->getFacetCount(); ++i) - { - Facet* pFacet = const_cast<Facet*>(mesh->getFacet(i)); - pFacet->materialId = chunkMeshes[cs]->getFacet(i)->materialId; - } - } -} - -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 MeshImpl(*reinterpret_cast<const MeshImpl*>(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]); - - 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 MeshImpl(*reinterpret_cast<const MeshImpl*>(chunkMeshes[cs])); - mChunkData[cs].parent = parentIds[cs]; - mChunkData[cs].chunkId = mChunkIdCounter++; - mChunkData[cs].isLeaf = isLeafs[cs]; - - mesh = mChunkData[cs].meshData; - Nv::Blast::Vertex* verticesBuffer = const_cast<Nv::Blast::Vertex*>(mesh->getVertices()); - for (uint32_t i = 0; i < mesh->getVerticesCount(); ++i) - { - verticesBuffer[i].p = (verticesBuffer[i].p - mOffset) * (1.0f / mScaleFactor); - } - PxBounds3& bb = const_cast<PxBounds3&>(mesh->getBoundingBox()); - bb.minimum = (bb.minimum - mOffset) * (1.0f / mScaleFactor); - bb.maximum = (bb.maximum - mOffset) * (1.0f / mScaleFactor); - for (uint32_t i = 0; i < mesh->getFacetCount(); ++i) - { - Facet* pFacet = const_cast<Facet*>(mesh->getFacet(i)); - pFacet->materialId = chunkMeshes[cs]->getFacet(i)->materialId; - } - } -} - -Nv::Blast::Mesh* BlastFractureTool::getSourceMesh(int32_t chunkId) -{ - if (chunkId < 0 || chunkId >= chunkMeshes.size()) - { - return nullptr; - } - return chunkMeshes[chunkId]; -}
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFractureTool.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFractureTool.h deleted file mode 100644 index 3436551..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastFractureTool.h +++ /dev/null @@ -1,61 +0,0 @@ -// 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 - -#include "NvBlastExtAuthoringFractureToolImpl.h" - -class BlastAsset; -namespace Nv -{ - namespace Blast - { - class Mesh; - } -} - -class BlastFractureTool : public Nv::Blast::FractureToolImpl -{ -public: - 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: - void free(); - - std::vector<Nv::Blast::Mesh*> chunkMeshes; -}; - -#endif //BLAST_FRACTURETOOL_H
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastModel.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastModel.cpp deleted file mode 100644 index 2f00207..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastModel.cpp +++ /dev/null @@ -1,338 +0,0 @@ -// 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" - -// Add By Lixu Begin -//#define TINYOBJLOADER_IMPLEMENTATION -// Add By Lixu End -#include "tiny_obj_loader.h" -#include "MathUtil.h" -#include "NvBlastExtExporter.h" -#include "NvBlastGlobals.h" - -using namespace physx; - -void computeFacenormalByPosition( - physx::PxVec3 p0, physx::PxVec3 p1, physx::PxVec3 p2, - physx::PxVec3& facenormal) -{ - physx::PxVec3 p01 = p1 - p0; - physx::PxVec3 p02 = p2 - p0; - - facenormal.x = p01.y * p02.z - p01.z * p02.y; - facenormal.y = p01.z * p02.x - p01.x * p02.z; - facenormal.z = p01.x * p02.y - p01.y * p02.x; - - facenormal = -facenormal.getNormalized(); -} - -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 - - - std::shared_ptr<Nv::Blast::IFbxFileReader> rdr(NvBlastExtExporterCreateFbxFileReader(), [](Nv::Blast::IFbxFileReader* p) {p->release(); }); - rdr->loadFromFile(path); - if (rdr->getBoneCount() == 0) - { - return nullptr; - } - - model->chunks.resize(rdr->getBoneCount()); - - model->materials.push_back(BlastModel::Material()); - - - /** - Produce buffers of appropriate for AssetViewer format - */ - uint32_t* infl; - rdr->getBoneInfluences(infl); - for (uint32_t i = 0; i < rdr->getBoneCount(); ++i) - { - std::vector<int32_t> indRemap(rdr->getVerticesCount(), -1); - std::vector<uint32_t> indices; - SimpleMesh cmesh; - for (uint32_t j = 0; j < rdr->getVerticesCount(); ++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->getIdicesCount(); 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; - - NVBLAST_FREE(infl); - } - 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; - std::vector<tinyobj::material_t> mats; - std::string err; - std::string mtlPath; - for (size_t i = strnlen(path, 255) - 1; i >= 0; --i) - { - if (path[i] == '\\' || path[i] == '/') - { - mtlPath.resize(i + 2, 0); - strncpy(&mtlPath[0], path, i + 1); - break; - } - } - - - bool ret = tinyobj::LoadObj(shapes, mats, err, path, mtlPath.data()); - - // can't load? - if (!ret) - return false; - - // one submodel per material - uint32_t materialsCount = (uint32_t)mats.size(); - model->materials.resize(materialsCount); - - // fill submodel materials - for (uint32_t i = 0; i < materialsCount; i++) - { - tinyobj::material_t *pMaterial = &mats[i]; - - // Add By Lixu Begin - if (strcmp(pMaterial->name.c_str(), "neverMat123XABCnever") == 0) - { - model->materials[i].name.clear(); - } - else - { - model->materials[i].name = pMaterial->name; - } - // 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; - } - } - - // estimate - model->chunks.reserve(shapes.size() / materialsCount + 1); - - if (shapes.size() > 0) - { - uint32_t meshIndex = 0; - for (uint32_t m = 0; m < shapes.size(); m++) - { - tinyobj::shape_t& pMesh = shapes[m]; - uint32_t materialIndex; - uint32_t chunkIndex; - sscanf(pMesh.name.data(), "%d_%d", &chunkIndex, &materialIndex); - if (model->chunks.size() <= chunkIndex) - { - model->chunks.resize(chunkIndex + 1); - } - model->chunks[chunkIndex].meshes.push_back(Chunk::Mesh()); - Chunk::Mesh& mesh = model->chunks[chunkIndex].meshes.back(); - - mesh.materialIndex = materialIndex; - SimpleMesh& chunkMesh = mesh.mesh; - - PxVec3 emin(FLT_MAX, FLT_MAX, FLT_MAX); - PxVec3 emax(FLT_MIN, FLT_MIN, FLT_MIN); - - - - // create an index buffer - chunkMesh.indices.resize(pMesh.mesh.indices.size()); - - // Check if all faces are triangles - bool allTriangles = true; - for (uint32_t i = 0; i < pMesh.mesh.num_vertices.size(); ++i) - { - if (pMesh.mesh.num_vertices[i] != 3) - { - allTriangles = false; - break; - } - } - - if (pMesh.mesh.indices.size() > 0 && allTriangles) - { - for (uint32_t i = 0; i < pMesh.mesh.indices.size(); i += 3) - { - chunkMesh.indices[i] = (uint16_t)pMesh.mesh.indices[i + 2]; - chunkMesh.indices[i + 1] = (uint16_t)pMesh.mesh.indices[i + 1]; - chunkMesh.indices[i + 2] = (uint16_t)pMesh.mesh.indices[i]; - } - } - // create vertex buffer - chunkMesh.vertices.resize(pMesh.mesh.positions.size() / 3); - // copy positions - uint32_t indexer = 0; - for (uint32_t i = 0; i < pMesh.mesh.positions.size() / 3; i++) - { - chunkMesh.vertices[i].position.x = pMesh.mesh.positions[indexer]; - chunkMesh.vertices[i].position.y = pMesh.mesh.positions[indexer + 1]; - chunkMesh.vertices[i].position.z = pMesh.mesh.positions[indexer + 2]; - indexer += 3; - // calc min/max - emin = emin.minimum(chunkMesh.vertices[i].position); - emax = emax.maximum(chunkMesh.vertices[i].position); - } - - // copy normals - if (pMesh.mesh.normals.size() > 0) - { - indexer = 0; - for (uint32_t i = 0; i < pMesh.mesh.normals.size() / 3; i++) - { - chunkMesh.vertices[i].normal.x = pMesh.mesh.normals[indexer]; - chunkMesh.vertices[i].normal.y = pMesh.mesh.normals[indexer + 1]; - chunkMesh.vertices[i].normal.z = pMesh.mesh.normals[indexer + 2]; - - indexer += 3; - } - } - - // copy uv - if (pMesh.mesh.texcoords.size() > 0) - { - indexer = 0; - for (uint32_t i = 0; i < pMesh.mesh.texcoords.size() / 2; i++) - { - chunkMesh.vertices[i].uv.x = pMesh.mesh.texcoords[indexer]; - chunkMesh.vertices[i].uv.y = pMesh.mesh.texcoords[indexer + 1]; - indexer += 2; - } - } - - // compute facenormal and 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 facenormal; - computeFacenormalByPosition( - v0.position, v1.position, v2.position, facenormal); - - v0.facenormal = facenormal; - v1.facenormal = facenormal; - v2.facenormal = facenormal; - - 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; - } - } - - return model; -} diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastModel.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastModel.h deleted file mode 100644 index 82d2af8..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastModel.h +++ /dev/null @@ -1,80 +0,0 @@ -// 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 - -#include "Mesh.h" -#include <vector> -#include <memory> - - -class BlastModel; -// Add By Lixu Begin -typedef BlastModel* BlastModelPtr; -// Add By Lixu End - -/** -BlastModel struct represents graphic model. -Now only loading from .obj file is supported. -Can have >=0 materials -Every chunk can have multiple meshes (1 for every material) -*/ -class BlastModel -{ -public: - struct Material - { - std::string name; - std::string diffuseTexture; - float r, g, b, a; - }; - - struct Chunk - { - struct Mesh - { - uint32_t materialIndex; - SimpleMesh mesh; - }; - - std::vector<Mesh> meshes; - }; - - 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() {} -}; - -#endif // ifndef BLAST_MODEL_H
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastReplay.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastReplay.cpp deleted file mode 100644 index 678cec2..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastReplay.cpp +++ /dev/null @@ -1,178 +0,0 @@ -// 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" -#include "NvBlastExtPxManager.h" -#include "NvBlastExtPxFamily.h" -#include "SampleProfiler.h" - - -using namespace std::chrono; - -BlastReplay::BlastReplay() : m_sync(nullptr) -{ - m_sync = ExtSync::create(); - reset(); -} - -BlastReplay::~BlastReplay() -{ - m_sync->release(); - clearBuffer(); -} - -void BlastReplay::addFamily(TkFamily* family) -{ - family->addListener(*m_sync); -} - -void BlastReplay::removeFamily(TkFamily* family) -{ - family->removeListener(*m_sync); -} - -void BlastReplay::startRecording(ExtPxManager& manager, bool syncFamily, bool syncPhysics) -{ - if (isRecording()) - return; - - m_sync->releaseSyncBuffer(); - - if (syncFamily || syncPhysics) - { - std::vector<ExtPxFamily*> families(manager.getFamilyCount()); - manager.getFamilies(families.data(), (uint32_t)families.size()); - for (ExtPxFamily* family : families) - { - if (syncPhysics) - { - m_sync->syncFamily(*family); - } - else if (syncFamily) - { - m_sync->syncFamily(family->getTkFamily()); - } - } - } - - m_isRecording = true; -} - -void BlastReplay::stopRecording() -{ - if (!isRecording()) - return; - - const ExtSyncEvent*const* buffer; - uint32_t size; - m_sync->acquireSyncBuffer(buffer, size); - - clearBuffer(); - m_buffer.resize(size); - for (uint32_t i = 0; i < size; ++i) - { - m_buffer[i] = buffer[i]->clone(); - } - - // TODO: sort by ts ? make sure? - //m_buffer.sort - - m_sync->releaseSyncBuffer(); - - m_isRecording = false; -} - -void BlastReplay::startPlayback(ExtPxManager& manager, TkGroup* group) -{ - if (isPlaying() || !hasRecord()) - return; - - m_isPlaying = true; - m_startTime = steady_clock::now(); - m_nextEventIndex = 0; - m_firstEventTs = m_buffer[0]->timestamp; - m_pxManager = &manager; - m_group = group; -} - -void BlastReplay::stopPlayback() -{ - if (!isPlaying()) - return; - - m_isPlaying = false; - m_pxManager = nullptr; - m_group = nullptr; -} - -void BlastReplay::update() -{ - if (isPlaying()) - { - PROFILER_SCOPED_FUNCTION(); - - auto now = steady_clock::now(); - auto mil = duration_cast<milliseconds>((now - m_startTime)); - bool stop = true; - while (m_nextEventIndex < m_buffer.size()) - { - const ExtSyncEvent* e = m_buffer[m_nextEventIndex]; - auto t = e->timestamp - m_firstEventTs; - if (t < (uint64_t)mil.count()) - { - m_sync->applySyncBuffer(m_pxManager->getFramework(), &e, 1, m_group, m_pxManager); - m_nextEventIndex++; - } - else - { - stop = false; - break; - } - } - - if (stop) - stopPlayback(); - } -} - -void BlastReplay::reset() -{ - m_isPlaying = false; - m_isRecording = false; - m_sync->releaseSyncBuffer(); -} - -void BlastReplay::clearBuffer() -{ - for (auto e : m_buffer) - { - e->release(); - } - m_buffer.clear(); -} diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastReplay.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastReplay.h deleted file mode 100644 index 2c247a5..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/blast/BlastReplay.h +++ /dev/null @@ -1,93 +0,0 @@ -// 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 - -#include "NvBlastExtSync.h" -#include <chrono> - -using namespace Nv::Blast; - -class BlastReplay -{ -public: - BlastReplay(); - ~BlastReplay(); - - bool isRecording() const - { - return m_isRecording; - } - - bool isPlaying() const - { - return m_isPlaying; - } - - bool hasRecord() const - { - return m_buffer.size() > 0; - } - - size_t getEventCount() const - { - return isRecording() ? m_sync->getSyncBufferSize() : m_buffer.size(); - } - - uint32_t getCurrentEventIndex() const - { - return m_nextEventIndex; - } - - void addFamily(TkFamily* family); - void removeFamily(TkFamily* family); - - void startRecording(ExtPxManager& manager, bool syncFamily, bool syncPhysics); - void stopRecording(); - void startPlayback(ExtPxManager& manager, TkGroup* group); - void stopPlayback(); - void update(); - void reset(); - -private: - void clearBuffer(); - - ExtPxManager* m_pxManager; - TkGroup* m_group; - std::chrono::steady_clock::time_point m_startTime; - uint64_t m_firstEventTs; - uint32_t m_nextEventIndex; - bool m_isRecording; - bool m_isPlaying; - ExtSync* m_sync; - std::vector<ExtSyncEvent*> m_buffer; -}; - - -#endif // ifndef BLAST_REPLAY_H
\ No newline at end of file |