From 7115f60b91b5717d90f643fd692010905c7004db Mon Sep 17 00:00:00 2001 From: Bryan Galdrikian Date: Thu, 31 May 2018 11:36:08 -0700 Subject: Blast 1.1.3. See docs/release_notes.txt. --- .../src/ApexDestructibleObjExporter.cpp | 230 +-- .../ApexImporter/src/ApexDestructibleObjExporter.h | 154 +- tools/ApexImporter/src/Main.cpp | 683 ++++----- tools/AuthoringTool/src/AuthoringTool.cpp | 1489 ++++++++++---------- tools/AuthoringTool/src/SimpleRandomGenerator.h | 52 +- tools/CMakeLists.txt | 190 +-- tools/LegacyConverter/src/Main.cpp | 658 ++++----- tools/common/BlastDataExporter.cpp | 282 ++-- tools/common/BlastDataExporter.h | 198 +-- tools/common/Log.cpp | 174 +-- tools/common/Log.h | 300 ++-- tools/common/Utils.cpp | 388 ++--- tools/common/Utils.h | 282 ++-- tools/compiler/cmake/ApexImporter.cmake | 162 +-- tools/compiler/cmake/AuthoringTool.cmake | 170 +-- tools/compiler/cmake/LegacyConverter.cmake | 126 +- tools/compiler/cmake/Windows/ApexImporter.cmake | 40 +- tools/compiler/cmake/Windows/AuthoringTool.cmake | 42 +- tools/compiler/cmake/Windows/CMakeLists.txt | 102 +- tools/compiler/cmake/Windows/LegacyConverter.cmake | 40 +- 20 files changed, 2911 insertions(+), 2851 deletions(-) mode change 100644 => 100755 tools/ApexImporter/src/ApexDestructibleObjExporter.cpp mode change 100644 => 100755 tools/ApexImporter/src/ApexDestructibleObjExporter.h mode change 100644 => 100755 tools/ApexImporter/src/Main.cpp mode change 100644 => 100755 tools/AuthoringTool/src/AuthoringTool.cpp mode change 100644 => 100755 tools/AuthoringTool/src/SimpleRandomGenerator.h mode change 100644 => 100755 tools/CMakeLists.txt mode change 100644 => 100755 tools/LegacyConverter/src/Main.cpp mode change 100644 => 100755 tools/common/BlastDataExporter.cpp mode change 100644 => 100755 tools/common/BlastDataExporter.h mode change 100644 => 100755 tools/common/Log.cpp mode change 100644 => 100755 tools/common/Log.h mode change 100644 => 100755 tools/common/Utils.cpp mode change 100644 => 100755 tools/common/Utils.h mode change 100644 => 100755 tools/compiler/cmake/ApexImporter.cmake mode change 100644 => 100755 tools/compiler/cmake/AuthoringTool.cmake mode change 100644 => 100755 tools/compiler/cmake/LegacyConverter.cmake mode change 100644 => 100755 tools/compiler/cmake/Windows/ApexImporter.cmake mode change 100644 => 100755 tools/compiler/cmake/Windows/AuthoringTool.cmake mode change 100644 => 100755 tools/compiler/cmake/Windows/CMakeLists.txt mode change 100644 => 100755 tools/compiler/cmake/Windows/LegacyConverter.cmake (limited to 'tools') diff --git a/tools/ApexImporter/src/ApexDestructibleObjExporter.cpp b/tools/ApexImporter/src/ApexDestructibleObjExporter.cpp old mode 100644 new mode 100755 index 3de7418..0dff785 --- a/tools/ApexImporter/src/ApexDestructibleObjExporter.cpp +++ b/tools/ApexImporter/src/ApexDestructibleObjExporter.cpp @@ -1,115 +1,115 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2016-2018 NVIDIA Corporation. All rights reserved. - - -#include "ApexDestructibleObjExporter.h" - -#include "Log.h" - -#include "PsFastXml.h" -#include "PsFileBuffer.h" -#include -#include -#include -#include -#include - - - -using namespace nvidia; -using namespace Nv::Blast; - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Material Parser -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -bool ApexDestructibleGeometryExporter::exportToFile(NvBlastAsset* asset, const NvParameterized::Interface* dmeshIfs, ApexImporter::ApexImportTool& tool, const std::string& name, - const std::vector& chunkReorderInvMap, bool toFbx, bool toObj, bool fbxascii, bool nonSkinned, const std::vector >& hulls) -{ - - Nv::Blast::ExporterMeshData meshData; - meshData.asset = asset; - tool.importRendermesh(chunkReorderInvMap, dmeshIfs, &meshData, m_materialsDir.c_str()); - - if (!hulls.empty()) - { - meshData.hullsOffsets = new uint32_t[hulls.size() + 1]{ 0 }; - for (uint32_t i = 0; i < hulls.size(); i++) - { - meshData.hullsOffsets[i + 1] = meshData.hullsOffsets[i] + (uint32_t)hulls[i].size(); - } - meshData.hulls = new CollisionHull*[meshData.hullsOffsets[hulls.size()]]; - for (uint32_t i = 0; i < hulls.size(); i++) - { - for (uint32_t j = 0; j < hulls[i].size(); j++) - { - meshData.hulls[meshData.hullsOffsets[i] + j] = hulls[i][j]; - } - } - } - else - { - meshData.hulls = nullptr; - meshData.hullsOffsets = nullptr; - } - if (toObj) - { - IMeshFileWriter* fileWriter = NvBlastExtExporterCreateObjFileWriter(); - fileWriter->appendMesh(meshData, name.c_str()); - fileWriter->saveToFile(name.c_str(), m_exportDir.c_str()); - fileWriter->release(); - //writer.saveToFile(asset, name, m_exportDir, compressedPositions, compressedNormals, compressedTextures, pInd, nInd, tInd, materialPathes, submeshCount); - } - if (toFbx) - { - IMeshFileWriter* fileWriter = NvBlastExtExporterCreateFbxFileWriter(fbxascii); - fileWriter->appendMesh(meshData, name.c_str(), nonSkinned); - fileWriter->saveToFile(name.c_str(), m_exportDir.c_str()); - fileWriter->release(); - } - - delete[] meshData.hulls; - delete[] meshData.hullsOffsets; - delete[] meshData.normals; - delete[] meshData.normIndex; - delete[] meshData.posIndex; - delete[] meshData.positions; - delete[] meshData.submeshOffsets; - delete[] meshData.texIndex; - - delete[] meshData.uvs; - - for (uint32_t i = 0; i < meshData.submeshCount; ++i) - { - delete[] meshData.submeshMats[i].diffuse_tex; - delete[] meshData.submeshMats[i].name; - } - delete[] meshData.submeshMats; - - return true; -} +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2018 NVIDIA Corporation. All rights reserved. + + +#include "ApexDestructibleObjExporter.h" + +#include "Log.h" + +#include "PsFastXml.h" +#include "PsFileBuffer.h" +#include +#include +#include +#include +#include + + + +using namespace nvidia; +using namespace Nv::Blast; + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Material Parser +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +bool ApexDestructibleGeometryExporter::exportToFile(NvBlastAsset* asset, const NvParameterized::Interface* dmeshIfs, ApexImporter::ApexImportTool& tool, const std::string& name, + const std::vector& chunkReorderInvMap, bool toFbx, bool toObj, bool fbxascii, bool nonSkinned, const std::vector >& hulls) +{ + + Nv::Blast::ExporterMeshData meshData; + meshData.asset = asset; + tool.importRendermesh(chunkReorderInvMap, dmeshIfs, &meshData, m_materialsDir.c_str()); + + if (!hulls.empty()) + { + meshData.hullsOffsets = new uint32_t[hulls.size() + 1]{ 0 }; + for (uint32_t i = 0; i < hulls.size(); i++) + { + meshData.hullsOffsets[i + 1] = meshData.hullsOffsets[i] + (uint32_t)hulls[i].size(); + } + meshData.hulls = new CollisionHull*[meshData.hullsOffsets[hulls.size()]]; + for (uint32_t i = 0; i < hulls.size(); i++) + { + for (uint32_t j = 0; j < hulls[i].size(); j++) + { + meshData.hulls[meshData.hullsOffsets[i] + j] = hulls[i][j]; + } + } + } + else + { + meshData.hulls = nullptr; + meshData.hullsOffsets = nullptr; + } + if (toObj) + { + IMeshFileWriter* fileWriter = NvBlastExtExporterCreateObjFileWriter(); + fileWriter->appendMesh(meshData, name.c_str()); + fileWriter->saveToFile(name.c_str(), m_exportDir.c_str()); + fileWriter->release(); + //writer.saveToFile(asset, name, m_exportDir, compressedPositions, compressedNormals, compressedTextures, pInd, nInd, tInd, materialPathes, submeshCount); + } + if (toFbx) + { + IMeshFileWriter* fileWriter = NvBlastExtExporterCreateFbxFileWriter(fbxascii); + fileWriter->appendMesh(meshData, name.c_str(), nonSkinned); + fileWriter->saveToFile(name.c_str(), m_exportDir.c_str()); + fileWriter->release(); + } + + delete[] meshData.hulls; + delete[] meshData.hullsOffsets; + delete[] meshData.normals; + delete[] meshData.normIndex; + delete[] meshData.posIndex; + delete[] meshData.positions; + delete[] meshData.submeshOffsets; + delete[] meshData.texIndex; + + delete[] meshData.uvs; + + for (uint32_t i = 0; i < meshData.submeshCount; ++i) + { + delete[] meshData.submeshMats[i].diffuse_tex; + delete[] meshData.submeshMats[i].name; + } + delete[] meshData.submeshMats; + + return true; +} diff --git a/tools/ApexImporter/src/ApexDestructibleObjExporter.h b/tools/ApexImporter/src/ApexDestructibleObjExporter.h old mode 100644 new mode 100755 index 26077e5..c4cf859 --- a/tools/ApexImporter/src/ApexDestructibleObjExporter.h +++ b/tools/ApexImporter/src/ApexDestructibleObjExporter.h @@ -1,77 +1,77 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2016-2018 NVIDIA Corporation. All rights reserved. - - -#ifndef OBJ_APEX_EXPORTER_H -#define OBJ_APEX_EXPORTER_H - -#include -#include -#include -#include - - - -namespace physx -{ - class PxVec3; - class PxVec2; -} - -struct NvBlastAsset; - -namespace Nv -{ -namespace Blast -{ - -class ApexDestructibleGeometryExporter -{ -public: - ApexDestructibleGeometryExporter(std::string materialsDir, std::string exportDir) : m_materialsDir(materialsDir), m_exportDir(exportDir) - {} - - bool exportToFile(NvBlastAsset* asset, const NvParameterized::Interface* dmeshIfs, ApexImporter::ApexImportTool& tool, const std::string& name, - const std::vector& chunkReorderInvMap, bool toFbx, bool toObj, bool fbxascii, bool nonSkinned, - const std::vector >& hulls = std::vector >()); - -private: - ApexDestructibleGeometryExporter& operator=(const ApexDestructibleGeometryExporter&) - { - return *this; - } - const std::string m_materialsDir; - const std::string m_exportDir; - -}; - - -} // namespace Blast -} // namespace Nv - - -#endif //OBJ_EXPORTER_H +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2018 NVIDIA Corporation. All rights reserved. + + +#ifndef OBJ_APEX_EXPORTER_H +#define OBJ_APEX_EXPORTER_H + +#include +#include +#include +#include + + + +namespace physx +{ + class PxVec3; + class PxVec2; +} + +struct NvBlastAsset; + +namespace Nv +{ +namespace Blast +{ + +class ApexDestructibleGeometryExporter +{ +public: + ApexDestructibleGeometryExporter(std::string materialsDir, std::string exportDir) : m_materialsDir(materialsDir), m_exportDir(exportDir) + {} + + bool exportToFile(NvBlastAsset* asset, const NvParameterized::Interface* dmeshIfs, ApexImporter::ApexImportTool& tool, const std::string& name, + const std::vector& chunkReorderInvMap, bool toFbx, bool toObj, bool fbxascii, bool nonSkinned, + const std::vector >& hulls = std::vector >()); + +private: + ApexDestructibleGeometryExporter& operator=(const ApexDestructibleGeometryExporter&) + { + return *this; + } + const std::string m_materialsDir; + const std::string m_exportDir; + +}; + + +} // namespace Blast +} // namespace Nv + + +#endif //OBJ_EXPORTER_H diff --git a/tools/ApexImporter/src/Main.cpp b/tools/ApexImporter/src/Main.cpp old mode 100644 new mode 100755 index 02839b1..c7b5897 --- a/tools/ApexImporter/src/Main.cpp +++ b/tools/ApexImporter/src/Main.cpp @@ -1,323 +1,360 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2016-2018 NVIDIA Corporation. All rights reserved. - - -#if NV_VC -#pragma warning(push) -#pragma warning(disable: 4996) // 'fopen' unsafe warning, from NxFileBuffer.h -#endif - -#include "PxPhysicsAPI.h" -#include "NvBlastExtApexImportTool.h" -#include "Log.h" -#include -#include -#include -#include "tclap/CmdLine.h" -#include "ApexDestructibleObjExporter.h" -#include "NvBlastTkFramework.h" -#include "NvBlastGlobals.h" -#include "NvBlastExtPxAsset.h" -#include "NvBlastExtPxManager.h" -#include "BlastDataExporter.h" -#include "windows.h" -#include -#include "NvBlastExtLlSerialization.h" -#include "NvBlastExtTkSerialization.h" -#include "NvBlastExtPxSerialization.h" -#include -#include -#define DEFAULT_INPUT_FILE "../../../tools/ApexImporter/resources/assets/table.apb" -#define DEFAULT_OUTPUT_DIR "C:/TestFracturer/" -#define DEFAULT_ASSET_NAME "table" - -using namespace Nv::Blast; -using namespace Nv::Blast::ApexImporter; - -void loggingCallback(int type, const char* msg, const char* file, int line) -{ - if (type == NvBlastMessage::Info) - lout() << Log::TYPE_INFO << msg << " FILE:" << file << " Line: " << line << "\n"; - else - lout() << Log::TYPE_ERROR << msg << " FILE:" << file << " Line: " << line << "\n"; -} - -bool isDirectoryExist(std::string path) -{ - DWORD attributes = GetFileAttributesA(path.c_str()); - if ((attributes != INVALID_FILE_ATTRIBUTES) && (attributes & FILE_ATTRIBUTE_DIRECTORY)) - { - return true; - } - return false; -} - -bool mkDirRecursively(std::string path) -{ - if (isDirectoryExist(path)) - { - return true; - } - auto indx = path.find_first_of("\\/"); - while (indx != std::string::npos) - { - std::string subfolder = path.substr(0, indx); - CreateDirectory(subfolder.c_str(), NULL); - indx = path.find_first_of("\\/", indx + 1); - } - return isDirectoryExist(path); -} - -// Create an Asset from the APEX destructible asset -void run(const std::string& inFilepath, const std::string& outDir, const std::string& assetName, uint32_t mode, bool llFlag, bool tkFlag, bool extPxFlag, bool obj, bool fbx, bool fbxascii, bool fbxCollision, bool nonSkinned) -{ - std::string inputDir = inFilepath.substr(0, inFilepath.find_last_of("/\\")); - - // load APEX - ApexImportTool blast; - - lout() << Log::TYPE_INFO << "ApexImportTool initialization" << std::endl; - if (!blast.isValid()) - { - lout() << Log::TYPE_ERROR << "Failed to create BlastSDK" << std::endl; - return; - } - - - // load asset - lout() << Log::TYPE_INFO << "Loading asset: " << inFilepath << std::endl; - physx::PxFileBuf* apexAssetStream = PX_NEW(physx::general_PxIOStream::PsFileBuffer)(inFilepath.c_str(), physx::PxFileBuf::OPEN_READ_ONLY); - - NvParameterized::Serializer::DeserializedData data; - blast.loadAssetFromFile(apexAssetStream, data); - if (data.size() == 0) - { - return; - } - apexAssetStream->release(); - - ApexImporterConfig config; - config.infSearchMode = static_cast(mode); - - std::vector chunkReorderInvMap; - TkFramework* framework = NvBlastTkFrameworkCreate(); - if (framework == nullptr) - { - lout() << Log::TYPE_ERROR << "Failed to create TkFramework" << std::endl; - return; - } - - std::vector chunkDesc; - std::vector bondDescs; - std::vector flags; - - std::vector physicsChunks; - std::vector physicsSubchunks; - - bool result = blast.importApexAsset(chunkReorderInvMap, data[0], chunkDesc, bondDescs, flags, config); - if (!result) - { - lout() << Log::TYPE_ERROR << "Failed to build Blast asset data" << std::endl; - return; - }; - std::vector> hulls; - result = blast.getCollisionGeometry(data[0], static_cast(chunkDesc.size()), chunkReorderInvMap, flags, physicsChunks, physicsSubchunks, hulls); - if (!result) - { - lout() << Log::TYPE_ERROR << "Failed to build physics data" << std::endl; - return; - }; - - - // save asset - lout() << Log::TYPE_INFO << "Saving blast asset: " << outDir << std::endl; - BlastDataExporter blExpr(framework, blast.getPxSdk(), blast.getCooking()); - NvBlastAsset* llAsset = blExpr.createLlBlastAsset(bondDescs, chunkDesc); - - std::cout <<"Chunk count: " << NvBlastAssetGetChunkCount(llAsset, NULL) << std::endl; - - if (llAsset == nullptr && (llFlag || fbx)) - { - lout() << Log::TYPE_ERROR << "Failed to build low-level asset" << std::endl; - return; - } - - if (llFlag) - { - blExpr.saveBlastObject(outDir, assetName, llAsset, LlObjectTypeID::Asset); - } - if (tkFlag) - { - TkAsset* tkAsset = blExpr.createTkBlastAsset(bondDescs, chunkDesc); - blExpr.saveBlastObject(outDir, assetName, tkAsset, TkObjectTypeID::Asset); - tkAsset->release(); - } - if (extPxFlag) - { - ExtPxAsset* pxAsset = blExpr.createExtBlastAsset(bondDescs, chunkDesc, physicsChunks); - blExpr.saveBlastObject(outDir, assetName, pxAsset, ExtPxObjectTypeID::Asset); - pxAsset->release(); - } - - lout() << Log::TYPE_INFO << "Saving model file: " << outDir << std::endl; - ApexDestructibleGeometryExporter objSaver(inputDir, outDir); - if (fbxCollision) - { - objSaver.exportToFile(llAsset, data[0], blast, assetName, chunkReorderInvMap, fbx, obj, fbxascii, nonSkinned, hulls); - } - else - { - objSaver.exportToFile(llAsset, data[0], blast, assetName, chunkReorderInvMap, fbx, obj, fbxascii, nonSkinned); - } - NVBLAST_FREE(llAsset); -} - - -int main(int argc, const char* const* argv) -{ - try - { - // setup cmd line - TCLAP::CmdLine cmd("Blast SDK: APEX Importer", ' ', "0.1"); - - TCLAP::ValueArg infileArg("f", "file", "File to load", true, DEFAULT_INPUT_FILE, "infile"); - cmd.add(infileArg); - - TCLAP::ValueArg outDirArg("o", "outputDir", "Output directory", false, DEFAULT_OUTPUT_DIR, "output directory"); - cmd.add(outDirArg); - - TCLAP::ValueArg outAssetName("n", "outAssetName", "Output asset name", true, DEFAULT_ASSET_NAME, "output asset name"); - cmd.add(outAssetName); - - - TCLAP::ValueArg interfaceSearchMode("m", "mode", "Interface search mode", false, 0, "0 - EXACT, 1 - FORCED, for detailed description see docs."); - cmd.add(interfaceSearchMode); - - TCLAP::SwitchArg debugSwitch("d", "debug", "Print debug output", cmd, false); - - TCLAP::SwitchArg pxOutputArg("", "px", "Output ExtPxAsset to the output directory", false); - cmd.add(pxOutputArg); - - TCLAP::SwitchArg tkOutputArg("", "tk", "Output TkAsset to the output directory", false); - cmd.add(tkOutputArg); - - TCLAP::SwitchArg llOutputArg("", "ll", "Output LL Blast asset to the output directory", false); - cmd.add(llOutputArg); - - TCLAP::SwitchArg fbxAsciiArg("", "fbxascii", "Output FBX as an ascii file (defaults to binary output)", false); - cmd.add(fbxAsciiArg); - - TCLAP::SwitchArg objOutputArg("", "obj", "Output a OBJ mesh to the output directory", false); - cmd.add(objOutputArg); - - TCLAP::SwitchArg fbxOutputArg("", "fbx", "Output a FBX mesh to the output directory", false); - cmd.add(fbxOutputArg); - - TCLAP::SwitchArg fbxcollision("", "fbxcollision", "Append collision geometry to FBX file", false); - cmd.add(fbxcollision); - - TCLAP::SwitchArg nonSkinnedFBX("", "nonskinned", "Output a non-skinned FBX file", false); - cmd.add(nonSkinnedFBX); - - // parse cmd input - cmd.parse(argc, argv); - - bool bOutputPX = pxOutputArg.getValue(); - bool bOutputTK = tkOutputArg.getValue(); - bool bOutputLL = llOutputArg.getValue(); - - bool bOutputFBXAscii = fbxAsciiArg.isSet(); - - bool bOutputObjFile = objOutputArg.isSet(); - bool bOutputFbxFile = fbxOutputArg.isSet(); - - bool bFbxCollision = fbxcollision.isSet(); - bool bNonSkinned = nonSkinnedFBX.isSet(); - - // Did we specify no output formats? - if (!pxOutputArg.isSet() && !tkOutputArg.isSet() && !llOutputArg.isSet()) - { - std::cout << "Didn't specify an output format on the command line, so defaulting to outputting an ExtPxAsset" << std::endl; - bOutputPX = true; - } - // Did we specify no geometry output formats? - if (!bOutputObjFile && !bOutputFbxFile) - { - std::cout << "Didn't specify an output geometry format on the command line, so defaulting to outputting .OBJ" << std::endl; - bOutputObjFile = true; - } - - // get cmd parse results - std::string infile = infileArg.getValue(); - std::string outDir; - std::string assetName = outAssetName.getValue(); - - /** - Set output dir, make sure that it exist. - */ - if (outDirArg.isSet()) - { - outDir = outDirArg.getValue(); - std::string temp = outDir + '/'; - if (!isDirectoryExist(outDir.data())) - { - std::cout << "Output directory doesn't exist. It will be created." << std::endl; - if (!mkDirRecursively(temp.data())) - { - std::cout << "Directory creation failed!" << std::endl; - return -1; - } - } - } - else - { - auto idx = infile.find_last_of("/\\"); - if (idx == 0 || idx == std::string::npos) - { - outDir = "."; - } - else - { - outDir = infile.substr(0, idx); - } - } - - bool debug = debugSwitch.getValue(); - int mode = interfaceSearchMode.getValue(); - // do stuff - if (debug) - lout().setMinVerbosity(Log::MOST_VERBOSE); - - run(infile, outDir, assetName, mode, bOutputLL, bOutputTK, bOutputPX, bOutputObjFile, bOutputFbxFile, bOutputFBXAscii, bFbxCollision, bNonSkinned); - } - catch (TCLAP::ArgException &e) // catch any exceptions - { - lout() << Log::TYPE_ERROR << "error: " << e.error() << " for arg " << e.argId() << std::endl; - } - - return 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) 2016-2018 NVIDIA Corporation. All rights reserved. + + +#if NV_VC +#pragma warning(push) +#pragma warning(disable: 4996) // 'fopen' unsafe warning, from NxFileBuffer.h +#endif + +#include "PxPhysicsAPI.h" +#include "NvBlastExtApexImportTool.h" +#include "Log.h" +#include +#include +#include +#include "tclap/CmdLine.h" +#include "ApexDestructibleObjExporter.h" +#include "NvBlastTkFramework.h" +#include "NvBlastGlobals.h" +#include "NvBlastExtPxAsset.h" +#include "NvBlastExtPxManager.h" +#include "BlastDataExporter.h" +#include "windows.h" +#include +#include "NvBlastExtLlSerialization.h" +#include "NvBlastExtTkSerialization.h" +#include "NvBlastExtPxSerialization.h" +#include "NvBlastExtExporterJsonCollision.h" +#include +#include +#define DEFAULT_INPUT_FILE "../../../tools/ApexImporter/resources/assets/table.apb" +#define DEFAULT_OUTPUT_DIR "C:/TestFracturer/" +#define DEFAULT_ASSET_NAME "table" + +using namespace Nv::Blast; +using namespace Nv::Blast::ApexImporter; + +void loggingCallback(int type, const char* msg, const char* file, int line) +{ + if (type == NvBlastMessage::Info) + lout() << Log::TYPE_INFO << msg << " FILE:" << file << " Line: " << line << "\n"; + else + lout() << Log::TYPE_ERROR << msg << " FILE:" << file << " Line: " << line << "\n"; +} + +bool isDirectoryExist(std::string path) +{ + DWORD attributes = GetFileAttributesA(path.c_str()); + if ((attributes != INVALID_FILE_ATTRIBUTES) && (attributes & FILE_ATTRIBUTE_DIRECTORY)) + { + return true; + } + return false; +} + +bool mkDirRecursively(std::string path) +{ + if (isDirectoryExist(path)) + { + return true; + } + auto indx = path.find_first_of("\\/"); + while (indx != std::string::npos) + { + std::string subfolder = path.substr(0, indx); + CreateDirectory(subfolder.c_str(), NULL); + indx = path.find_first_of("\\/", indx + 1); + } + return isDirectoryExist(path); +} + +// Create an Asset from the APEX destructible asset +void run(const std::string& inFilepath, const std::string& outDir, const std::string& assetName, uint32_t mode, bool llFlag, bool tkFlag, bool extPxFlag, + bool obj, bool fbx, bool fbxascii, bool fbxCollision, bool jsonCollision, bool nonSkinned) +{ + std::string inputDir = inFilepath.substr(0, inFilepath.find_last_of("/\\")); + + // load APEX + ApexImportTool blast; + + lout() << Log::TYPE_INFO << "ApexImportTool initialization" << std::endl; + if (!blast.isValid()) + { + lout() << Log::TYPE_ERROR << "Failed to create BlastSDK" << std::endl; + return; + } + + + // load asset + lout() << Log::TYPE_INFO << "Loading asset: " << inFilepath << std::endl; + physx::PxFileBuf* apexAssetStream = PX_NEW(physx::general_PxIOStream::PsFileBuffer)(inFilepath.c_str(), physx::PxFileBuf::OPEN_READ_ONLY); + + NvParameterized::Serializer::DeserializedData data; + blast.loadAssetFromFile(apexAssetStream, data); + if (data.size() == 0) + { + return; + } + apexAssetStream->release(); + + ApexImporterConfig config; + config.infSearchMode = static_cast(mode); + + std::vector chunkReorderInvMap; + TkFramework* framework = NvBlastTkFrameworkCreate(); + if (framework == nullptr) + { + lout() << Log::TYPE_ERROR << "Failed to create TkFramework" << std::endl; + return; + } + + std::vector chunkDesc; + std::vector bondDescs; + std::vector flags; + + std::vector physicsChunks; + std::vector physicsSubchunks; + + bool result = blast.importApexAsset(chunkReorderInvMap, data[0], chunkDesc, bondDescs, flags, config); + if (!result) + { + lout() << Log::TYPE_ERROR << "Failed to build Blast asset data" << std::endl; + return; + }; + std::vector> hulls; + result = blast.getCollisionGeometry(data[0], static_cast(chunkDesc.size()), chunkReorderInvMap, flags, physicsChunks, physicsSubchunks, hulls); + if (!result) + { + lout() << Log::TYPE_ERROR << "Failed to build physics data" << std::endl; + return; + }; + + + // save asset + lout() << Log::TYPE_INFO << "Saving blast asset: " << outDir << std::endl; + BlastDataExporter blExpr(framework, blast.getPxSdk(), blast.getCooking()); + NvBlastAsset* llAsset = blExpr.createLlBlastAsset(bondDescs, chunkDesc); + + std::cout <<"Chunk count: " << NvBlastAssetGetChunkCount(llAsset, NULL) << std::endl; + + if (llAsset == nullptr && (llFlag || fbx)) + { + lout() << Log::TYPE_ERROR << "Failed to build low-level asset" << std::endl; + return; + } + + if (llFlag) + { + blExpr.saveBlastObject(outDir, assetName, llAsset, LlObjectTypeID::Asset); + } + if (tkFlag) + { + TkAsset* tkAsset = blExpr.createTkBlastAsset(bondDescs, chunkDesc); + blExpr.saveBlastObject(outDir, assetName, tkAsset, TkObjectTypeID::Asset); + tkAsset->release(); + } + if (extPxFlag) + { + ExtPxAsset* pxAsset = blExpr.createExtBlastAsset(bondDescs, chunkDesc, physicsChunks); + blExpr.saveBlastObject(outDir, assetName, pxAsset, ExtPxObjectTypeID::Asset); + pxAsset->release(); + } + + lout() << Log::TYPE_INFO << "Saving model file: " << outDir << std::endl; + ApexDestructibleGeometryExporter objSaver(inputDir, outDir); + if (fbxCollision) + { + objSaver.exportToFile(llAsset, data[0], blast, assetName, chunkReorderInvMap, fbx, obj, fbxascii, nonSkinned, hulls); + } + else + { + objSaver.exportToFile(llAsset, data[0], blast, assetName, chunkReorderInvMap, fbx, obj, fbxascii, nonSkinned); + } + + if (jsonCollision) + { + std::vector flattenedHulls; + std::vector hullOffsets; + for (std::vector& chunkHulls : hulls) + { + hullOffsets.push_back(static_cast(flattenedHulls.size())); + for (CollisionHull* hull : chunkHulls) + { + flattenedHulls.push_back(hull); + } + } + hullOffsets.push_back(static_cast(flattenedHulls.size())); + const std::string fullJsonFilename = outDir + ((outDir.back() == '/' || outDir.back() == '\\') ? "" : "/") + assetName + ".json"; + IJsonCollisionExporter* collisionExporter = NvBlastExtExporterCreateJsonCollisionExporter(); + if (collisionExporter != nullptr) + { + if (collisionExporter->writeCollision(fullJsonFilename.c_str(), static_cast(hulls.size()), hullOffsets.data(), flattenedHulls.data())) + { + std::cout << "Exported collision geometry: " << fullJsonFilename << std::endl; + } + else + { + std::cerr << "Can't write collision geometry to json file." << std::endl; + } + collisionExporter->release(); + } + } + + NVBLAST_FREE(llAsset); +} + + +int main(int argc, const char* const* argv) +{ + try + { + // setup cmd line + TCLAP::CmdLine cmd("Blast SDK: APEX Importer", ' ', "0.1"); + + TCLAP::ValueArg infileArg("f", "file", "File to load", true, DEFAULT_INPUT_FILE, "infile"); + cmd.add(infileArg); + + TCLAP::ValueArg outDirArg("o", "outputDir", "Output directory", false, DEFAULT_OUTPUT_DIR, "output directory"); + cmd.add(outDirArg); + + TCLAP::ValueArg outAssetName("n", "outAssetName", "Output asset name", true, DEFAULT_ASSET_NAME, "output asset name"); + cmd.add(outAssetName); + + + TCLAP::ValueArg interfaceSearchMode("m", "mode", "Interface search mode", false, 0, "0 - EXACT, 1 - FORCED, for detailed description see docs."); + cmd.add(interfaceSearchMode); + + TCLAP::SwitchArg debugSwitch("d", "debug", "Print debug output", cmd, false); + + TCLAP::SwitchArg pxOutputArg("", "px", "Output ExtPxAsset to the output directory", false); + cmd.add(pxOutputArg); + + TCLAP::SwitchArg tkOutputArg("", "tk", "Output TkAsset to the output directory", false); + cmd.add(tkOutputArg); + + TCLAP::SwitchArg llOutputArg("", "ll", "Output LL Blast asset to the output directory", false); + cmd.add(llOutputArg); + + TCLAP::SwitchArg fbxAsciiArg("", "fbxascii", "Output FBX as an ascii file (defaults to binary output)", false); + cmd.add(fbxAsciiArg); + + TCLAP::SwitchArg objOutputArg("", "obj", "Output a OBJ mesh to the output directory", false); + cmd.add(objOutputArg); + + TCLAP::SwitchArg fbxOutputArg("", "fbx", "Output a FBX mesh to the output directory", false); + cmd.add(fbxOutputArg); + + TCLAP::SwitchArg jsonCollision("", "jsoncollision", "Save collision geometry to a json file", false); + cmd.add(jsonCollision); + + TCLAP::SwitchArg fbxcollision("", "fbxcollision", "Append collision geometry to FBX file", false); + cmd.add(fbxcollision); + + TCLAP::SwitchArg nonSkinnedFBX("", "nonskinned", "Output a non-skinned FBX file", false); + cmd.add(nonSkinnedFBX); + + // parse cmd input + cmd.parse(argc, argv); + + bool bOutputPX = pxOutputArg.getValue(); + bool bOutputTK = tkOutputArg.getValue(); + bool bOutputLL = llOutputArg.getValue(); + + bool bOutputFBXAscii = fbxAsciiArg.isSet(); + + bool bOutputObjFile = objOutputArg.isSet(); + bool bOutputFbxFile = fbxOutputArg.isSet(); + + bool bFbxCollision = fbxcollision.isSet(); + bool bJsonCollision = jsonCollision.isSet(); + + bool bNonSkinned = nonSkinnedFBX.isSet(); + + // Did we specify no output formats? + if (!pxOutputArg.isSet() && !tkOutputArg.isSet() && !llOutputArg.isSet()) + { + std::cout << "Didn't specify an output format on the command line, so defaulting to outputting an ExtPxAsset" << std::endl; + bOutputPX = true; + } + // Did we specify no geometry output formats? + if (!bOutputObjFile && !bOutputFbxFile) + { + std::cout << "Didn't specify an output geometry format on the command line, so defaulting to outputting .OBJ" << std::endl; + bOutputObjFile = true; + } + + // get cmd parse results + std::string infile = infileArg.getValue(); + std::string outDir; + std::string assetName = outAssetName.getValue(); + + /** + Set output dir, make sure that it exist. + */ + if (outDirArg.isSet()) + { + outDir = outDirArg.getValue(); + std::string temp = outDir + '/'; + if (!isDirectoryExist(outDir.data())) + { + std::cout << "Output directory doesn't exist. It will be created." << std::endl; + if (!mkDirRecursively(temp.data())) + { + std::cout << "Directory creation failed!" << std::endl; + return -1; + } + } + } + else + { + auto idx = infile.find_last_of("/\\"); + if (idx == 0 || idx == std::string::npos) + { + outDir = "."; + } + else + { + outDir = infile.substr(0, idx); + } + } + + bool debug = debugSwitch.getValue(); + int mode = interfaceSearchMode.getValue(); + // do stuff + if (debug) + lout().setMinVerbosity(Log::MOST_VERBOSE); + + run(infile, outDir, assetName, mode, bOutputLL, bOutputTK, bOutputPX, bOutputObjFile, bOutputFbxFile, bOutputFBXAscii, bFbxCollision, bJsonCollision, bNonSkinned); + } + catch (TCLAP::ArgException &e) // catch any exceptions + { + lout() << Log::TYPE_ERROR << "error: " << e.error() << " for arg " << e.argId() << std::endl; + } + + return 0; +} diff --git a/tools/AuthoringTool/src/AuthoringTool.cpp b/tools/AuthoringTool/src/AuthoringTool.cpp old mode 100644 new mode 100755 index 09e66bb..c7b664f --- a/tools/AuthoringTool/src/AuthoringTool.cpp +++ b/tools/AuthoringTool/src/AuthoringTool.cpp @@ -1,734 +1,755 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2016-2018 NVIDIA Corporation. All rights reserved. - - -#include "PxPhysicsAPI.h" -#include "PsFileBuffer.h" -#include "NvBlast.h" -#include "NvBlastAssert.h" -#include "NvBlastGlobals.h" -#include "NvBlastExtExporter.h" -#include "NvBlastPxCallbacks.h" -#include "NvBlastTkAsset.h" -#include "NvBlastExtLlSerialization.h" -#include "NvBlastExtTkSerialization.h" -#include "NvBlastExtPxSerialization.h" -#include "NvBlastExtAuthoring.h" -#include "NvBlastExtAuthoringMesh.h" -#include "NvBlastExtAuthoringBondGenerator.h" -#include "NvBlastExtAuthoringCollisionBuilder.h" -#include "NvBlastExtAuthoringCutout.h" -#include "NvBlastExtAuthoringFractureTool.h" -#include "BlastDataExporter.h" -#include "SimpleRandomGenerator.h" -#include "NvBlastExtAuthoringMeshCleaner.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include "tclap/CmdLine.h" - -using physx::PxVec3; -using physx::PxVec2; - -#define DEFAULT_ASSET_NAME "AuthoringTest" - -using namespace Nv::Blast; - -physx::PxFoundation* gFoundation = nullptr; -physx::PxPhysics* gPhysics = nullptr; -physx::PxCooking* gCooking = nullptr; - -struct TCLAPint3 -{ - int32_t x, y, z; - TCLAPint3(int32_t x, int32_t y, int32_t z) :x(x), y(y), z(z){}; - TCLAPint3() :x(0), y(0), z(0){}; - TCLAPint3& operator=(const std::string &inp) - { - std::istringstream stream(inp); - if (!(stream >> x >> y >> z)) - throw TCLAP::ArgParseException(inp + " is not int3"); - return *this; - } -}; - -struct TCLAPfloat3 -{ - float x, y, z; - TCLAPfloat3(float x, float y, float z) :x(x), y(y), z(z) {}; - TCLAPfloat3() :x(0), y(0), z(0) {}; - TCLAPfloat3& operator=(const std::string &inp) - { - std::istringstream stream(inp); - if (!(stream >> x >> y >> z)) - throw TCLAP::ArgParseException(inp + " is not float3"); - return *this; - } - - operator physx::PxVec3() - { - return physx::PxVec3(x, y, z); - } -}; - -namespace TCLAP { - template<> - struct ArgTraits { - typedef StringLike ValueCategory; - }; - - template<> - struct ArgTraits { - typedef StringLike ValueCategory; - }; -} - -bool isDirectoryExist(const std::string& path) -{ - DWORD attributes = GetFileAttributesA(path.c_str()); - if ((attributes != INVALID_FILE_ATTRIBUTES) && (attributes & FILE_ATTRIBUTE_DIRECTORY)) - { - return true; - } - return false; -} - -bool isFileExist(const std::string& path) -{ - DWORD attributes = GetFileAttributesA(path.c_str()); - if ((attributes != INVALID_FILE_ATTRIBUTES) && !(attributes & FILE_ATTRIBUTE_DIRECTORY)) - { - return true; - } - return false; -} - -bool mkDirRecursively(const std::string& path) -{ - if (isDirectoryExist(path)) - { - return true; - } - auto indx = path.find_first_of("\\/"); - while (indx != std::string::npos) - { - std::string subfolder = path.substr(0, indx); - CreateDirectory(subfolder.c_str(), NULL); - indx = path.find_first_of("\\/", indx + 1); - } - return isDirectoryExist(path); -} - -unsigned char *LoadBitmapFile(const char *filename, BITMAPINFOHEADER *bitmapInfoHeader) -{ - FILE *filePtr; //our file pointer - BITMAPFILEHEADER bitmapFileHeader; //our bitmap file header - unsigned char *bitmapImage; //store image data - //int imageIdx = 0; //image index counter - unsigned char tempRGB; //our swap variable - - //open filename in read binary mode - filePtr = fopen(filename, "rb"); - if (filePtr == NULL) - return NULL; - - //read the bitmap file header - fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr); - - //verify that this is a bmp file by check bitmap id - if (bitmapFileHeader.bfType != 0x4D42) - { - fclose(filePtr); - return NULL; - } - - //read the bitmap info header - fread(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr); // small edit. forgot to add the closing bracket at sizeof - - //move file point to the begging of bitmap data - fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET); - - //Only incompressed 24 byte RGB is supported - if (bitmapInfoHeader->biCompression != BI_RGB || bitmapInfoHeader->biBitCount != 24) - { - return nullptr; - } - else - { - bitmapInfoHeader->biSizeImage = 3 * bitmapInfoHeader->biHeight * bitmapInfoHeader->biHeight; - } - - //allocate enough memory for the bitmap image data - bitmapImage = (unsigned char*)malloc(bitmapInfoHeader->biSizeImage); - - //verify memory allocation - if (!bitmapImage) - { - free(bitmapImage); - fclose(filePtr); - return NULL; - } - - //read in the bitmap image data - fread(bitmapImage, sizeof(uint8_t), bitmapInfoHeader->biSizeImage, filePtr); - - //make sure bitmap image data was read - if (bitmapImage == NULL) - { - fclose(filePtr); - return NULL; - } - - //swap the r and b values to get RGB (bitmap is BGR) - if (bitmapInfoHeader->biBitCount > 1) - { - for (uint32_t imageIdx = 0; imageIdx < bitmapInfoHeader->biSizeImage; imageIdx += 3) // fixed semicolon - { - tempRGB = bitmapImage[imageIdx]; - bitmapImage[imageIdx] = bitmapImage[imageIdx + 2]; - bitmapImage[imageIdx + 2] = tempRGB; - } - } - - //close file and return bitmap iamge data - fclose(filePtr); - return bitmapImage; -} - -bool initPhysX() -{ - gFoundation = PxCreateFoundation(PX_FOUNDATION_VERSION, NvBlastGetPxAllocatorCallback(), NvBlastGetPxErrorCallback()); - if (!gFoundation) - { - std::cerr << "Can't init PhysX foundation" << std::endl; - return false; - } - physx::PxTolerancesScale scale; - gPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *gFoundation, scale, true); - if (!gPhysics) - { - std::cerr << "Can't create Physics" << std::endl; - return false; - } - physx::PxCookingParams cookingParams(scale); - cookingParams.buildGPUData = true; - gCooking = PxCreateCooking(PX_PHYSICS_VERSION, gPhysics->getFoundation(), cookingParams); - if (!gCooking) - { - std::cerr << "Can't create Cooking" << std::endl; - return false; - } - return true; -} - -int main(int argc, const char* const* argv) -{ - // set blast global error callback - // overriding default one in order to exit tool in profile/release configuration too (and write to stderr) - class CustomErrorCallback : public ErrorCallback - { - virtual void reportError(ErrorCode::Enum code, const char* msg, const char* file, int line) override - { - std::stringstream str; - bool critical = false; - switch (code) - { - case ErrorCode::eNO_ERROR: str << "[Info]"; critical = false; break; - case ErrorCode::eDEBUG_INFO: str << "[Debug Info]"; critical = false; break; - case ErrorCode::eDEBUG_WARNING: str << "[Debug Warning]"; critical = false; break; - case ErrorCode::eINVALID_PARAMETER: str << "[Invalid Parameter]"; critical = true; break; - case ErrorCode::eINVALID_OPERATION: str << "[Invalid Operation]"; critical = true; break; - case ErrorCode::eOUT_OF_MEMORY: str << "[Out of] Memory"; critical = true; break; - case ErrorCode::eINTERNAL_ERROR: str << "[Internal Error]"; critical = true; break; - case ErrorCode::eABORT: str << "[Abort]"; critical = true; break; - case ErrorCode::ePERF_WARNING: str << "[Perf Warning]"; critical = false; break; - default: NVBLAST_ASSERT(false); - } -#if NV_DEBUG || NV_CHECKED - str << file << "(" << line << "): "; -#else - NV_UNUSED(file); - NV_UNUSED(line); -#endif - str << " " << msg << "\n"; - std::cerr << str.str(); - - if (critical) - { - std::cerr << "Authoring failed. Exiting.\n"; - exit(-1); - } - } - }; - CustomErrorCallback errorCallback; - NvBlastGlobalSetErrorCallback(&errorCallback); - - // setup cmd line - TCLAP::CmdLine cmd("Blast SDK: Authoring Tool", ' ', "1.1"); - - TCLAP::UnlabeledValueArg infileArg("file", "File to load", true, "", "infile"); - cmd.add(infileArg); - - TCLAP::UnlabeledValueArg outAssetName("outAssetName", "Output asset name", true, DEFAULT_ASSET_NAME, "output asset name"); - cmd.add(outAssetName); - - TCLAP::ValueArg outDirArg("", "outputDir", "Output directory", false, ".", "by default directory of the input file"); - cmd.add(outDirArg); - - TCLAP::SwitchArg cleanArg("", "clean", "Try cleaning mesh before fracturing", false); - cmd.add(cleanArg); - - // The output modes - //NOTE: Fun TCLAP quirk here - if you set the default to true and specify this switch on the command line, the value will be false! - TCLAP::SwitchArg pxOutputArg("", "px", "Output ExtPxAsset to the .blast file in the output directory.", false); - cmd.add(pxOutputArg); - - TCLAP::SwitchArg tkOutputArg("", "tk", "Output TkAsset to the .blast file in the output directory.", false); - cmd.add(tkOutputArg); - - TCLAP::SwitchArg llOutputArg("", "ll", "Output LL Blast (NvBlastAsset) to the .blast file in the output directory.", false); - cmd.add(llOutputArg); - - TCLAP::SwitchArg fbxAsciiArg("", "fbxascii", "Output FBX as an ascii file (defaults to binary output)", false); - cmd.add(fbxAsciiArg); - - TCLAP::SwitchArg objOutputArg("", "obj", "Output a OBJ mesh to the output directory", false); - cmd.add(objOutputArg); - - TCLAP::SwitchArg fbxOutputArg("", "fbx", "Output a FBX mesh to the output directory", false); - cmd.add(fbxOutputArg); - - TCLAP::SwitchArg fbxCollision("", "fbxcollision", "Add collision geometry to FBX file", false); - cmd.add(fbxCollision); - - TCLAP::SwitchArg nonSkinnedFBX("", "nonskinned", "Output a non-skinned FBX file", false); - cmd.add(nonSkinnedFBX); - - TCLAP::ValueArg interiorMatId("", "interiorMat", "Use to setup interior material id, by default new material for internal surface will be created.", false, -1, "by default -1"); - cmd.add(interiorMatId); - - TCLAP::ValueArg fracturingMode("", "mode", "Fracturing mode", false, 'v', - "v - voronoi, c - clustered voronoi, s - slicing, p - plane cut, u - cutout."); - cmd.add(fracturingMode); - TCLAP::ValueArg cellsCount("", "cells", "Voronoi cells count", false, 5, "by default 5"); - cmd.add(cellsCount); - TCLAP::ValueArg clusterCount("", "clusters", "Uniform Voronoi cluster count", false, 5, "by default 5"); - cmd.add(clusterCount); - TCLAP::ValueArg clusterRad("", "radius", "Clustered Voronoi cluster radius", false, 1.0f, "by default 1.0"); - cmd.add(clusterRad); - - TCLAP::ValueArg slicingNumber("", "slices", "Number of slices per direction", false, TCLAPint3(1, 1, 1), "by default 1 1 1"); - cmd.add(slicingNumber); - - TCLAP::ValueArg angleVariation("", "avar", "Slicing angle variation", false, 0.0, "by default 0.0"); - cmd.add(angleVariation); - - TCLAP::ValueArg offsetVariation("", "ovar", "Slicing offset variation", false, 0.0, "by default 0.0"); - cmd.add(offsetVariation); - - TCLAP::ValueArg point("", "point", "Plane surface point", false, TCLAPfloat3(0, 0, 0), "by default 0 0 0"); - cmd.add(point); - - TCLAP::ValueArg normal("", "normal", "Plane surface normal", false, TCLAPfloat3(1, 0, 0), "by default 1 0 0"); - cmd.add(normal); - - TCLAP::ValueArg cutoutBitmapPath("", "cutoutBitmap", "Path to *.bmp file with cutout bitmap", false, ".", "by defualt empty"); - cmd.add(cutoutBitmapPath); - - try - { - // parse cmd input - cmd.parse(argc, argv); - } - catch (TCLAP::ArgException &e) // catch any exceptions - { - std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; - return -1; - } - - // get cmd parse results - std::string infile = infileArg.getValue(); - if (!isFileExist(infile)) - { - std::cerr << "[Error] Can't find input file: " << infile << std::endl; - return -1; - } - - std::string outDir; - - std::cout << "Input file: " << infile << std::endl; - - if (outDirArg.isSet()) - { - outDir = outDirArg.getValue(); - std::string temp = outDir + '/'; - if (!isDirectoryExist(outDir.data())) - { - std::cout << "Output directory doesn't exist. It will be created." << std::endl; - if (!mkDirRecursively(temp.data())) - { - std::cerr << "Directory creation failed!" << std::endl; - return -1; - } - } - } - else - { - auto idx = infile.find_last_of("/\\"); - if (idx == 0 || idx == std::string::npos) - { - outDir = "."; - } - else - { - outDir = infile.substr(0, idx); - } - } - std::cout << "Output directory: " << outDir << std::endl; - std::string assetName = outAssetName.getValue(); - - // Determine whether to use the obj or fbx loader - - auto idx = infile.rfind('.'); - std::string extension; - - - if (idx != std::string::npos) - { - extension = infile.substr(idx + 1); - std::transform(extension.begin(), extension.end(), extension.begin(), std::toupper); - } - else - { - std::cerr << "Can't determine extension (and thus, loader) of input file. " << infile << std::endl; - return -1; - } - - bool bOutputPX = pxOutputArg.getValue(); - bool bOutputTK = tkOutputArg.getValue(); - bool bOutputLL = llOutputArg.getValue(); - - bool bOutputFBXAscii = fbxAsciiArg.getValue(); - - bool bOutputObjFile = objOutputArg.isSet(); - bool bOutputFbxFile = fbxOutputArg.isSet(); - - // Did we specify no output formats? - if (!bOutputPX && !bOutputTK && !bOutputLL) - { - std::cout << "Didn't specify an output format on the command line. Use default: LL Blast asset (NvBlastAsset)." << std::endl; - bOutputLL = true; - } - else if ((int)bOutputPX + (int)bOutputTK + (int)bOutputLL > 1) - { - std::cerr << "More than one of the --ll, --tk, and --px options are set. Choose one. " << std::endl; - return -1; - } - - // Did we specify no geometry output formats? - if (!bOutputObjFile && !bOutputFbxFile) - { - std::cout << "Didn't specify an output geometry format on the command line. Use default: .FBX" << std::endl; - bOutputFbxFile = true; - } - - std::shared_ptr fileReader; - - if (extension.compare("FBX")==0) - { - fileReader = std::shared_ptr(NvBlastExtExporterCreateFbxFileReader(), [](IMeshFileReader* p) {p->release(); }); - } - else if (extension.compare("OBJ")==0) - { - fileReader = std::shared_ptr(NvBlastExtExporterCreateObjFileReader(), [](IMeshFileReader* p) {p->release(); }); - } - else - { - std::cout << "Unsupported file extension " << extension << std::endl; - return -1; - } - - // Load the asset - fileReader->loadFromFile(infile.c_str()); - - uint32_t vcount = fileReader->getVerticesCount(); - - if (!initPhysX()) - { - std::cerr << "Failed to initialize PhysX" << std::endl; - return -1; - } - Nv::Blast::FractureTool* fTool = NvBlastExtAuthoringCreateFractureTool(); - - PxVec3* pos = fileReader->getPositionArray(); - PxVec3* norm = fileReader->getNormalsArray(); - PxVec2* uv = fileReader->getUvArray(); - - Nv::Blast::Mesh* mesh = NvBlastExtAuthoringCreateMesh(pos, norm, uv, vcount, fileReader->getIndexArray(), fileReader->getIndicesCount()); - - if (cleanArg.isSet()) - { - MeshCleaner* clr = NvBlastExtAuthoringCreateMeshCleaner(); - Nv::Blast::Mesh* nmesh; - nmesh = clr->cleanMesh(mesh); - clr->release(); - mesh->release(); - mesh = nmesh; - } - mesh->setMaterialId(fileReader->getMaterialIds()); - mesh->setSmoothingGroup(fileReader->getSmoothingGroups()); - - fTool->setSourceMesh(mesh); - - - SimpleRandomGenerator rng; - Nv::Blast::VoronoiSitesGenerator* voronoiSitesGenerator = NvBlastExtAuthoringCreateVoronoiSitesGenerator(mesh, &rng); - if (voronoiSitesGenerator == nullptr) - { - std::cerr << "Failed to create Voronoi sites generator" << std::endl; - return -1; - } - - // Send it to the fracture processor - - switch (fracturingMode.getValue()) - { - case 'v': - { - std::cout << "Fracturing with Voronoi..." << std::endl; - voronoiSitesGenerator->uniformlyGenerateSitesInMesh(cellsCount.getValue()); - const physx::PxVec3* sites = nullptr; - uint32_t sitesCount = voronoiSitesGenerator->getVoronoiSites(sites); - if (fTool->voronoiFracturing(0, sitesCount, sites, false) != 0) - { - std::cerr << "Failed to fracture with Voronoi" << std::endl; - return -1; - } - break; - } - case 'c': - { - std::cout << "Fracturing with Clustered Voronoi..." << std::endl; - voronoiSitesGenerator->clusteredSitesGeneration(cellsCount.getValue(), clusterCount.getValue(), clusterRad.getValue()); - const physx::PxVec3* sites = nullptr; - uint32_t sitesCount = voronoiSitesGenerator->getVoronoiSites(sites); - if (fTool->voronoiFracturing(0, sitesCount, sites, false) != 0) - { - std::cerr << "Failed to fracture with Clustered Voronoi" << std::endl; - return -1; - } - break; - } - case 's': - { - std::cout << "Fracturing with Slicing..." << std::endl; - SlicingConfiguration slConfig; - slConfig.x_slices = slicingNumber.getValue().x; - slConfig.y_slices = slicingNumber.getValue().y; - slConfig.z_slices = slicingNumber.getValue().z; - slConfig.angle_variations = angleVariation.getValue(); - slConfig.offset_variations = offsetVariation.getValue(); - if (fTool->slicing(0, slConfig, false, &rng) != 0) - { - std::cerr << "Failed to fracture with Slicing" << std::endl; - return -1; - } - break; - } - case 'p': - { - std::cout << "Plane cut fracturing..." << std::endl; - NoiseConfiguration noise; - if (fTool->cut(0, normal.getValue(), point.getValue(), noise, false, &rng) != 0) - { - std::cerr << "Failed to fracture with Cutout (in half-space, plane cut)" << std::endl; - return -1; - } - break; - } - case 'u': - { - std::cout << "Cutout fracturing..." << std::endl; - CutoutConfiguration cutoutConfig; - physx::PxVec3 axis = normal.getValue(); - if (axis.isZero()) - { - axis = PxVec3(0.f, 0.f, 1.f); - } - axis.normalize(); - float d = axis.dot(physx::PxVec3(0.f, 0.f, 1.f)); - if (d < (1e-6f - 1.0f)) - { - cutoutConfig.transform.q = physx::PxQuat(physx::PxPi, PxVec3(1.f, 0.f, 0.f)); - } - else if (d < 1.f) - { - float s = physx::PxSqrt((1 + d) * 2); - float invs = 1 / s; - auto c = axis.cross(PxVec3(0.f, 0.f, 1.f)); - cutoutConfig.transform.q = physx::PxQuat(c.x * invs, c.y * invs, c.z * invs, s * 0.5f); - cutoutConfig.transform.q.normalize(); - } - cutoutConfig.transform.p = point.getValue(); - if (cutoutBitmapPath.isSet()) - { - BITMAPINFOHEADER header; - uint8_t* bitmap = LoadBitmapFile(cutoutBitmapPath.getValue().c_str(), &header); - if (bitmap != nullptr) - { - cutoutConfig.cutoutSet = NvBlastExtAuthoringCreateCutoutSet(); - NvBlastExtAuthoringBuildCutoutSet(*cutoutConfig.cutoutSet, bitmap, header.biWidth, header.biHeight, 0.001f, 1.f, false, true); - } - } - if (fTool->cutout(0, cutoutConfig, false, &rng) != 0) - { - std::cerr << "Failed to fracture with Cutout" << std::endl; - return -1; - } - break; - } - default: - std::cerr << "Unknown mode" << std::endl; - return -1; - } - voronoiSitesGenerator->release(); - mesh->release(); - - Nv::Blast::BlastBondGenerator* bondGenerator = NvBlastExtAuthoringCreateBondGenerator(gCooking, &gPhysics->getPhysicsInsertionCallback()); - Nv::Blast::ConvexMeshBuilder* collisionBuilder = NvBlastExtAuthoringCreateConvexMeshBuilder(gCooking, &gPhysics->getPhysicsInsertionCallback()); - Nv::Blast::CollisionParams collisionParameter; - collisionParameter.maximumNumberOfHulls = 1; - collisionParameter.voxelGridResolution = 0; - Nv::Blast::AuthoringResult* result = NvBlastExtAuthoringProcessFracture(*fTool, *bondGenerator, *collisionBuilder, collisionParameter); - NvBlastTkFrameworkCreate(); - - collisionBuilder->release(); - bondGenerator->release(); - fTool->release(); - - // Output the results - // NOTE: Writing to FBX by default. - - std::vector matNames; - for (int32_t i = 0; i < fileReader->getMaterialCount(); ++i) - { - matNames.push_back(fileReader->getMaterialName(i)); - } - result->materialNames = matNames.data(); - result->materialCount = static_cast(matNames.size()); - - - if (!fbxCollision.isSet()) - { - result->releaseCollisionHulls(); - } - - const std::string assetNameFull = outDir + "\\" + assetName; - - if (bOutputObjFile) - { - std::shared_ptr fileWriter(NvBlastExtExporterCreateObjFileWriter(), [](IMeshFileWriter* p) {p->release(); }); - if (interiorMatId.isSet() && interiorMatId.getValue() >= 0) - { - fileWriter->setInteriorIndex(interiorMatId.getValue()); - } - fileWriter->appendMesh(*result, assetName.c_str()); - if (!fileWriter->saveToFile(assetName.c_str(), outDir.c_str())) - { - std::cerr << "Can't write geometry to OBJ file." << std::endl; - return -1; - } - std::cout << "Exported render mesh geometry: " << assetNameFull << ".obj" << std::endl; - } - if (bOutputFbxFile) - { - std::shared_ptr fileWriter(NvBlastExtExporterCreateFbxFileWriter(bOutputFBXAscii), [](IMeshFileWriter* p) {p->release(); }); - if (interiorMatId.isSet() && interiorMatId.getValue() >= 0) - { - fileWriter->setInteriorIndex(interiorMatId.getValue()); - } - fileWriter->appendMesh(*result, assetName.c_str(), nonSkinnedFBX.isSet()); - if (!fileWriter->saveToFile(assetName.c_str(), outDir.c_str())) - { - std::cerr << "Can't write geometry to FBX file." << std::endl; - return -1; - } - if (fbxCollision.isSet()) - { - std::cout << "Exported render mesh and collision geometry: " << assetNameFull << ".fbx" << std::endl; - } - else - { - std::cout << "Exported render mesh geometry: " << assetNameFull << ".fbx" << std::endl; - } - } - - auto saveBlastData = [&](BlastDataExporter& blExpr) - { - if (bOutputLL) - { - blExpr.saveBlastObject(outDir, assetName, result->asset, LlObjectTypeID::Asset); - std::cout << "Exported NvBlastAsset: " << assetNameFull << ".blast" << std::endl; - } - else - { - Nv::Blast::TkAssetDesc descriptor; - descriptor.bondCount = result->bondCount; - descriptor.bondDescs = result->bondDescs; - descriptor.bondFlags = nullptr; - descriptor.chunkCount = result->chunkCount; - descriptor.chunkDescs = result->chunkDescs; - Nv::Blast::ExtPxAsset* physicsAsset = Nv::Blast::ExtPxAsset::create(descriptor, result->physicsChunks, result->physicsSubchunks, *NvBlastTkFrameworkGet()); - if (bOutputTK) - { - blExpr.saveBlastObject(outDir, assetName, &physicsAsset->getTkAsset(), TkObjectTypeID::Asset); - std::cout << "Exported TkAsset: " << assetNameFull << ".blast" << std::endl; - } - else if (bOutputPX) - { - blExpr.saveBlastObject(outDir, assetName, physicsAsset, ExtPxObjectTypeID::Asset); - std::cout << "Exported ExtPxAsset: " << assetNameFull << ".blast" << std::endl; - } - physicsAsset->release(); - } - }; - - BlastDataExporter blExpr(NvBlastTkFrameworkGet(), gPhysics, gCooking); - saveBlastData(blExpr); - - result->release(); - - std::cout << "Success!" << std::endl; - - return 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) 2016-2018 NVIDIA Corporation. All rights reserved. + + +#include "PxPhysicsAPI.h" +#include "PsFileBuffer.h" +#include "NvBlast.h" +#include "NvBlastAssert.h" +#include "NvBlastGlobals.h" +#include "NvBlastExtExporter.h" +#include "NvBlastPxCallbacks.h" +#include "NvBlastTkAsset.h" +#include "NvBlastExtLlSerialization.h" +#include "NvBlastExtTkSerialization.h" +#include "NvBlastExtPxSerialization.h" +#include "NvBlastExtAuthoring.h" +#include "NvBlastExtAuthoringMesh.h" +#include "NvBlastExtAuthoringBondGenerator.h" +#include "NvBlastExtAuthoringCollisionBuilder.h" +#include "NvBlastExtAuthoringCutout.h" +#include "NvBlastExtAuthoringFractureTool.h" +#include "BlastDataExporter.h" +#include "SimpleRandomGenerator.h" +#include "NvBlastExtAuthoringMeshCleaner.h" +#include "NvBlastExtExporterJsonCollision.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include "tclap/CmdLine.h" + +using physx::PxVec3; +using physx::PxVec2; + +#define DEFAULT_ASSET_NAME "AuthoringTest" + +using namespace Nv::Blast; + +physx::PxFoundation* gFoundation = nullptr; +physx::PxPhysics* gPhysics = nullptr; +physx::PxCooking* gCooking = nullptr; + +struct TCLAPint3 +{ + int32_t x, y, z; + TCLAPint3(int32_t x, int32_t y, int32_t z) :x(x), y(y), z(z){}; + TCLAPint3() :x(0), y(0), z(0){}; + TCLAPint3& operator=(const std::string &inp) + { + std::istringstream stream(inp); + if (!(stream >> x >> y >> z)) + throw TCLAP::ArgParseException(inp + " is not int3"); + return *this; + } +}; + +struct TCLAPfloat3 +{ + float x, y, z; + TCLAPfloat3(float x, float y, float z) :x(x), y(y), z(z) {}; + TCLAPfloat3() :x(0), y(0), z(0) {}; + TCLAPfloat3& operator=(const std::string &inp) + { + std::istringstream stream(inp); + if (!(stream >> x >> y >> z)) + throw TCLAP::ArgParseException(inp + " is not float3"); + return *this; + } + + operator physx::PxVec3() + { + return physx::PxVec3(x, y, z); + } +}; + +namespace TCLAP { + template<> + struct ArgTraits { + typedef StringLike ValueCategory; + }; + + template<> + struct ArgTraits { + typedef StringLike ValueCategory; + }; +} + +bool isDirectoryExist(const std::string& path) +{ + DWORD attributes = GetFileAttributesA(path.c_str()); + if ((attributes != INVALID_FILE_ATTRIBUTES) && (attributes & FILE_ATTRIBUTE_DIRECTORY)) + { + return true; + } + return false; +} + +bool isFileExist(const std::string& path) +{ + DWORD attributes = GetFileAttributesA(path.c_str()); + if ((attributes != INVALID_FILE_ATTRIBUTES) && !(attributes & FILE_ATTRIBUTE_DIRECTORY)) + { + return true; + } + return false; +} + +bool mkDirRecursively(const std::string& path) +{ + if (isDirectoryExist(path)) + { + return true; + } + auto indx = path.find_first_of("\\/"); + while (indx != std::string::npos) + { + std::string subfolder = path.substr(0, indx); + CreateDirectory(subfolder.c_str(), NULL); + indx = path.find_first_of("\\/", indx + 1); + } + return isDirectoryExist(path); +} + +unsigned char *LoadBitmapFile(const char *filename, BITMAPINFOHEADER *bitmapInfoHeader) +{ + FILE *filePtr; //our file pointer + BITMAPFILEHEADER bitmapFileHeader; //our bitmap file header + unsigned char *bitmapImage; //store image data + //int imageIdx = 0; //image index counter + unsigned char tempRGB; //our swap variable + + //open filename in read binary mode + filePtr = fopen(filename, "rb"); + if (filePtr == NULL) + return NULL; + + //read the bitmap file header + fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr); + + //verify that this is a bmp file by check bitmap id + if (bitmapFileHeader.bfType != 0x4D42) + { + fclose(filePtr); + return NULL; + } + + //read the bitmap info header + fread(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr); // small edit. forgot to add the closing bracket at sizeof + + //move file point to the begging of bitmap data + fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET); + + //Only incompressed 24 byte RGB is supported + if (bitmapInfoHeader->biCompression != BI_RGB || bitmapInfoHeader->biBitCount != 24) + { + return nullptr; + } + else + { + bitmapInfoHeader->biSizeImage = 3 * bitmapInfoHeader->biHeight * bitmapInfoHeader->biHeight; + } + + //allocate enough memory for the bitmap image data + bitmapImage = (unsigned char*)malloc(bitmapInfoHeader->biSizeImage); + + //verify memory allocation + if (!bitmapImage) + { + free(bitmapImage); + fclose(filePtr); + return NULL; + } + + //read in the bitmap image data + fread(bitmapImage, sizeof(uint8_t), bitmapInfoHeader->biSizeImage, filePtr); + + //make sure bitmap image data was read + if (bitmapImage == NULL) + { + fclose(filePtr); + return NULL; + } + + //swap the r and b values to get RGB (bitmap is BGR) + if (bitmapInfoHeader->biBitCount > 1) + { + for (uint32_t imageIdx = 0; imageIdx < bitmapInfoHeader->biSizeImage; imageIdx += 3) // fixed semicolon + { + tempRGB = bitmapImage[imageIdx]; + bitmapImage[imageIdx] = bitmapImage[imageIdx + 2]; + bitmapImage[imageIdx + 2] = tempRGB; + } + } + + //close file and return bitmap iamge data + fclose(filePtr); + return bitmapImage; +} + +bool initPhysX() +{ + gFoundation = PxCreateFoundation(PX_FOUNDATION_VERSION, NvBlastGetPxAllocatorCallback(), NvBlastGetPxErrorCallback()); + if (!gFoundation) + { + std::cerr << "Can't init PhysX foundation" << std::endl; + return false; + } + physx::PxTolerancesScale scale; + gPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *gFoundation, scale, true); + if (!gPhysics) + { + std::cerr << "Can't create Physics" << std::endl; + return false; + } + physx::PxCookingParams cookingParams(scale); + cookingParams.buildGPUData = true; + gCooking = PxCreateCooking(PX_PHYSICS_VERSION, gPhysics->getFoundation(), cookingParams); + if (!gCooking) + { + std::cerr << "Can't create Cooking" << std::endl; + return false; + } + return true; +} + +int main(int argc, const char* const* argv) +{ + // set blast global error callback + // overriding default one in order to exit tool in profile/release configuration too (and write to stderr) + class CustomErrorCallback : public ErrorCallback + { + virtual void reportError(ErrorCode::Enum code, const char* msg, const char* file, int line) override + { + std::stringstream str; + bool critical = false; + switch (code) + { + case ErrorCode::eNO_ERROR: str << "[Info]"; critical = false; break; + case ErrorCode::eDEBUG_INFO: str << "[Debug Info]"; critical = false; break; + case ErrorCode::eDEBUG_WARNING: str << "[Debug Warning]"; critical = false; break; + case ErrorCode::eINVALID_PARAMETER: str << "[Invalid Parameter]"; critical = true; break; + case ErrorCode::eINVALID_OPERATION: str << "[Invalid Operation]"; critical = true; break; + case ErrorCode::eOUT_OF_MEMORY: str << "[Out of] Memory"; critical = true; break; + case ErrorCode::eINTERNAL_ERROR: str << "[Internal Error]"; critical = true; break; + case ErrorCode::eABORT: str << "[Abort]"; critical = true; break; + case ErrorCode::ePERF_WARNING: str << "[Perf Warning]"; critical = false; break; + default: NVBLAST_ASSERT(false); + } +#if NV_DEBUG || NV_CHECKED + str << file << "(" << line << "): "; +#else + NV_UNUSED(file); + NV_UNUSED(line); +#endif + str << " " << msg << "\n"; + std::cerr << str.str(); + + if (critical) + { + std::cerr << "Authoring failed. Exiting.\n"; + exit(-1); + } + } + }; + CustomErrorCallback errorCallback; + NvBlastGlobalSetErrorCallback(&errorCallback); + + // setup cmd line + TCLAP::CmdLine cmd("Blast SDK: Authoring Tool", ' ', "1.1"); + + TCLAP::UnlabeledValueArg infileArg("file", "File to load", true, "", "infile"); + cmd.add(infileArg); + + TCLAP::UnlabeledValueArg outAssetName("outAssetName", "Output asset name", true, DEFAULT_ASSET_NAME, "output asset name"); + cmd.add(outAssetName); + + TCLAP::ValueArg outDirArg("", "outputDir", "Output directory", false, ".", "by default directory of the input file"); + cmd.add(outDirArg); + + TCLAP::SwitchArg cleanArg("", "clean", "Try cleaning mesh before fracturing", false); + cmd.add(cleanArg); + + // The output modes + //NOTE: Fun TCLAP quirk here - if you set the default to true and specify this switch on the command line, the value will be false! + TCLAP::SwitchArg pxOutputArg("", "px", "Output ExtPxAsset to the .blast file in the output directory.", false); + cmd.add(pxOutputArg); + + TCLAP::SwitchArg tkOutputArg("", "tk", "Output TkAsset to the .blast file in the output directory.", false); + cmd.add(tkOutputArg); + + TCLAP::SwitchArg llOutputArg("", "ll", "Output LL Blast (NvBlastAsset) to the .blast file in the output directory.", false); + cmd.add(llOutputArg); + + TCLAP::SwitchArg fbxAsciiArg("", "fbxascii", "Output FBX as an ascii file (defaults to binary output)", false); + cmd.add(fbxAsciiArg); + + TCLAP::SwitchArg objOutputArg("", "obj", "Output a OBJ mesh to the output directory", false); + cmd.add(objOutputArg); + + TCLAP::SwitchArg fbxOutputArg("", "fbx", "Output a FBX mesh to the output directory", false); + cmd.add(fbxOutputArg); + + TCLAP::SwitchArg fbxCollision("", "fbxcollision", "Add collision geometry to FBX file", false); + cmd.add(fbxCollision); + + TCLAP::SwitchArg jsonCollision("", "jsoncollision", "Save collision geometry to a json file", false); + cmd.add(jsonCollision); + + TCLAP::SwitchArg nonSkinnedFBX("", "nonskinned", "Output a non-skinned FBX file", false); + cmd.add(nonSkinnedFBX); + + TCLAP::ValueArg interiorMatId("", "interiorMat", "Use to setup interior material id, by default new material for internal surface will be created.", false, -1, "by default -1"); + cmd.add(interiorMatId); + + TCLAP::ValueArg fracturingMode("", "mode", "Fracturing mode", false, 'v', + "v - voronoi, c - clustered voronoi, s - slicing, p - plane cut, u - cutout."); + cmd.add(fracturingMode); + TCLAP::ValueArg cellsCount("", "cells", "Voronoi cells count", false, 5, "by default 5"); + cmd.add(cellsCount); + TCLAP::ValueArg clusterCount("", "clusters", "Uniform Voronoi cluster count", false, 5, "by default 5"); + cmd.add(clusterCount); + TCLAP::ValueArg clusterRad("", "radius", "Clustered Voronoi cluster radius", false, 1.0f, "by default 1.0"); + cmd.add(clusterRad); + + TCLAP::ValueArg slicingNumber("", "slices", "Number of slices per direction", false, TCLAPint3(1, 1, 1), "by default 1 1 1"); + cmd.add(slicingNumber); + + TCLAP::ValueArg angleVariation("", "avar", "Slicing angle variation", false, 0.0, "by default 0.0"); + cmd.add(angleVariation); + + TCLAP::ValueArg offsetVariation("", "ovar", "Slicing offset variation", false, 0.0, "by default 0.0"); + cmd.add(offsetVariation); + + TCLAP::ValueArg point("", "point", "Plane surface point", false, TCLAPfloat3(0, 0, 0), "by default 0 0 0"); + cmd.add(point); + + TCLAP::ValueArg normal("", "normal", "Plane surface normal", false, TCLAPfloat3(1, 0, 0), "by default 1 0 0"); + cmd.add(normal); + + TCLAP::ValueArg cutoutBitmapPath("", "cutoutBitmap", "Path to *.bmp file with cutout bitmap", false, ".", "by defualt empty"); + cmd.add(cutoutBitmapPath); + + try + { + // parse cmd input + cmd.parse(argc, argv); + } + catch (TCLAP::ArgException &e) // catch any exceptions + { + std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; + return -1; + } + + // get cmd parse results + std::string infile = infileArg.getValue(); + if (!isFileExist(infile)) + { + std::cerr << "[Error] Can't find input file: " << infile << std::endl; + return -1; + } + + std::string outDir; + + std::cout << "Input file: " << infile << std::endl; + + if (outDirArg.isSet()) + { + outDir = outDirArg.getValue(); + std::string temp = outDir + '/'; + if (!isDirectoryExist(outDir.data())) + { + std::cout << "Output directory doesn't exist. It will be created." << std::endl; + if (!mkDirRecursively(temp.data())) + { + std::cerr << "Directory creation failed!" << std::endl; + return -1; + } + } + } + else + { + auto idx = infile.find_last_of("/\\"); + if (idx == 0 || idx == std::string::npos) + { + outDir = "."; + } + else + { + outDir = infile.substr(0, idx); + } + } + std::cout << "Output directory: " << outDir << std::endl; + std::string assetName = outAssetName.getValue(); + + // Determine whether to use the obj or fbx loader + + auto idx = infile.rfind('.'); + std::string extension; + + + if (idx != std::string::npos) + { + extension = infile.substr(idx + 1); + std::transform(extension.begin(), extension.end(), extension.begin(), std::toupper); + } + else + { + std::cerr << "Can't determine extension (and thus, loader) of input file. " << infile << std::endl; + return -1; + } + + bool bOutputPX = pxOutputArg.getValue(); + bool bOutputTK = tkOutputArg.getValue(); + bool bOutputLL = llOutputArg.getValue(); + + bool bOutputFBXAscii = fbxAsciiArg.getValue(); + + bool bOutputObjFile = objOutputArg.isSet(); + bool bOutputFbxFile = fbxOutputArg.isSet(); + + // Did we specify no output formats? + if (!bOutputPX && !bOutputTK && !bOutputLL) + { + std::cout << "Didn't specify an output format on the command line. Use default: LL Blast asset (NvBlastAsset)." << std::endl; + bOutputLL = true; + } + else if ((int)bOutputPX + (int)bOutputTK + (int)bOutputLL > 1) + { + std::cerr << "More than one of the --ll, --tk, and --px options are set. Choose one. " << std::endl; + return -1; + } + + // Did we specify no geometry output formats? + if (!bOutputObjFile && !bOutputFbxFile) + { + std::cout << "Didn't specify an output geometry format on the command line. Use default: .FBX" << std::endl; + bOutputFbxFile = true; + } + + std::shared_ptr fileReader; + + if (extension.compare("FBX")==0) + { + fileReader = std::shared_ptr(NvBlastExtExporterCreateFbxFileReader(), [](IMeshFileReader* p) {p->release(); }); + } + else if (extension.compare("OBJ")==0) + { + fileReader = std::shared_ptr(NvBlastExtExporterCreateObjFileReader(), [](IMeshFileReader* p) {p->release(); }); + } + else + { + std::cout << "Unsupported file extension " << extension << std::endl; + return -1; + } + + // Load the asset + fileReader->loadFromFile(infile.c_str()); + + uint32_t vcount = fileReader->getVerticesCount(); + + if (!initPhysX()) + { + std::cerr << "Failed to initialize PhysX" << std::endl; + return -1; + } + Nv::Blast::FractureTool* fTool = NvBlastExtAuthoringCreateFractureTool(); + + PxVec3* pos = fileReader->getPositionArray(); + PxVec3* norm = fileReader->getNormalsArray(); + PxVec2* uv = fileReader->getUvArray(); + + Nv::Blast::Mesh* mesh = NvBlastExtAuthoringCreateMesh(pos, norm, uv, vcount, fileReader->getIndexArray(), fileReader->getIndicesCount()); + + if (cleanArg.isSet()) + { + MeshCleaner* clr = NvBlastExtAuthoringCreateMeshCleaner(); + Nv::Blast::Mesh* nmesh; + nmesh = clr->cleanMesh(mesh); + clr->release(); + mesh->release(); + mesh = nmesh; + } + mesh->setMaterialId(fileReader->getMaterialIds()); + mesh->setSmoothingGroup(fileReader->getSmoothingGroups()); + + fTool->setSourceMesh(mesh); + + + SimpleRandomGenerator rng; + Nv::Blast::VoronoiSitesGenerator* voronoiSitesGenerator = NvBlastExtAuthoringCreateVoronoiSitesGenerator(mesh, &rng); + if (voronoiSitesGenerator == nullptr) + { + std::cerr << "Failed to create Voronoi sites generator" << std::endl; + return -1; + } + + // Send it to the fracture processor + + switch (fracturingMode.getValue()) + { + case 'v': + { + std::cout << "Fracturing with Voronoi..." << std::endl; + voronoiSitesGenerator->uniformlyGenerateSitesInMesh(cellsCount.getValue()); + const physx::PxVec3* sites = nullptr; + uint32_t sitesCount = voronoiSitesGenerator->getVoronoiSites(sites); + if (fTool->voronoiFracturing(0, sitesCount, sites, false) != 0) + { + std::cerr << "Failed to fracture with Voronoi" << std::endl; + return -1; + } + break; + } + case 'c': + { + std::cout << "Fracturing with Clustered Voronoi..." << std::endl; + voronoiSitesGenerator->clusteredSitesGeneration(cellsCount.getValue(), clusterCount.getValue(), clusterRad.getValue()); + const physx::PxVec3* sites = nullptr; + uint32_t sitesCount = voronoiSitesGenerator->getVoronoiSites(sites); + if (fTool->voronoiFracturing(0, sitesCount, sites, false) != 0) + { + std::cerr << "Failed to fracture with Clustered Voronoi" << std::endl; + return -1; + } + break; + } + case 's': + { + std::cout << "Fracturing with Slicing..." << std::endl; + SlicingConfiguration slConfig; + slConfig.x_slices = slicingNumber.getValue().x; + slConfig.y_slices = slicingNumber.getValue().y; + slConfig.z_slices = slicingNumber.getValue().z; + slConfig.angle_variations = angleVariation.getValue(); + slConfig.offset_variations = offsetVariation.getValue(); + if (fTool->slicing(0, slConfig, false, &rng) != 0) + { + std::cerr << "Failed to fracture with Slicing" << std::endl; + return -1; + } + break; + } + case 'p': + { + std::cout << "Plane cut fracturing..." << std::endl; + NoiseConfiguration noise; + if (fTool->cut(0, normal.getValue(), point.getValue(), noise, false, &rng) != 0) + { + std::cerr << "Failed to fracture with Cutout (in half-space, plane cut)" << std::endl; + return -1; + } + break; + } + case 'u': + { + std::cout << "Cutout fracturing..." << std::endl; + CutoutConfiguration cutoutConfig; + physx::PxVec3 axis = normal.getValue(); + if (axis.isZero()) + { + axis = PxVec3(0.f, 0.f, 1.f); + } + axis.normalize(); + float d = axis.dot(physx::PxVec3(0.f, 0.f, 1.f)); + if (d < (1e-6f - 1.0f)) + { + cutoutConfig.transform.q = physx::PxQuat(physx::PxPi, PxVec3(1.f, 0.f, 0.f)); + } + else if (d < 1.f) + { + float s = physx::PxSqrt((1 + d) * 2); + float invs = 1 / s; + auto c = axis.cross(PxVec3(0.f, 0.f, 1.f)); + cutoutConfig.transform.q = physx::PxQuat(c.x * invs, c.y * invs, c.z * invs, s * 0.5f); + cutoutConfig.transform.q.normalize(); + } + cutoutConfig.transform.p = point.getValue(); + if (cutoutBitmapPath.isSet()) + { + BITMAPINFOHEADER header; + uint8_t* bitmap = LoadBitmapFile(cutoutBitmapPath.getValue().c_str(), &header); + if (bitmap != nullptr) + { + cutoutConfig.cutoutSet = NvBlastExtAuthoringCreateCutoutSet(); + NvBlastExtAuthoringBuildCutoutSet(*cutoutConfig.cutoutSet, bitmap, header.biWidth, header.biHeight, 0.001f, 1.f, false, true); + } + } + if (fTool->cutout(0, cutoutConfig, false, &rng) != 0) + { + std::cerr << "Failed to fracture with Cutout" << std::endl; + return -1; + } + break; + } + default: + std::cerr << "Unknown mode" << std::endl; + return -1; + } + voronoiSitesGenerator->release(); + mesh->release(); + + Nv::Blast::BlastBondGenerator* bondGenerator = NvBlastExtAuthoringCreateBondGenerator(gCooking, &gPhysics->getPhysicsInsertionCallback()); + Nv::Blast::ConvexMeshBuilder* collisionBuilder = NvBlastExtAuthoringCreateConvexMeshBuilder(gCooking, &gPhysics->getPhysicsInsertionCallback()); + Nv::Blast::CollisionParams collisionParameter; + collisionParameter.maximumNumberOfHulls = 1; + collisionParameter.voxelGridResolution = 0; + Nv::Blast::AuthoringResult* result = NvBlastExtAuthoringProcessFracture(*fTool, *bondGenerator, *collisionBuilder, collisionParameter); + NvBlastTkFrameworkCreate(); + + collisionBuilder->release(); + bondGenerator->release(); + fTool->release(); + + // Output the results + // NOTE: Writing to FBX by default. + + std::vector matNames; + for (int32_t i = 0; i < fileReader->getMaterialCount(); ++i) + { + matNames.push_back(fileReader->getMaterialName(i)); + } + result->materialNames = matNames.data(); + result->materialCount = static_cast(matNames.size()); + + const std::string assetNameFull = outDir + "\\" + assetName; + + if (jsonCollision.isSet()) + { + const std::string fullJsonFilename = assetNameFull + ".json"; + IJsonCollisionExporter* collisionExporter = NvBlastExtExporterCreateJsonCollisionExporter(); + if (collisionExporter != nullptr) + { + if (collisionExporter->writeCollision(fullJsonFilename.c_str(), result->chunkCount, result->collisionHullOffset, result->collisionHull)) + { + std::cout << "Exported collision geometry: " << fullJsonFilename << std::endl; + } + else + { + std::cerr << "Can't write collision geometry to json file." << std::endl; + } + collisionExporter->release(); + } + } + + if (!fbxCollision.isSet()) + { + result->releaseCollisionHulls(); + } + + if (bOutputObjFile) + { + std::shared_ptr fileWriter(NvBlastExtExporterCreateObjFileWriter(), [](IMeshFileWriter* p) {p->release(); }); + if (interiorMatId.isSet() && interiorMatId.getValue() >= 0) + { + fileWriter->setInteriorIndex(interiorMatId.getValue()); + } + fileWriter->appendMesh(*result, assetName.c_str()); + if (!fileWriter->saveToFile(assetName.c_str(), outDir.c_str())) + { + std::cerr << "Can't write geometry to OBJ file." << std::endl; + return -1; + } + std::cout << "Exported render mesh geometry: " << assetNameFull << ".obj" << std::endl; + } + if (bOutputFbxFile) + { + std::shared_ptr fileWriter(NvBlastExtExporterCreateFbxFileWriter(bOutputFBXAscii), [](IMeshFileWriter* p) {p->release(); }); + if (interiorMatId.isSet() && interiorMatId.getValue() >= 0) + { + fileWriter->setInteriorIndex(interiorMatId.getValue()); + } + fileWriter->appendMesh(*result, assetName.c_str(), nonSkinnedFBX.isSet()); + if (!fileWriter->saveToFile(assetName.c_str(), outDir.c_str())) + { + std::cerr << "Can't write geometry to FBX file." << std::endl; + return -1; + } + if (fbxCollision.isSet()) + { + std::cout << "Exported render mesh and collision geometry: " << assetNameFull << ".fbx" << std::endl; + } + else + { + std::cout << "Exported render mesh geometry: " << assetNameFull << ".fbx" << std::endl; + } + } + + auto saveBlastData = [&](BlastDataExporter& blExpr) + { + if (bOutputLL) + { + blExpr.saveBlastObject(outDir, assetName, result->asset, LlObjectTypeID::Asset); + std::cout << "Exported NvBlastAsset: " << assetNameFull << ".blast" << std::endl; + } + else + { + Nv::Blast::TkAssetDesc descriptor; + descriptor.bondCount = result->bondCount; + descriptor.bondDescs = result->bondDescs; + descriptor.bondFlags = nullptr; + descriptor.chunkCount = result->chunkCount; + descriptor.chunkDescs = result->chunkDescs; + Nv::Blast::ExtPxAsset* physicsAsset = Nv::Blast::ExtPxAsset::create(descriptor, result->physicsChunks, result->physicsSubchunks, *NvBlastTkFrameworkGet()); + if (bOutputTK) + { + blExpr.saveBlastObject(outDir, assetName, &physicsAsset->getTkAsset(), TkObjectTypeID::Asset); + std::cout << "Exported TkAsset: " << assetNameFull << ".blast" << std::endl; + } + else if (bOutputPX) + { + blExpr.saveBlastObject(outDir, assetName, physicsAsset, ExtPxObjectTypeID::Asset); + std::cout << "Exported ExtPxAsset: " << assetNameFull << ".blast" << std::endl; + } + physicsAsset->release(); + } + }; + + BlastDataExporter blExpr(NvBlastTkFrameworkGet(), gPhysics, gCooking); + saveBlastData(blExpr); + + result->release(); + + std::cout << "Success!" << std::endl; + + return 0; +} diff --git a/tools/AuthoringTool/src/SimpleRandomGenerator.h b/tools/AuthoringTool/src/SimpleRandomGenerator.h old mode 100644 new mode 100755 index 63e2d45..9ad06ea --- a/tools/AuthoringTool/src/SimpleRandomGenerator.h +++ b/tools/AuthoringTool/src/SimpleRandomGenerator.h @@ -1,27 +1,27 @@ -#pragma once -#include "NvBlastExtAuthoringTypes.h" - - -class SimpleRandomGenerator : public Nv::Blast::RandomGeneratorBase -{ -public: - SimpleRandomGenerator() { - remember = false; - }; - - virtual float getRandomValue() - { - float r = (float)rand(); - r = r / RAND_MAX; - return r; - } - virtual void seed(int32_t seed) - { - srand(seed); - } - - virtual ~SimpleRandomGenerator() {}; - -private: - bool remember; +#pragma once +#include "NvBlastExtAuthoringTypes.h" + + +class SimpleRandomGenerator : public Nv::Blast::RandomGeneratorBase +{ +public: + SimpleRandomGenerator() { + remember = false; + }; + + virtual float getRandomValue() + { + float r = (float)rand(); + r = r / RAND_MAX; + return r; + } + virtual void seed(int32_t seed) + { + srand(seed); + } + + virtual ~SimpleRandomGenerator() {}; + +private: + bool remember; }; \ No newline at end of file diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt old mode 100644 new mode 100755 index 6e3c58c..6bb6507 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,95 +1,95 @@ -cmake_minimum_required(VERSION 3.3) - -project(BlastTools CXX) - -CMAKE_POLICY(SET CMP0057 NEW) # Enable IN_LIST - -IF(NOT DEFINED BLAST_ROOT_DIR) - - STRING(REPLACE "\\" "/" BRD_TEMP $ENV{BLAST_ROOT_DIR}) - - # This env variable is set by GenerateProjects.bat, and is no longer available when CMake rebuilds, so this stores it in the cache - SET(BLAST_ROOT_DIR ${BRD_TEMP} CACHE INTERNAL "Root of the Blast source tree") - -ENDIF() - -IF(NOT EXISTS ${BLAST_ROOT_DIR}) - MESSAGE(FATAL_ERROR "BLAST_ROOT_DIR environment variable wasn't set or was invalid.") -ENDIF() - - -SET(GW_DEPS_ROOT $ENV{PM_PACKAGES_ROOT}) - -# Add the project specific CMake modules to the module path -LIST(APPEND CMAKE_MODULE_PATH ${BLAST_ROOT_DIR}/sdk/compiler/cmake/modules/) - -IF(NOT DEFINED CMAKEMODULES_VERSION) - SET(CMAKEMODULES_VERSION $ENV{PM_CMakeModules_VERSION} CACHE INTERNAL "CMakeModules version from generation batch") -ENDIF() - -#TODO: More elegance -IF(NOT EXISTS ${GW_DEPS_ROOT}/$ENV{PM_CMakeModules_NAME}/${CMAKEMODULES_VERSION}) - MESSAGE(FATAL_ERROR "Could not find $ENV{PM_CMakeModules_NAME}/${CMAKEMODULES_VERSION} at ${GW_DEPS_ROOT}") -ENDIF() - -SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${GW_DEPS_ROOT}/$ENV{PM_CMakeModules_NAME}/${CMAKEMODULES_VERSION}") - -MESSAGE("Module path:" ${CMAKE_MODULE_PATH}) - - -IF(CMAKE_CONFIGURATION_TYPES) - SET(CMAKE_CONFIGURATION_TYPES debug profile checked release) - SET(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING - "Reset config to what we need" - FORCE) - - SET(CMAKE_SHARED_LINKER_FLAGS_CHECKED "") - SET(CMAKE_SHARED_LINKER_FLAGS_PROFILE "") - - SET(CMAKE_EXE_LINKER_FLAGS_CHECKED "") - SET(CMAKE_EXE_LINKER_FLAGS_PROFILE "") - -ENDIF() - -# Default to appending "DEBUG", "PROFILE", etc to produced artifacts -IF(NOT DEFINED APPEND_CONFIG_NAME) - SET(APPEND_CONFIG_NAME ON) -ENDIF() - -IF (APPEND_CONFIG_NAME) - MESSAGE("Appending config to output names") - - SET(CMAKE_DEBUG_POSTFIX "DEBUG") - SET(CMAKE_PROFILE_POSTFIX "PROFILE") - SET(CMAKE_CHECKED_POSTFIX "CHECKED") - SET(CMAKE_RELEASE_POSTFIX "") -ENDIF() - -INCLUDE(SetOutputPaths) - -# Either have to define a single output path, or each one. - -IF(NOT DEFINED BL_OUTPUT_DIR) - IF (NOT DEFINED BL_LIB_OUTPUT_DIR) - MESSAGE(FATAL_ERROR "BL_LIB_OUTPUT_DIR not defined - Define either BL_OUTPUT_DIR or BL_LIB_OUTPUT_DIR and BL_DLL_OUTPUT_DIR and BL_EXE_OUTPUT_DIR") - ENDIF() - - IF (NOT DEFINED BL_DLL_OUTPUT_DIR) - MESSAGE(FATAL_ERROR "BL_DLL_OUTPUT_DIR not defined - Define either BL_OUTPUT_DIR or BL_LIB_OUTPUT_DIR and BL_DLL_OUTPUT_DIR and BL_EXE_OUTPUT_DIR") - ENDIF() - - IF (NOT DEFINED BL_EXE_OUTPUT_DIR) - MESSAGE(FATAL_ERROR "BL_EXE_OUTPUT_DIR not defined - Define either BL_OUTPUT_DIR or BL_LIB_OUTPUT_DIR and BL_DLL_OUTPUT_DIR and BL_EXE_OUTPUT_DIR") - ENDIF() - - SetLibOutputPath(${BL_LIB_OUTPUT_DIR}) - SetDllOutputPath(${BL_DLL_OUTPUT_DIR}) - SetExeOutputPath(${BL_EXE_OUTPUT_DIR}) -ELSE() - SetSingleOutputPath(${BL_OUTPUT_DIR}) -ENDIF() - -SET(PROJECT_CMAKE_FILES_DIR compiler/cmake/) - -# Include the platform specific configuration -INCLUDE(${PROJECT_CMAKE_FILES_DIR}${TARGET_BUILD_PLATFORM}/CMakeLists.txt OPTIONAL) +cmake_minimum_required(VERSION 3.3) + +project(BlastTools CXX) + +CMAKE_POLICY(SET CMP0057 NEW) # Enable IN_LIST + +IF(NOT DEFINED BLAST_ROOT_DIR) + + STRING(REPLACE "\\" "/" BRD_TEMP $ENV{BLAST_ROOT_DIR}) + + # This env variable is set by GenerateProjects.bat, and is no longer available when CMake rebuilds, so this stores it in the cache + SET(BLAST_ROOT_DIR ${BRD_TEMP} CACHE INTERNAL "Root of the Blast source tree") + +ENDIF() + +IF(NOT EXISTS ${BLAST_ROOT_DIR}) + MESSAGE(FATAL_ERROR "BLAST_ROOT_DIR environment variable wasn't set or was invalid.") +ENDIF() + + +SET(GW_DEPS_ROOT $ENV{PM_PACKAGES_ROOT}) + +# Add the project specific CMake modules to the module path +LIST(APPEND CMAKE_MODULE_PATH ${BLAST_ROOT_DIR}/sdk/compiler/cmake/modules/) + +IF(NOT DEFINED CMAKEMODULES_VERSION) + SET(CMAKEMODULES_VERSION $ENV{PM_CMakeModules_VERSION} CACHE INTERNAL "CMakeModules version from generation batch") +ENDIF() + +#TODO: More elegance +IF(NOT EXISTS $ENV{PM_CMakeModules_PATH}) + MESSAGE(FATAL_ERROR "Could not find $ENV{PM_CMakeModules_PATH}") +ENDIF() + +SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "$ENV{PM_CMakeModules_PATH}") + +MESSAGE("Module path:" ${CMAKE_MODULE_PATH}) + + +IF(CMAKE_CONFIGURATION_TYPES) + SET(CMAKE_CONFIGURATION_TYPES debug profile checked release) + SET(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING + "Reset config to what we need" + FORCE) + + SET(CMAKE_SHARED_LINKER_FLAGS_CHECKED "") + SET(CMAKE_SHARED_LINKER_FLAGS_PROFILE "") + + SET(CMAKE_EXE_LINKER_FLAGS_CHECKED "") + SET(CMAKE_EXE_LINKER_FLAGS_PROFILE "") + +ENDIF() + +# Default to appending "DEBUG", "PROFILE", etc to produced artifacts +IF(NOT DEFINED APPEND_CONFIG_NAME) + SET(APPEND_CONFIG_NAME ON) +ENDIF() + +IF (APPEND_CONFIG_NAME) + MESSAGE("Appending config to output names") + + SET(CMAKE_DEBUG_POSTFIX "DEBUG") + SET(CMAKE_PROFILE_POSTFIX "PROFILE") + SET(CMAKE_CHECKED_POSTFIX "CHECKED") + SET(CMAKE_RELEASE_POSTFIX "") +ENDIF() + +INCLUDE(SetOutputPaths) + +# Either have to define a single output path, or each one. + +IF(NOT DEFINED BL_OUTPUT_DIR) + IF (NOT DEFINED BL_LIB_OUTPUT_DIR) + MESSAGE(FATAL_ERROR "BL_LIB_OUTPUT_DIR not defined - Define either BL_OUTPUT_DIR or BL_LIB_OUTPUT_DIR and BL_DLL_OUTPUT_DIR and BL_EXE_OUTPUT_DIR") + ENDIF() + + IF (NOT DEFINED BL_DLL_OUTPUT_DIR) + MESSAGE(FATAL_ERROR "BL_DLL_OUTPUT_DIR not defined - Define either BL_OUTPUT_DIR or BL_LIB_OUTPUT_DIR and BL_DLL_OUTPUT_DIR and BL_EXE_OUTPUT_DIR") + ENDIF() + + IF (NOT DEFINED BL_EXE_OUTPUT_DIR) + MESSAGE(FATAL_ERROR "BL_EXE_OUTPUT_DIR not defined - Define either BL_OUTPUT_DIR or BL_LIB_OUTPUT_DIR and BL_DLL_OUTPUT_DIR and BL_EXE_OUTPUT_DIR") + ENDIF() + + SetLibOutputPath(${BL_LIB_OUTPUT_DIR}) + SetDllOutputPath(${BL_DLL_OUTPUT_DIR}) + SetExeOutputPath(${BL_EXE_OUTPUT_DIR}) +ELSE() + SetSingleOutputPath(${BL_OUTPUT_DIR}) +ENDIF() + +SET(PROJECT_CMAKE_FILES_DIR compiler/cmake/) + +# Include the platform specific configuration +INCLUDE(${PROJECT_CMAKE_FILES_DIR}${TARGET_BUILD_PLATFORM}/CMakeLists.txt OPTIONAL) diff --git a/tools/LegacyConverter/src/Main.cpp b/tools/LegacyConverter/src/Main.cpp old mode 100644 new mode 100755 index 74f261f..c3f677e --- a/tools/LegacyConverter/src/Main.cpp +++ b/tools/LegacyConverter/src/Main.cpp @@ -1,329 +1,329 @@ -// 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) 2018 NVIDIA Corporation. All rights reserved. - - -#include "NvBlastExtSerialization.h" -#include "NvBlastExtLlSerialization.h" -#include "NvBlastExtTkSerialization.h" -#include "NvBlastExtPxSerialization.h" -#include "NvBlastTk.h" -#include -#include -#include "tclap/CmdLine.h" -#include -#include -#include -#include - -#include "PxIO.h" -#include "PxPhysics.h" -#include "PxFileBuf.h" -#include "cooking/PxCooking.h" - -#include "NvBlastExtSerializationInternal.h" -#include "NvBlastPxCallbacks.h" -#include "PxFoundation.h" -#include "PxFoundationVersion.h" -#include "PxPhysicsVersion.h" - - -using namespace Nv::Blast; -using namespace physx; -using namespace physx::general_PxIOStream2; - - -static ExtSerializationInternal* sSer = nullptr; -static TkFramework* sFwk = nullptr; -static PxFoundation* sFnd = nullptr; -static PxPhysics* sPhys = nullptr; -static PxCooking* sCook = nullptr; - - -static void str_to_upper(std::string& str) -{ - for (auto & c : str) c = (char)::toupper(c); -} - - -static void decompose_filename(std::string& name, std::string& ext, const std::string& filename) -{ - const size_t pos = filename.find_last_of('.'); - if (pos != std::string::npos) - { - name = filename.substr(0, pos); - ext = filename.substr(pos + 1); - } - else - { - name = filename; - ext = ""; - } -} - - -static uint32_t encodingID_from_str(const std::string& str) -{ - const char* s = str.c_str(); - return str.length() >= 4 ? NVBLAST_FOURCC(s[0], s[1], s[2], s[3]) : 0; -} - - -static int init_framework() -{ - // create serialization manager and load all serializers - sSer = static_cast(NvBlastExtSerializationCreate()); - if (sSer == nullptr) - { - std::cerr << "FAIL: Could not create serialization manager" << std::endl; - return -1; - } - - sFwk = NvBlastTkFrameworkCreate(); - if (sFwk != nullptr) - { - NvBlastExtTkSerializerLoadSet(*sFwk, *sSer); - } - - sFnd = PxCreateFoundation(PX_FOUNDATION_VERSION, NvBlastGetPxAllocatorCallback(), NvBlastGetPxErrorCallback()); - if (sFnd != nullptr) - { - PxTolerancesScale tol; - PxCookingParams cookingParams(tol); - cookingParams.buildGPUData = true; - sPhys = PxCreatePhysics(PX_PHYSICS_VERSION, *sFnd, tol, true); - if (sPhys != nullptr) - { - sCook = PxCreateCooking(PX_PHYSICS_VERSION, sPhys->getFoundation(), cookingParams); - if (sPhys != nullptr && sCook != nullptr) - { - NvBlastExtPxSerializerLoadSet(*sFwk, *sPhys, *sCook, *sSer); - return 0; - } - } - } - - return -1; -} - - -static void term_framework() -{ - // release serialization - if (sSer != nullptr) - { - sSer->release(); - } - - // release framework, physics, foundation, and cooking - if (sCook != nullptr) - { - sCook->release(); - } - if (sPhys != nullptr) - { - sPhys->release(); - } - if (sFnd != nullptr) - { - sFnd->release(); - } - if (sFwk != nullptr) - { - sFwk->release(); - } -} - - -static bool parse_inputs(uint32_t& objectTypeID, uint32_t& inEncodingID, std::string& outfile, uint32_t& outEncodingID, TCLAP::CmdLine& cmd, std::vector& args, const std::string& infile) -{ - TCLAP::ValueArg typeArg("t", "type", "Input file type: llasset, tkasset, bpxa, pllasset, ptkasset, or pbpxa. The default will be based upon the input filename's extension.", false, "", "type"); - cmd.add(typeArg); - TCLAP::ValueArg outfileArg("o", "outfile", "Output filename. The extension will be .blast if none is given in the filename. If no outfile is given, infile with .blast extension will be used.", false, "", "outfile"); - cmd.add(outfileArg); - TCLAP::ValueArg encodingArg("e", "encoding", "Output encoding: cpnb or raw (default is cpnb).", false, "", "encoding"); - cmd.add(encodingArg); - - cmd.parse(args); - - std::string name; - std::string ext; - decompose_filename(name, ext, infile); - - std::string type = typeArg.isSet() ? typeArg.getValue() : ext; - str_to_upper(type); - const char* types[] = { "LLASSET", "PLLASSET", "TKASSET", "PTKASSET", "BPXA", "PBPXA" }; - size_t typeIndex = 0; - for (; typeIndex < sizeof(types) / sizeof(types[0]) && type != types[typeIndex]; ++typeIndex) {} - - inEncodingID = ExtSerialization::EncodingID::CapnProtoBinary; - switch (typeIndex) - { - case 0: - inEncodingID = ExtSerialization::EncodingID::RawBinary; - case 1: - objectTypeID = LlObjectTypeID::Asset; - break; - case 2: - inEncodingID = ExtSerialization::EncodingID::RawBinary; - case 3: - objectTypeID = TkObjectTypeID::Asset; - break; - case 4: - inEncodingID = ExtSerialization::EncodingID::RawBinary; - case 5: - objectTypeID = ExtPxObjectTypeID::Asset; - break; - default: - return false; - } - - if (outfileArg.isSet()) - { - outfile = outfileArg.getValue(); - if (std::string::npos == outfile.find_first_of('.')) - { - outfile += ".blast"; - } - } - else - { - outfile = name + ".blast"; - } - - std::string encoding = encodingArg.isSet() ? encodingArg.getValue() : "CPNB"; - str_to_upper(encoding); - if (encoding.length() < 4) - { - encoding.insert(encoding.end(), 4 - encoding.length(), ' '); - } - outEncodingID = encodingID_from_str(encoding); - - return true; -} - - -int customMain(std::vector& args) -{ - try - { - // setup cmd line - TCLAP::CmdLine cmd("Blast Legacy File Converter", ' ', "1.0"); - - // parse cmd input - std::string infile; - if (args.size() > 1) - { - infile = args[1]; - args.erase(args.begin() + 1); - } - uint32_t objectTypeID; - uint32_t inEncodingID; - std::string outfile; - uint32_t outEncodingID; - if (!parse_inputs(objectTypeID, inEncodingID, outfile, outEncodingID, cmd, args, infile)) - { - std::cerr << "FAIL: Could not parse inputs" << std::endl; - return -1; - } - - if (init_framework()) - { - return -1; - } - - sSer->setSerializationEncoding(outEncodingID); - - // find serializer - ExtSerializer* serializer = sSer->findSerializer(objectTypeID, inEncodingID); - if (serializer == nullptr) - { - std::cerr << "FAIL: No serializer for the file object type and encoding found" << std::endl; - return -1; - } - - // read input file - std::ifstream infileStream(infile.c_str(), std::ios::binary); - if (!infileStream.is_open()) - { - std::cerr << "FAIL: Can't open input file: " << infile << std::endl; - return -1; - } - const std::vector inBuffer((std::istreambuf_iterator(infileStream)), std::istreambuf_iterator()); - infileStream.close(); - - // deserialize - void* object = serializer->deserializeFromBuffer(inBuffer.data(), inBuffer.size()); - if (object == nullptr) - { - std::cerr << "FAIL: serializer could not deserialize data from input file: " << infile << std::endl; - return -1; - } - - // serialize using manager, so that the appropriate header information is written - void* outBuffer; - const uint64_t bytesWritten = sSer->serializeIntoBuffer(outBuffer, object, objectTypeID); - if (bytesWritten == 0) - { - std::cerr << "FAIL: could not serialize object in requested output format" << std::endl; - return -1; - } - - // release object - NVBLAST_FREE(object); - - // write file - std::ofstream outfileStream(outfile.c_str(), std::ios::binary); - if (!outfileStream.is_open()) - { - std::cerr << "FAIL: Can't open output file: " << outfile << std::endl; - return -1; - } - outfileStream.write(reinterpret_cast(outBuffer), bytesWritten); - outfileStream.close(); - - // release buffer - NVBLAST_FREE(outBuffer); - - // release framework - term_framework(); - } - catch (TCLAP::ArgException &e) // catch any exceptions - { - std::cout << "error: " << e.error() << " for arg " << e.argId() << std::endl; - } - - return 0; -} - - -int main(int argc, const char* const* argv) -{ - std::vector args; - for (int i = 0; i < argc; i++) - args.push_back(argv[i]); - return customMain(args); -} +// 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) 2018 NVIDIA Corporation. All rights reserved. + + +#include "NvBlastExtSerialization.h" +#include "NvBlastExtLlSerialization.h" +#include "NvBlastExtTkSerialization.h" +#include "NvBlastExtPxSerialization.h" +#include "NvBlastTk.h" +#include +#include +#include "tclap/CmdLine.h" +#include +#include +#include +#include + +#include "PxIO.h" +#include "PxPhysics.h" +#include "PxFileBuf.h" +#include "cooking/PxCooking.h" + +#include "NvBlastExtSerializationInternal.h" +#include "NvBlastPxCallbacks.h" +#include "PxFoundation.h" +#include "PxFoundationVersion.h" +#include "PxPhysicsVersion.h" + + +using namespace Nv::Blast; +using namespace physx; +using namespace physx::general_PxIOStream2; + + +static ExtSerializationInternal* sSer = nullptr; +static TkFramework* sFwk = nullptr; +static PxFoundation* sFnd = nullptr; +static PxPhysics* sPhys = nullptr; +static PxCooking* sCook = nullptr; + + +static void str_to_upper(std::string& str) +{ + for (auto & c : str) c = (char)::toupper(c); +} + + +static void decompose_filename(std::string& name, std::string& ext, const std::string& filename) +{ + const size_t pos = filename.find_last_of('.'); + if (pos != std::string::npos) + { + name = filename.substr(0, pos); + ext = filename.substr(pos + 1); + } + else + { + name = filename; + ext = ""; + } +} + + +static uint32_t encodingID_from_str(const std::string& str) +{ + const char* s = str.c_str(); + return str.length() >= 4 ? NVBLAST_FOURCC(s[0], s[1], s[2], s[3]) : 0; +} + + +static int init_framework() +{ + // create serialization manager and load all serializers + sSer = static_cast(NvBlastExtSerializationCreate()); + if (sSer == nullptr) + { + std::cerr << "FAIL: Could not create serialization manager" << std::endl; + return -1; + } + + sFwk = NvBlastTkFrameworkCreate(); + if (sFwk != nullptr) + { + NvBlastExtTkSerializerLoadSet(*sFwk, *sSer); + } + + sFnd = PxCreateFoundation(PX_FOUNDATION_VERSION, NvBlastGetPxAllocatorCallback(), NvBlastGetPxErrorCallback()); + if (sFnd != nullptr) + { + PxTolerancesScale tol; + PxCookingParams cookingParams(tol); + cookingParams.buildGPUData = true; + sPhys = PxCreatePhysics(PX_PHYSICS_VERSION, *sFnd, tol, true); + if (sPhys != nullptr) + { + sCook = PxCreateCooking(PX_PHYSICS_VERSION, sPhys->getFoundation(), cookingParams); + if (sPhys != nullptr && sCook != nullptr) + { + NvBlastExtPxSerializerLoadSet(*sFwk, *sPhys, *sCook, *sSer); + return 0; + } + } + } + + return -1; +} + + +static void term_framework() +{ + // release serialization + if (sSer != nullptr) + { + sSer->release(); + } + + // release framework, physics, foundation, and cooking + if (sCook != nullptr) + { + sCook->release(); + } + if (sPhys != nullptr) + { + sPhys->release(); + } + if (sFnd != nullptr) + { + sFnd->release(); + } + if (sFwk != nullptr) + { + sFwk->release(); + } +} + + +static bool parse_inputs(uint32_t& objectTypeID, uint32_t& inEncodingID, std::string& outfile, uint32_t& outEncodingID, TCLAP::CmdLine& cmd, std::vector& args, const std::string& infile) +{ + TCLAP::ValueArg typeArg("t", "type", "Input file type: llasset, tkasset, bpxa, pllasset, ptkasset, or pbpxa. The default will be based upon the input filename's extension.", false, "", "type"); + cmd.add(typeArg); + TCLAP::ValueArg outfileArg("o", "outfile", "Output filename. The extension will be .blast if none is given in the filename. If no outfile is given, infile with .blast extension will be used.", false, "", "outfile"); + cmd.add(outfileArg); + TCLAP::ValueArg encodingArg("e", "encoding", "Output encoding: cpnb or raw (default is cpnb).", false, "", "encoding"); + cmd.add(encodingArg); + + cmd.parse(args); + + std::string name; + std::string ext; + decompose_filename(name, ext, infile); + + std::string type = typeArg.isSet() ? typeArg.getValue() : ext; + str_to_upper(type); + const char* types[] = { "LLASSET", "PLLASSET", "TKASSET", "PTKASSET", "BPXA", "PBPXA" }; + size_t typeIndex = 0; + for (; typeIndex < sizeof(types) / sizeof(types[0]) && type != types[typeIndex]; ++typeIndex) {} + + inEncodingID = ExtSerialization::EncodingID::CapnProtoBinary; + switch (typeIndex) + { + case 0: + inEncodingID = ExtSerialization::EncodingID::RawBinary; + case 1: + objectTypeID = LlObjectTypeID::Asset; + break; + case 2: + inEncodingID = ExtSerialization::EncodingID::RawBinary; + case 3: + objectTypeID = TkObjectTypeID::Asset; + break; + case 4: + inEncodingID = ExtSerialization::EncodingID::RawBinary; + case 5: + objectTypeID = ExtPxObjectTypeID::Asset; + break; + default: + return false; + } + + if (outfileArg.isSet()) + { + outfile = outfileArg.getValue(); + if (std::string::npos == outfile.find_first_of('.')) + { + outfile += ".blast"; + } + } + else + { + outfile = name + ".blast"; + } + + std::string encoding = encodingArg.isSet() ? encodingArg.getValue() : "CPNB"; + str_to_upper(encoding); + if (encoding.length() < 4) + { + encoding.insert(encoding.end(), 4 - encoding.length(), ' '); + } + outEncodingID = encodingID_from_str(encoding); + + return true; +} + + +int customMain(std::vector& args) +{ + try + { + // setup cmd line + TCLAP::CmdLine cmd("Blast Legacy File Converter", ' ', "1.0"); + + // parse cmd input + std::string infile; + if (args.size() > 1) + { + infile = args[1]; + args.erase(args.begin() + 1); + } + uint32_t objectTypeID; + uint32_t inEncodingID; + std::string outfile; + uint32_t outEncodingID; + if (!parse_inputs(objectTypeID, inEncodingID, outfile, outEncodingID, cmd, args, infile)) + { + std::cerr << "FAIL: Could not parse inputs" << std::endl; + return -1; + } + + if (init_framework()) + { + return -1; + } + + sSer->setSerializationEncoding(outEncodingID); + + // find serializer + ExtSerializer* serializer = sSer->findSerializer(objectTypeID, inEncodingID); + if (serializer == nullptr) + { + std::cerr << "FAIL: No serializer for the file object type and encoding found" << std::endl; + return -1; + } + + // read input file + std::ifstream infileStream(infile.c_str(), std::ios::binary); + if (!infileStream.is_open()) + { + std::cerr << "FAIL: Can't open input file: " << infile << std::endl; + return -1; + } + const std::vector inBuffer((std::istreambuf_iterator(infileStream)), std::istreambuf_iterator()); + infileStream.close(); + + // deserialize + void* object = serializer->deserializeFromBuffer(inBuffer.data(), inBuffer.size()); + if (object == nullptr) + { + std::cerr << "FAIL: serializer could not deserialize data from input file: " << infile << std::endl; + return -1; + } + + // serialize using manager, so that the appropriate header information is written + void* outBuffer; + const uint64_t bytesWritten = sSer->serializeIntoBuffer(outBuffer, object, objectTypeID); + if (bytesWritten == 0) + { + std::cerr << "FAIL: could not serialize object in requested output format" << std::endl; + return -1; + } + + // release object + NVBLAST_FREE(object); + + // write file + std::ofstream outfileStream(outfile.c_str(), std::ios::binary); + if (!outfileStream.is_open()) + { + std::cerr << "FAIL: Can't open output file: " << outfile << std::endl; + return -1; + } + outfileStream.write(reinterpret_cast(outBuffer), bytesWritten); + outfileStream.close(); + + // release buffer + NVBLAST_FREE(outBuffer); + + // release framework + term_framework(); + } + catch (TCLAP::ArgException &e) // catch any exceptions + { + std::cout << "error: " << e.error() << " for arg " << e.argId() << std::endl; + } + + return 0; +} + + +int main(int argc, const char* const* argv) +{ + std::vector args; + for (int i = 0; i < argc; i++) + args.push_back(argv[i]); + return customMain(args); +} diff --git a/tools/common/BlastDataExporter.cpp b/tools/common/BlastDataExporter.cpp old mode 100644 new mode 100755 index 3ffffb1..2f88476 --- a/tools/common/BlastDataExporter.cpp +++ b/tools/common/BlastDataExporter.cpp @@ -1,141 +1,141 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2018 NVIDIA Corporation. All rights reserved. - - -#include "BlastDataExporter.h" -#include "NvBlastExtPxManager.h" -#include -#include "NvBlastExtSerialization.h" -#include "NvBlastExtLlSerialization.h" -#include "NvBlastExtTkSerialization.h" -#include "NvBlastExtPxSerialization.h" -#include -#include "PsFileBuffer.h" -#include "NvBlastExtPxAsset.h" -#include "NvBlast.h" -#include "NvBlastGlobals.h" -#include -#include -using namespace Nv::Blast; - - -BlastDataExporter::BlastDataExporter(TkFramework* framework, physx::PxPhysics* physics, physx::PxCooking* cooking) : mFramework(framework) -{ - mSerialization = NvBlastExtSerializationCreate(); - if (mSerialization != nullptr && physics != nullptr && cooking != nullptr && framework != nullptr) - { - NvBlastExtTkSerializerLoadSet(*framework, *mSerialization); - NvBlastExtPxSerializerLoadSet(*framework, *physics, *cooking, *mSerialization); - mSerialization->setSerializationEncoding(NVBLAST_FOURCC('C', 'P', 'N', 'B')); - } -} - - -BlastDataExporter::~BlastDataExporter() -{ - if (mSerialization != nullptr) - { - mSerialization->release(); - } -} - - -ExtPxAsset* BlastDataExporter::createExtBlastAsset(std::vector& bondDescs, const std::vector& chunkDescs, - std::vector& physicsChunks) -{ - ExtPxAssetDesc descriptor; - descriptor.bondCount = static_cast(bondDescs.size()); - descriptor.bondDescs = bondDescs.data(); - descriptor.chunkCount = static_cast(chunkDescs.size()); - descriptor.chunkDescs = chunkDescs.data(); - descriptor.bondFlags = nullptr; - descriptor.pxChunks = physicsChunks.data(); - ExtPxAsset* asset = ExtPxAsset::create(descriptor, *mFramework); - return asset; -} - - -NvBlastAsset* BlastDataExporter::createLlBlastAsset(std::vector& bondDescs, const std::vector& chunkDescs) -{ - NvBlastAssetDesc assetDesc; - assetDesc.bondCount = static_cast(bondDescs.size()); - assetDesc.bondDescs = bondDescs.data(); - - assetDesc.chunkCount = static_cast(chunkDescs.size()); - assetDesc.chunkDescs = chunkDescs.data(); - - std::vector scratch(static_cast(NvBlastGetRequiredScratchForCreateAsset(&assetDesc, logLL))); - void* mem = NVBLAST_ALLOC(NvBlastGetAssetMemorySize(&assetDesc, logLL)); - NvBlastAsset* asset = NvBlastCreateAsset(mem, &assetDesc, scratch.data(), logLL); - return asset; -} - - -TkAsset* BlastDataExporter::createTkBlastAsset(const std::vector& bondDescs, const std::vector& chunkDescs) -{ - TkAssetDesc desc; - desc.bondCount = static_cast(bondDescs.size()); - desc.bondDescs = bondDescs.data(); - desc.chunkCount = static_cast(chunkDescs.size()); - desc.chunkDescs = chunkDescs.data(); - desc.bondFlags = nullptr; - TkAsset* asset = mFramework->createAsset(desc); - return asset; -}; - - -bool BlastDataExporter::saveBlastObject(const std::string& outputDir, const std::string& objectName, const void* object, uint32_t objectTypeID) -{ - void* buffer; - const uint64_t bufferSize = mSerialization->serializeIntoBuffer(buffer, object, objectTypeID); - if (bufferSize == 0) - { - std::cerr << "saveBlastObject: Serialization failed.\n"; - return false; - } - - physx::PsFileBuffer fileBuf((outputDir + "/" + objectName + ".blast").c_str(), physx::PxFileBuf::OPEN_WRITE_ONLY); - bool result = fileBuf.isOpen(); - - if (!result) - { - std::cerr << "Can't open output buffer.\n"; - } - else - { - result = (bufferSize == (size_t)fileBuf.write(buffer, (uint32_t)bufferSize)); - if (!result) - { - std::cerr << "Buffer write failed.\n"; - } - fileBuf.close(); - } - - NVBLAST_FREE(buffer); - - return result; -}; +// 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) 2018 NVIDIA Corporation. All rights reserved. + + +#include "BlastDataExporter.h" +#include "NvBlastExtPxManager.h" +#include +#include "NvBlastExtSerialization.h" +#include "NvBlastExtLlSerialization.h" +#include "NvBlastExtTkSerialization.h" +#include "NvBlastExtPxSerialization.h" +#include +#include "PsFileBuffer.h" +#include "NvBlastExtPxAsset.h" +#include "NvBlast.h" +#include "NvBlastGlobals.h" +#include +#include +using namespace Nv::Blast; + + +BlastDataExporter::BlastDataExporter(TkFramework* framework, physx::PxPhysics* physics, physx::PxCooking* cooking) : mFramework(framework) +{ + mSerialization = NvBlastExtSerializationCreate(); + if (mSerialization != nullptr && physics != nullptr && cooking != nullptr && framework != nullptr) + { + NvBlastExtTkSerializerLoadSet(*framework, *mSerialization); + NvBlastExtPxSerializerLoadSet(*framework, *physics, *cooking, *mSerialization); + mSerialization->setSerializationEncoding(NVBLAST_FOURCC('C', 'P', 'N', 'B')); + } +} + + +BlastDataExporter::~BlastDataExporter() +{ + if (mSerialization != nullptr) + { + mSerialization->release(); + } +} + + +ExtPxAsset* BlastDataExporter::createExtBlastAsset(std::vector& bondDescs, const std::vector& chunkDescs, + std::vector& physicsChunks) +{ + ExtPxAssetDesc descriptor; + descriptor.bondCount = static_cast(bondDescs.size()); + descriptor.bondDescs = bondDescs.data(); + descriptor.chunkCount = static_cast(chunkDescs.size()); + descriptor.chunkDescs = chunkDescs.data(); + descriptor.bondFlags = nullptr; + descriptor.pxChunks = physicsChunks.data(); + ExtPxAsset* asset = ExtPxAsset::create(descriptor, *mFramework); + return asset; +} + + +NvBlastAsset* BlastDataExporter::createLlBlastAsset(std::vector& bondDescs, const std::vector& chunkDescs) +{ + NvBlastAssetDesc assetDesc; + assetDesc.bondCount = static_cast(bondDescs.size()); + assetDesc.bondDescs = bondDescs.data(); + + assetDesc.chunkCount = static_cast(chunkDescs.size()); + assetDesc.chunkDescs = chunkDescs.data(); + + std::vector scratch(static_cast(NvBlastGetRequiredScratchForCreateAsset(&assetDesc, logLL))); + void* mem = NVBLAST_ALLOC(NvBlastGetAssetMemorySize(&assetDesc, logLL)); + NvBlastAsset* asset = NvBlastCreateAsset(mem, &assetDesc, scratch.data(), logLL); + return asset; +} + + +TkAsset* BlastDataExporter::createTkBlastAsset(const std::vector& bondDescs, const std::vector& chunkDescs) +{ + TkAssetDesc desc; + desc.bondCount = static_cast(bondDescs.size()); + desc.bondDescs = bondDescs.data(); + desc.chunkCount = static_cast(chunkDescs.size()); + desc.chunkDescs = chunkDescs.data(); + desc.bondFlags = nullptr; + TkAsset* asset = mFramework->createAsset(desc); + return asset; +}; + + +bool BlastDataExporter::saveBlastObject(const std::string& outputDir, const std::string& objectName, const void* object, uint32_t objectTypeID) +{ + void* buffer; + const uint64_t bufferSize = mSerialization->serializeIntoBuffer(buffer, object, objectTypeID); + if (bufferSize == 0) + { + std::cerr << "saveBlastObject: Serialization failed.\n"; + return false; + } + + physx::PsFileBuffer fileBuf((outputDir + "/" + objectName + ".blast").c_str(), physx::PxFileBuf::OPEN_WRITE_ONLY); + bool result = fileBuf.isOpen(); + + if (!result) + { + std::cerr << "Can't open output buffer.\n"; + } + else + { + result = (bufferSize == (size_t)fileBuf.write(buffer, (uint32_t)bufferSize)); + if (!result) + { + std::cerr << "Buffer write failed.\n"; + } + fileBuf.close(); + } + + NVBLAST_FREE(buffer); + + return result; +}; diff --git a/tools/common/BlastDataExporter.h b/tools/common/BlastDataExporter.h old mode 100644 new mode 100755 index f3cae31..54e2bbf --- a/tools/common/BlastDataExporter.h +++ b/tools/common/BlastDataExporter.h @@ -1,100 +1,100 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2018 NVIDIA Corporation. All rights reserved. - - -#ifndef BLAST_DATA_EXPORTER -#define BLAST_DATA_EXPORTER - - -#include -#include -#include -#include -#include - -using namespace Nv::Blast; - -namespace physx -{ -class PxPhysics; -class PxCooking; -} - - -struct NvBlastBondDesc; -struct NvBlastChunkDesc; - -struct NvBlastAsset; -namespace Nv -{ -namespace Blast -{ -class TkAsset; -class ExtPxAsset; -class ExtSerialization; -} -} - - -/** - Tool for Blast asset creation and exporting -*/ -class BlastDataExporter -{ -public: - BlastDataExporter(TkFramework* framework, physx::PxPhysics* physics, physx::PxCooking* cooking); - ~BlastDataExporter(); - - /** - Creates ExtPxAsset - */ - ExtPxAsset* createExtBlastAsset(std::vector& bondDescs, const std::vector& chunkDescs, - std::vector& physicsChunks); - /** - Creates Low Level Blast asset - */ - NvBlastAsset* createLlBlastAsset(std::vector& bondDescs, const std::vector& chunkDescs); - - /** - Creates Blast Toolkit Asset asset - */ - TkAsset* createTkBlastAsset(const std::vector& bondDescs, const std::vector& chunkDescs); - - /* - Saves a Blast object to given path - */ - bool saveBlastObject(const std::string& outputDir, const std::string& objectName, const void* object, uint32_t objectTypeID); - -private: - TkFramework* mFramework; - ExtSerialization* mSerialization; -}; - - - - +// 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) 2018 NVIDIA Corporation. All rights reserved. + + +#ifndef BLAST_DATA_EXPORTER +#define BLAST_DATA_EXPORTER + + +#include +#include +#include +#include +#include + +using namespace Nv::Blast; + +namespace physx +{ +class PxPhysics; +class PxCooking; +} + + +struct NvBlastBondDesc; +struct NvBlastChunkDesc; + +struct NvBlastAsset; +namespace Nv +{ +namespace Blast +{ +class TkAsset; +class ExtPxAsset; +class ExtSerialization; +} +} + + +/** + Tool for Blast asset creation and exporting +*/ +class BlastDataExporter +{ +public: + BlastDataExporter(TkFramework* framework, physx::PxPhysics* physics, physx::PxCooking* cooking); + ~BlastDataExporter(); + + /** + Creates ExtPxAsset + */ + ExtPxAsset* createExtBlastAsset(std::vector& bondDescs, const std::vector& chunkDescs, + std::vector& physicsChunks); + /** + Creates Low Level Blast asset + */ + NvBlastAsset* createLlBlastAsset(std::vector& bondDescs, const std::vector& chunkDescs); + + /** + Creates Blast Toolkit Asset asset + */ + TkAsset* createTkBlastAsset(const std::vector& bondDescs, const std::vector& chunkDescs); + + /* + Saves a Blast object to given path + */ + bool saveBlastObject(const std::string& outputDir, const std::string& objectName, const void* object, uint32_t objectTypeID); + +private: + TkFramework* mFramework; + ExtSerialization* mSerialization; +}; + + + + #endif \ No newline at end of file diff --git a/tools/common/Log.cpp b/tools/common/Log.cpp old mode 100644 new mode 100755 index 0d4c8f7..57a25b4 --- a/tools/common/Log.cpp +++ b/tools/common/Log.cpp @@ -1,87 +1,87 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2016-2018 NVIDIA Corporation. All rights reserved. - - -#include "Log.h" - -#include "PsString.h" - -#include -#include -#include - -/////////////////////////////////////////////////////////////////////////// - -namespace Nv -{ -namespace Blast -{ - -void fLogf(const char* format, ...) -{ - char buf[4096], *p = buf; - va_list args; - int n; - - va_start(args, format); - //n = _vsnprintf(p, sizeof buf - 3, format, args); - n = vsprintf_s(p, sizeof(buf)-3, format, args); - va_end(args); - - p += (n < 0) ? sizeof buf - 3 : n; - - while (p > buf && isspace((unsigned char)p[-1])) - { - *--p = '\0'; - } - - *p++ = '\r'; - *p++ = '\n'; - *p = '\0'; - - fLog(buf, Log::TYPE_INFO); -} - - -////////////////////////////////////////////////////////////////////////////// - -void Log::flushDeferredMessages() -{ - if (mDeferredMessages.size() == 0) return; - - std::cout << std::endl; - for (std::vector::iterator it = mDeferredMessages.begin(); it != mDeferredMessages.end(); ++it) - { - log(*it, mMinVerbosity); - } - mDeferredMessages.clear(); -} - - - -} // namespace Blast -} // namespace Nv +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2018 NVIDIA Corporation. All rights reserved. + + +#include "Log.h" + +#include "PsString.h" + +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + +namespace Nv +{ +namespace Blast +{ + +void fLogf(const char* format, ...) +{ + char buf[4096], *p = buf; + va_list args; + int n; + + va_start(args, format); + //n = _vsnprintf(p, sizeof buf - 3, format, args); + n = vsprintf_s(p, sizeof(buf)-3, format, args); + va_end(args); + + p += (n < 0) ? sizeof buf - 3 : n; + + while (p > buf && isspace((unsigned char)p[-1])) + { + *--p = '\0'; + } + + *p++ = '\r'; + *p++ = '\n'; + *p = '\0'; + + fLog(buf, Log::TYPE_INFO); +} + + +////////////////////////////////////////////////////////////////////////////// + +void Log::flushDeferredMessages() +{ + if (mDeferredMessages.size() == 0) return; + + std::cout << std::endl; + for (std::vector::iterator it = mDeferredMessages.begin(); it != mDeferredMessages.end(); ++it) + { + log(*it, mMinVerbosity); + } + mDeferredMessages.clear(); +} + + + +} // namespace Blast +} // namespace Nv diff --git a/tools/common/Log.h b/tools/common/Log.h old mode 100644 new mode 100755 index 8df9660..588c32b --- a/tools/common/Log.h +++ b/tools/common/Log.h @@ -1,150 +1,150 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2016-2018 NVIDIA Corporation. All rights reserved. - - -#ifndef LOG_H -#define LOG_H - -#include "Utils.h" -#include "PxVec3.h" - -#include - -namespace Nv -{ -namespace Blast -{ - - -////////////////////////////////////////////////////////////////////////////// - -void fLogf(const char* format, ...); - -class Log : public Singleton -{ - friend class Singleton; - -public: - - enum MessageType { - TYPE_INFO = 0, - TYPE_WARNING, - TYPE_ERROR, - TYPE_DEFERRED, - - NUM_TYPES, - MOST_VERBOSE = TYPE_INFO, - LEAST_VERBOSE = TYPE_ERROR -#if defined(_DEBUG) - , DEFAULT_VERBOSITY = MOST_VERBOSE -#else - , DEFAULT_VERBOSITY = LEAST_VERBOSE -#endif - }; - typedef MessageType Verbosity; - - /////////////////////////////////////////////////////////////////////////// - - template - Log& log(const T& value, MessageType messageType); - - void flushDeferredMessages(); - - /////////////////////////////////////////////////////////////////////////// - - void setCurrentVerbosity(Verbosity verbosity) { mCurrentVerbosity = verbosity; } - Verbosity getCurrentVerbosity() const { return mCurrentVerbosity; } - - // Messages types below this level will be ignored - void setMinVerbosity(Verbosity verbosity) { mMinVerbosity = verbosity; } - Verbosity getMinVerbosity() const { return mMinVerbosity; } - - /////////////////////////////////////////////////////////////////////////// - -protected: - Log(MessageType verbosity = DEFAULT_VERBOSITY) - : mCurrentVerbosity(LEAST_VERBOSE), - mMinVerbosity(verbosity) { } - -private: - Verbosity mCurrentVerbosity; - Verbosity mMinVerbosity; - std::vector mDeferredMessages; -}; - -/////////////////////////////////////////////////////////////////////////// - -PX_INLINE std::ostream& operator<< (std::ostream& stream, const physx::PxVec3& vec) -{ - return stream << "(" << vec.x << ", " << vec.y << ", " << vec.z << ")"; -} - -template -Log& Log::log(const T& value, Log::MessageType messageType) -{ - if (TYPE_DEFERRED == messageType) - { - std::stringstream ss; - ss << value; - mDeferredMessages.push_back(ss.str()); - } - else if(mMinVerbosity <= messageType) - { - std::cout << value; - } - return *this; -} - -PX_INLINE Log& lout() { return Log::instance(); } - -template -PX_INLINE void fLog(const T& value, Log::MessageType messageType = Log::TYPE_INFO) -{ - lout().log(value, messageType); -} -template -PX_INLINE Log& operator<<(Log& logger, const T& value) -{ - return logger.log(value, logger.getCurrentVerbosity()); -} -PX_INLINE Log& operator<<(Log& logger, Log::MessageType verbosity) -{ - logger.setCurrentVerbosity(verbosity); - return logger; -} -typedef std::ostream& (*ostream_manipulator)(std::ostream&); -PX_INLINE Log& operator<<(Log& logger, ostream_manipulator pf) -{ - return operator<< (logger, pf); -} - - -} // namespace Blast -} // namespace Nv - - -#endif +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2018 NVIDIA Corporation. All rights reserved. + + +#ifndef LOG_H +#define LOG_H + +#include "Utils.h" +#include "PxVec3.h" + +#include + +namespace Nv +{ +namespace Blast +{ + + +////////////////////////////////////////////////////////////////////////////// + +void fLogf(const char* format, ...); + +class Log : public Singleton +{ + friend class Singleton; + +public: + + enum MessageType { + TYPE_INFO = 0, + TYPE_WARNING, + TYPE_ERROR, + TYPE_DEFERRED, + + NUM_TYPES, + MOST_VERBOSE = TYPE_INFO, + LEAST_VERBOSE = TYPE_ERROR +#if defined(_DEBUG) + , DEFAULT_VERBOSITY = MOST_VERBOSE +#else + , DEFAULT_VERBOSITY = LEAST_VERBOSE +#endif + }; + typedef MessageType Verbosity; + + /////////////////////////////////////////////////////////////////////////// + + template + Log& log(const T& value, MessageType messageType); + + void flushDeferredMessages(); + + /////////////////////////////////////////////////////////////////////////// + + void setCurrentVerbosity(Verbosity verbosity) { mCurrentVerbosity = verbosity; } + Verbosity getCurrentVerbosity() const { return mCurrentVerbosity; } + + // Messages types below this level will be ignored + void setMinVerbosity(Verbosity verbosity) { mMinVerbosity = verbosity; } + Verbosity getMinVerbosity() const { return mMinVerbosity; } + + /////////////////////////////////////////////////////////////////////////// + +protected: + Log(MessageType verbosity = DEFAULT_VERBOSITY) + : mCurrentVerbosity(LEAST_VERBOSE), + mMinVerbosity(verbosity) { } + +private: + Verbosity mCurrentVerbosity; + Verbosity mMinVerbosity; + std::vector mDeferredMessages; +}; + +/////////////////////////////////////////////////////////////////////////// + +PX_INLINE std::ostream& operator<< (std::ostream& stream, const physx::PxVec3& vec) +{ + return stream << "(" << vec.x << ", " << vec.y << ", " << vec.z << ")"; +} + +template +Log& Log::log(const T& value, Log::MessageType messageType) +{ + if (TYPE_DEFERRED == messageType) + { + std::stringstream ss; + ss << value; + mDeferredMessages.push_back(ss.str()); + } + else if(mMinVerbosity <= messageType) + { + std::cout << value; + } + return *this; +} + +PX_INLINE Log& lout() { return Log::instance(); } + +template +PX_INLINE void fLog(const T& value, Log::MessageType messageType = Log::TYPE_INFO) +{ + lout().log(value, messageType); +} +template +PX_INLINE Log& operator<<(Log& logger, const T& value) +{ + return logger.log(value, logger.getCurrentVerbosity()); +} +PX_INLINE Log& operator<<(Log& logger, Log::MessageType verbosity) +{ + logger.setCurrentVerbosity(verbosity); + return logger; +} +typedef std::ostream& (*ostream_manipulator)(std::ostream&); +PX_INLINE Log& operator<<(Log& logger, ostream_manipulator pf) +{ + return operator<< (logger, pf); +} + + +} // namespace Blast +} // namespace Nv + + +#endif diff --git a/tools/common/Utils.cpp b/tools/common/Utils.cpp old mode 100644 new mode 100755 index d42ed81..8355f48 --- a/tools/common/Utils.cpp +++ b/tools/common/Utils.cpp @@ -1,194 +1,194 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2016-2018 NVIDIA Corporation. All rights reserved. - - -#include "Utils.h" - -#include "Log.h" - -#include - -#if PX_WINDOWS_FAMILY -#include -#define getCwd _getcwd -#else -#include -#define getCwd getcwd -#endif - -/////////////////////////////////////////////////////////////////////////// - -namespace Nv -{ -namespace Blast -{ - -////////////////////////////////////////////////////////////////////////////// - -static void addSlashToPath(std::string& path) -{ - if (path[path.length() - 1] != '/' && path[path.length() - 1] != '\\') - { - path.append("/"); - } -} - -FileUtils::FileUtils() -{ - mSearchPaths.push_back(""); - char currentPathTemp[FILENAME_MAX]; - if (getCwd(currentPathTemp, sizeof(currentPathTemp))) - { - std::string currentPath(currentPathTemp); - addSlashToPath(currentPath); - addAbsolutePath(currentPath); - mCurrentPath = currentPath; - } -} - -std::string FileUtils::getDirectory(const std::string& filePath) -{ - return filePath.substr(0, filePath.find_last_of("/\\") + 1); -} - -std::string FileUtils::getFilename(const std::string& filePath, bool bWithExtension) -{ - size_t p0 = filePath.find_last_of("/\\") + 1; - if (bWithExtension) - { - return filePath.substr(p0); - } - else - { - return filePath.substr(p0, filePath.find_last_of(".") - p0); - } -} - -std::string FileUtils::getFileExtension(const std::string& filePath) -{ - std::string filename = getFilename(filePath); - size_t p0 = filename.find_last_of("."); - if (p0 != std::string::npos) - return filePath.substr(p0);// + 1); - return ""; -} - -void FileUtils::addAbsolutePath(const std::string& path) -{ - if (path.empty()) - { - return; - } - - std::string newPath = path; - addSlashToPath(newPath); - - mSearchPaths.push_back(newPath); -} - -void FileUtils::addRelativePath(const std::string& relPath) -{ - addAbsolutePath(mCurrentPath + relPath); -} - -void FileUtils::clearPaths() -{ - mSearchPaths.clear(); -} - -FILE* FileUtils::findFile(const std::string& path, bool bVerbose) -{ - FILE* file; - if (find(path, &file, NULL, bVerbose)) - { - return file; - } - else - { - return NULL; - } -} - -std::string FileUtils::findPath(const std::string& path, bool bVerbose) -{ - std::string fullPath; - if (find(path, NULL, &fullPath, bVerbose)) - { - return fullPath; - } - else - { - return path; - } -} - -bool FileUtils::find(const std::string& path, FILE** ppFile, std::string* pFullPath, bool bVerbose) -{ - if (mSearchPaths.empty() || path.empty()) - { - if (bVerbose) - { - lout() << Log::TYPE_ERROR << "Error: Invalid search path configuration."; - } - return false; - } - - std::string fullPath; - - FILE* file = NULL; - const uint32_t numSearchPaths = (uint32_t)mSearchPaths.size(); - for (uint32_t i = 0; i < numSearchPaths; ++i) - { - fullPath = mSearchPaths[i] + path; - fopen_s(&file, fullPath.c_str(), "rb"); - if (file) - { - break; - } - } - - if (!file) - { - if (bVerbose) - lout() << Log::TYPE_ERROR << std::endl << "Error: Unable to find file " << path << std::endl; - return false; - } - - if (ppFile) - *ppFile = file; - else - fclose(file); - - if (pFullPath) - *pFullPath = fullPath; - - return true; -} - - -} // namespace Blast -} // namespace Nv +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2018 NVIDIA Corporation. All rights reserved. + + +#include "Utils.h" + +#include "Log.h" + +#include + +#if PX_WINDOWS_FAMILY +#include +#define getCwd _getcwd +#else +#include +#define getCwd getcwd +#endif + +/////////////////////////////////////////////////////////////////////////// + +namespace Nv +{ +namespace Blast +{ + +////////////////////////////////////////////////////////////////////////////// + +static void addSlashToPath(std::string& path) +{ + if (path[path.length() - 1] != '/' && path[path.length() - 1] != '\\') + { + path.append("/"); + } +} + +FileUtils::FileUtils() +{ + mSearchPaths.push_back(""); + char currentPathTemp[FILENAME_MAX]; + if (getCwd(currentPathTemp, sizeof(currentPathTemp))) + { + std::string currentPath(currentPathTemp); + addSlashToPath(currentPath); + addAbsolutePath(currentPath); + mCurrentPath = currentPath; + } +} + +std::string FileUtils::getDirectory(const std::string& filePath) +{ + return filePath.substr(0, filePath.find_last_of("/\\") + 1); +} + +std::string FileUtils::getFilename(const std::string& filePath, bool bWithExtension) +{ + size_t p0 = filePath.find_last_of("/\\") + 1; + if (bWithExtension) + { + return filePath.substr(p0); + } + else + { + return filePath.substr(p0, filePath.find_last_of(".") - p0); + } +} + +std::string FileUtils::getFileExtension(const std::string& filePath) +{ + std::string filename = getFilename(filePath); + size_t p0 = filename.find_last_of("."); + if (p0 != std::string::npos) + return filePath.substr(p0);// + 1); + return ""; +} + +void FileUtils::addAbsolutePath(const std::string& path) +{ + if (path.empty()) + { + return; + } + + std::string newPath = path; + addSlashToPath(newPath); + + mSearchPaths.push_back(newPath); +} + +void FileUtils::addRelativePath(const std::string& relPath) +{ + addAbsolutePath(mCurrentPath + relPath); +} + +void FileUtils::clearPaths() +{ + mSearchPaths.clear(); +} + +FILE* FileUtils::findFile(const std::string& path, bool bVerbose) +{ + FILE* file; + if (find(path, &file, NULL, bVerbose)) + { + return file; + } + else + { + return NULL; + } +} + +std::string FileUtils::findPath(const std::string& path, bool bVerbose) +{ + std::string fullPath; + if (find(path, NULL, &fullPath, bVerbose)) + { + return fullPath; + } + else + { + return path; + } +} + +bool FileUtils::find(const std::string& path, FILE** ppFile, std::string* pFullPath, bool bVerbose) +{ + if (mSearchPaths.empty() || path.empty()) + { + if (bVerbose) + { + lout() << Log::TYPE_ERROR << "Error: Invalid search path configuration."; + } + return false; + } + + std::string fullPath; + + FILE* file = NULL; + const uint32_t numSearchPaths = (uint32_t)mSearchPaths.size(); + for (uint32_t i = 0; i < numSearchPaths; ++i) + { + fullPath = mSearchPaths[i] + path; + fopen_s(&file, fullPath.c_str(), "rb"); + if (file) + { + break; + } + } + + if (!file) + { + if (bVerbose) + lout() << Log::TYPE_ERROR << std::endl << "Error: Unable to find file " << path << std::endl; + return false; + } + + if (ppFile) + *ppFile = file; + else + fclose(file); + + if (pFullPath) + *pFullPath = fullPath; + + return true; +} + + +} // namespace Blast +} // namespace Nv diff --git a/tools/common/Utils.h b/tools/common/Utils.h old mode 100644 new mode 100755 index 5d01480..8eb3530 --- a/tools/common/Utils.h +++ b/tools/common/Utils.h @@ -1,141 +1,141 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2016-2018 NVIDIA Corporation. All rights reserved. - - -#ifndef UTILS_H -#define UTILS_H - -#include "PsString.h" - -#include -#include -#include -#include - -////////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////////// - -namespace Nv -{ -namespace Blast -{ - -/////////////////////////////////////////////////////////////////////////// - -template -PX_INLINE bool isNull(const T* p) { return nullptr == p; } - -template class ScopedResource; -template -PX_INLINE bool isNull(const ScopedResource& p) { return !p; } - -PX_INLINE bool isNullString(const char* pString) -{ - return (nullptr == pString || pString[0] == '\0' || physx::shdfnd::strcmp(pString, "null") == 0); -} - -template -PX_INLINE bool isValid(const T& p) { return !isNull(p.get()); } - -PX_INLINE bool isValidString(const char* pString) { return !isNullString(pString); } - -/////////////////////////////////////////////////////////////////////////// - -// Note: This is not a thread safe singleton class -template -class Singleton -{ - // The fact that I cannot declare T a friend directly is rather absurd... - typedef T Type; - friend typename Singleton::Type; - - ////////////////////////////////////////////////////////////////////////////// - -public: - static T& instance() - { - static T _instance; - return _instance; - } - - ////////////////////////////////////////////////////////////////////////////// - -private: - Singleton() { } - ~Singleton() { }; - Singleton(const Singleton&); - Singleton& operator=(const Singleton&); -}; - -////////////////////////////////////////////////////////////////////////////// - -class FileUtils : public Singleton -{ - friend class Singleton; - -public: - void addAbsolutePath(const std::string&); - void addRelativePath(const std::string&); - void clearPaths(); - - ////////////////////////////////////////////////////////////////////////////// - - FILE* findFile(const std::string&, bool bVerbose = true); - std::string findPath(const std::string&, bool bVerbose = true); - bool find(const std::string&, FILE**, std::string*, bool bVerbose = true); - - ////////////////////////////////////////////////////////////////////////////// - - const std::string& getCurrentPath() const - { - return mCurrentPath; - } - - ////////////////////////////////////////////////////////////////////////////// - - static std::string getDirectory(const std::string&); - static std::string getFilename(const std::string&, bool bWithExtension = true); - static std::string getFileExtension(const std::string&); - - ////////////////////////////////////////////////////////////////////////////// - -protected: - FileUtils(); - - ////////////////////////////////////////////////////////////////////////////// - - std::string mCurrentPath; - std::vector mSearchPaths; -}; - - -} // namespace Blast -} // namespace Nv - - -#endif +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2018 NVIDIA Corporation. All rights reserved. + + +#ifndef UTILS_H +#define UTILS_H + +#include "PsString.h" + +#include +#include +#include +#include + +////////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////////// + +namespace Nv +{ +namespace Blast +{ + +/////////////////////////////////////////////////////////////////////////// + +template +PX_INLINE bool isNull(const T* p) { return nullptr == p; } + +template class ScopedResource; +template +PX_INLINE bool isNull(const ScopedResource& p) { return !p; } + +PX_INLINE bool isNullString(const char* pString) +{ + return (nullptr == pString || pString[0] == '\0' || physx::shdfnd::strcmp(pString, "null") == 0); +} + +template +PX_INLINE bool isValid(const T& p) { return !isNull(p.get()); } + +PX_INLINE bool isValidString(const char* pString) { return !isNullString(pString); } + +/////////////////////////////////////////////////////////////////////////// + +// Note: This is not a thread safe singleton class +template +class Singleton +{ + // The fact that I cannot declare T a friend directly is rather absurd... + typedef T Type; + friend typename Singleton::Type; + + ////////////////////////////////////////////////////////////////////////////// + +public: + static T& instance() + { + static T _instance; + return _instance; + } + + ////////////////////////////////////////////////////////////////////////////// + +private: + Singleton() { } + ~Singleton() { }; + Singleton(const Singleton&); + Singleton& operator=(const Singleton&); +}; + +////////////////////////////////////////////////////////////////////////////// + +class FileUtils : public Singleton +{ + friend class Singleton; + +public: + void addAbsolutePath(const std::string&); + void addRelativePath(const std::string&); + void clearPaths(); + + ////////////////////////////////////////////////////////////////////////////// + + FILE* findFile(const std::string&, bool bVerbose = true); + std::string findPath(const std::string&, bool bVerbose = true); + bool find(const std::string&, FILE**, std::string*, bool bVerbose = true); + + ////////////////////////////////////////////////////////////////////////////// + + const std::string& getCurrentPath() const + { + return mCurrentPath; + } + + ////////////////////////////////////////////////////////////////////////////// + + static std::string getDirectory(const std::string&); + static std::string getFilename(const std::string&, bool bWithExtension = true); + static std::string getFileExtension(const std::string&); + + ////////////////////////////////////////////////////////////////////////////// + +protected: + FileUtils(); + + ////////////////////////////////////////////////////////////////////////////// + + std::string mCurrentPath; + std::vector mSearchPaths; +}; + + +} // namespace Blast +} // namespace Nv + + +#endif diff --git a/tools/compiler/cmake/ApexImporter.cmake b/tools/compiler/cmake/ApexImporter.cmake old mode 100644 new mode 100755 index f8e4a45..7ab0907 --- a/tools/compiler/cmake/ApexImporter.cmake +++ b/tools/compiler/cmake/ApexImporter.cmake @@ -1,81 +1,81 @@ -# -# Build ApexImporter common -# - -SET(APEXIMPORTER_SOURCE_DIR ${PROJECT_SOURCE_DIR}/ApexImporter/src) -SET(TOOLS_COMMON_DIR ${BLAST_ROOT_DIR}/tools/common) -SET(TOOLS_COMMON_DIR ${BLAST_ROOT_DIR}/tools/common) -SET(APEX_MODULES_DIR ${BLAST_ROOT_DIR}/sdk/extensions/import/apexmodules) - -FIND_PACKAGE(PhysXSDK $ENV{PM_PhysX_VERSION} REQUIRED) -FIND_PACKAGE(PxSharedSDK $ENV{PM_PxShared_VERSION} REQUIRED) -FIND_PACKAGE(tclap $ENV{PM_tclap_VERSION} REQUIRED) -FIND_PACKAGE(FBXSDK $ENV{PM_FBXSDK_VERSION} REQUIRED) - - -# Include here after the directories are defined so that the platform specific file can use the variables. -include(${PROJECT_CMAKE_FILES_DIR}/${TARGET_BUILD_PLATFORM}/ApexImporter.cmake) - -SET(COMMON_FILES - ${APEXIMPORTER_PLATFORM_COMMON_FILES} - - ${APEXIMPORTER_SOURCE_DIR}/Main.cpp - ${APEXIMPORTER_SOURCE_DIR}/ApexDestructibleObjExporter.cpp - ${APEXIMPORTER_SOURCE_DIR}/ApexDestructibleObjExporter.h - ${BLAST_ROOT_DIR}/tools/common/BlastDataExporter.cpp - ${BLAST_ROOT_DIR}/tools/common/BlastDataExporter.h -) - -ADD_EXECUTABLE(ApexImporter - ${COMMON_FILES} -) - -set_target_properties(ApexImporter - PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX} - CHECKED_POSTFIX ${CMAKE_CHECKED_POSTFIX} - RELEASE_POSTFIX ${CMAKE_RELEASE_POSTFIX} - PROFILE_POSTFIX ${CMAKE_PROFILE_POSTFIX} -) - -SOURCE_GROUP("src" FILES ${COMMON_FILES}) - -# Target specific compile options - -TARGET_INCLUDE_DIRECTORIES(ApexImporter - PRIVATE ${APEXIMPORTER_PLATFORM_INCLUDES} - - PRIVATE ${BLAST_ROOT_DIR}/sdk/common - PRIVATE ${TOOLS_COMMON_DIR} - - PRIVATE ${PHYSXSDK_INCLUDE_DIRS} - PRIVATE ${PXSHAREDSDK_INCLUDE_DIRS} - PRIVATE ${TCLAP_INCLUDE_DIRS} - PRIVATE ${FBXSDK_INCLUDE_DIRS} - - PRIVATE ${APEX_MODULES_DIR}/nvparutils - - PRIVATE ${APEX_MODULES_DIR}/NvParameterized/include -) - -TARGET_COMPILE_DEFINITIONS(ApexImporter - PRIVATE ${APEXIMPORTER_COMPILE_DEFS} -) - -SET_TARGET_PROPERTIES(ApexImporter PROPERTIES - COMPILE_PDB_NAME_DEBUG "ApexImporter${CMAKE_DEBUG_POSTFIX}" - COMPILE_PDB_NAME_CHECKED "ApexImporter${CMAKE_CHECKED_POSTFIX}" - COMPILE_PDB_NAME_PROFILE "ApexImporter${CMAKE_PROFILE_POSTFIX}" - COMPILE_PDB_NAME_RELEASE "ApexImporter${CMAKE_RELEASE_POSTFIX}" -) - -# Do final direct sets after the target has been defined -TARGET_LINK_LIBRARIES(ApexImporter - PRIVATE NvBlast NvBlastExtPhysX NvBlastExtAuthoring NvBlastExtImport NvBlastExtExporter NvBlastExtSerialization NvBlastExtTkSerialization NvBlastExtPxSerialization Rpcrt4 - PRIVATE ${FBXSDK_LIBRARIES} -) - -ADD_CUSTOM_COMMAND(TARGET ApexImporter POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${PHYSXSDK_DLLS} ${PXSHAREDSDK_DLLS} - ${BL_EXE_OUTPUT_DIR} -) +# +# Build ApexImporter common +# + +SET(APEXIMPORTER_SOURCE_DIR ${PROJECT_SOURCE_DIR}/ApexImporter/src) +SET(TOOLS_COMMON_DIR ${BLAST_ROOT_DIR}/tools/common) +SET(TOOLS_COMMON_DIR ${BLAST_ROOT_DIR}/tools/common) +SET(APEX_MODULES_DIR ${BLAST_ROOT_DIR}/sdk/extensions/import/apexmodules) + +FIND_PACKAGE(PhysXSDK $ENV{PM_PhysX_VERSION} REQUIRED) +FIND_PACKAGE(PxSharedSDK $ENV{PM_PxShared_VERSION} REQUIRED) +FIND_PACKAGE(tclap $ENV{PM_tclap_VERSION} REQUIRED) +FIND_PACKAGE(FBXSDK $ENV{PM_FBXSDK_VERSION} REQUIRED) + + +# Include here after the directories are defined so that the platform specific file can use the variables. +include(${PROJECT_CMAKE_FILES_DIR}/${TARGET_BUILD_PLATFORM}/ApexImporter.cmake) + +SET(COMMON_FILES + ${APEXIMPORTER_PLATFORM_COMMON_FILES} + + ${APEXIMPORTER_SOURCE_DIR}/Main.cpp + ${APEXIMPORTER_SOURCE_DIR}/ApexDestructibleObjExporter.cpp + ${APEXIMPORTER_SOURCE_DIR}/ApexDestructibleObjExporter.h + ${BLAST_ROOT_DIR}/tools/common/BlastDataExporter.cpp + ${BLAST_ROOT_DIR}/tools/common/BlastDataExporter.h +) + +ADD_EXECUTABLE(ApexImporter + ${COMMON_FILES} +) + +set_target_properties(ApexImporter + PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX} + CHECKED_POSTFIX ${CMAKE_CHECKED_POSTFIX} + RELEASE_POSTFIX ${CMAKE_RELEASE_POSTFIX} + PROFILE_POSTFIX ${CMAKE_PROFILE_POSTFIX} +) + +SOURCE_GROUP("src" FILES ${COMMON_FILES}) + +# Target specific compile options + +TARGET_INCLUDE_DIRECTORIES(ApexImporter + PRIVATE ${APEXIMPORTER_PLATFORM_INCLUDES} + + PRIVATE ${BLAST_ROOT_DIR}/sdk/common + PRIVATE ${TOOLS_COMMON_DIR} + + PRIVATE ${PHYSXSDK_INCLUDE_DIRS} + PRIVATE ${PXSHAREDSDK_INCLUDE_DIRS} + PRIVATE ${TCLAP_INCLUDE_DIRS} + PRIVATE ${FBXSDK_INCLUDE_DIRS} + + PRIVATE ${APEX_MODULES_DIR}/nvparutils + + PRIVATE ${APEX_MODULES_DIR}/NvParameterized/include +) + +TARGET_COMPILE_DEFINITIONS(ApexImporter + PRIVATE ${APEXIMPORTER_COMPILE_DEFS} +) + +SET_TARGET_PROPERTIES(ApexImporter PROPERTIES + COMPILE_PDB_NAME_DEBUG "ApexImporter${CMAKE_DEBUG_POSTFIX}" + COMPILE_PDB_NAME_CHECKED "ApexImporter${CMAKE_CHECKED_POSTFIX}" + COMPILE_PDB_NAME_PROFILE "ApexImporter${CMAKE_PROFILE_POSTFIX}" + COMPILE_PDB_NAME_RELEASE "ApexImporter${CMAKE_RELEASE_POSTFIX}" +) + +# Do final direct sets after the target has been defined +TARGET_LINK_LIBRARIES(ApexImporter + PRIVATE NvBlast NvBlastExtPhysX NvBlastExtAuthoring NvBlastExtImport NvBlastExtExporter NvBlastExtSerialization NvBlastExtTkSerialization NvBlastExtPxSerialization Rpcrt4 + PRIVATE ${FBXSDK_LIBRARIES} +) + +ADD_CUSTOM_COMMAND(TARGET ApexImporter POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${PHYSXSDK_DLLS} ${PXSHAREDSDK_DLLS} + ${BL_EXE_OUTPUT_DIR} +) diff --git a/tools/compiler/cmake/AuthoringTool.cmake b/tools/compiler/cmake/AuthoringTool.cmake old mode 100644 new mode 100755 index 82132b9..3b16da0 --- a/tools/compiler/cmake/AuthoringTool.cmake +++ b/tools/compiler/cmake/AuthoringTool.cmake @@ -1,85 +1,85 @@ -# -# Build AuthoringTool common -# - -SET(AUTHORTINGTOOL_SOURCE_DIR ${PROJECT_SOURCE_DIR}/AuthoringTool/src) -SET(TOOLS_COMMON_SOURCE_DIR ${PROJECT_SOURCE_DIR}/common) - -SET(EXT_AUTHORING_INCLUDE_DIR ${BLAST_ROOT_DIR}/sdk/extensions/authoring/include) -SET(TK_INCLUDE_DIR ${BLAST_ROOT_DIR}/sdk/toolkit/include) - -FIND_PACKAGE(PhysXSDK $ENV{PM_PhysXSDK_VERSION} REQUIRED) -FIND_PACKAGE(PxSharedSDK $ENV{PM_PxSharedSDK_VERSION} REQUIRED) -FIND_PACKAGE(tclap $ENV{PM_tclap_VERSION} REQUIRED) -FIND_PACKAGE(tinyObjLoader $ENV{PM_tinyObjLoader_VERSION} REQUIRED) -FIND_PACKAGE(FBXSDK $ENV{PM_FBXSDK_VERSION} REQUIRED) - - -# Include here after the directories are defined so that the platform specific file can use the variables. -include(${PROJECT_CMAKE_FILES_DIR}/${TARGET_BUILD_PLATFORM}/AuthoringTool.cmake) - -SET(COMMON_FILES - ${AUTHORTINGTOOL_PLATFORM_COMMON_FILES} - - ${AUTHORTINGTOOL_SOURCE_DIR}/AuthoringTool.cpp - ${AUTHORTINGTOOL_SOURCE_DIR}/SimpleRandomGenerator.h - ${TOOLS_COMMON_SOURCE_DIR}/BlastDataExporter.h - ${TOOLS_COMMON_SOURCE_DIR}/BlastDataExporter.cpp -) - -ADD_EXECUTABLE(AuthoringTool - ${COMMON_FILES} -) - -set_target_properties(AuthoringTool - PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX} - CHECKED_POSTFIX ${CMAKE_CHECKED_POSTFIX} - RELEASE_POSTFIX ${CMAKE_RELEASE_POSTFIX} - PROFILE_POSTFIX ${CMAKE_PROFILE_POSTFIX} -) - -SOURCE_GROUP("src" FILES ${COMMON_FILES}) - -# Target specific compile options - -TARGET_INCLUDE_DIRECTORIES(AuthoringTool - PRIVATE ${AUTHORTINGTOOL_PLATFORM_INCLUDES} - - PRIVATE ${TOOLS_COMMON_SOURCE_DIR} - PRIVATE ${EXT_AUTHORING_INCLUDE_DIR} - PRIVATE ${TK_INCLUDE_DIR} - PRIVATE ${BLAST_ROOT_DIR}/sdk/common - PRIVATE ${BLAST_ROOT_DIR}/sdk/extensions/common/include - - PRIVATE ${PHYSXSDK_INCLUDE_DIRS} - PRIVATE ${PXSHAREDSDK_INCLUDE_DIRS} - PRIVATE ${TCLAP_INCLUDE_DIRS} - PRIVATE ${TINYOBJLOADER_INCLUDE_DIRS} - PRIVATE ${FBXSDK_INCLUDE_DIRS} -) - -TARGET_COMPILE_DEFINITIONS(AuthoringTool - PRIVATE ${AUTHORTINGTOOL_COMPILE_DEFS} -) - -SET_TARGET_PROPERTIES(AuthoringTool PROPERTIES - PDB_NAME_DEBUG "AuthoringTool${CMAKE_DEBUG_POSTFIX}" - PDB_NAME_CHECKED "AuthoringTool${CMAKE_CHECKED_POSTFIX}" - PDB_NAME_PROFILE "AuthoringTool${CMAKE_PROFILE_POSTFIX}" - PDB_NAME_RELEASE "AuthoringTool${CMAKE_RELEASE_POSTFIX}" -) - -# Do final direct sets after the target has been defined -TARGET_LINK_LIBRARIES(AuthoringTool - PRIVATE NvBlast NvBlastTk NvBlastExtSerialization NvBlastExtTkSerialization NvBlastExtPxSerialization NvBlastExtPhysX NvBlastExtExporter NvBlastExtAuthoring - PRIVATE ${FBXSDK_LIBRARIES} -) - -# Copy the dlls from the deps - -ADD_CUSTOM_COMMAND(TARGET AuthoringTool POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${APEXSDK_DLLS} ${PHYSXSDK_DLLS} ${PXSHAREDSDK_DLLS} - ${BL_EXE_OUTPUT_DIR} -) - +# +# Build AuthoringTool common +# + +SET(AUTHORTINGTOOL_SOURCE_DIR ${PROJECT_SOURCE_DIR}/AuthoringTool/src) +SET(TOOLS_COMMON_SOURCE_DIR ${PROJECT_SOURCE_DIR}/common) + +SET(EXT_AUTHORING_INCLUDE_DIR ${BLAST_ROOT_DIR}/sdk/extensions/authoring/include) +SET(TK_INCLUDE_DIR ${BLAST_ROOT_DIR}/sdk/toolkit/include) + +FIND_PACKAGE(PhysXSDK $ENV{PM_PhysXSDK_VERSION} REQUIRED) +FIND_PACKAGE(PxSharedSDK $ENV{PM_PxSharedSDK_VERSION} REQUIRED) +FIND_PACKAGE(tclap $ENV{PM_tclap_VERSION} REQUIRED) +FIND_PACKAGE(tinyObjLoader $ENV{PM_tinyObjLoader_VERSION} REQUIRED) +FIND_PACKAGE(FBXSDK $ENV{PM_FBXSDK_VERSION} REQUIRED) + + +# Include here after the directories are defined so that the platform specific file can use the variables. +include(${PROJECT_CMAKE_FILES_DIR}/${TARGET_BUILD_PLATFORM}/AuthoringTool.cmake) + +SET(COMMON_FILES + ${AUTHORTINGTOOL_PLATFORM_COMMON_FILES} + + ${AUTHORTINGTOOL_SOURCE_DIR}/AuthoringTool.cpp + ${AUTHORTINGTOOL_SOURCE_DIR}/SimpleRandomGenerator.h + ${TOOLS_COMMON_SOURCE_DIR}/BlastDataExporter.h + ${TOOLS_COMMON_SOURCE_DIR}/BlastDataExporter.cpp +) + +ADD_EXECUTABLE(AuthoringTool + ${COMMON_FILES} +) + +set_target_properties(AuthoringTool + PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX} + CHECKED_POSTFIX ${CMAKE_CHECKED_POSTFIX} + RELEASE_POSTFIX ${CMAKE_RELEASE_POSTFIX} + PROFILE_POSTFIX ${CMAKE_PROFILE_POSTFIX} +) + +SOURCE_GROUP("src" FILES ${COMMON_FILES}) + +# Target specific compile options + +TARGET_INCLUDE_DIRECTORIES(AuthoringTool + PRIVATE ${AUTHORTINGTOOL_PLATFORM_INCLUDES} + + PRIVATE ${TOOLS_COMMON_SOURCE_DIR} + PRIVATE ${EXT_AUTHORING_INCLUDE_DIR} + PRIVATE ${TK_INCLUDE_DIR} + PRIVATE ${BLAST_ROOT_DIR}/sdk/common + PRIVATE ${BLAST_ROOT_DIR}/sdk/extensions/common/include + + PRIVATE ${PHYSXSDK_INCLUDE_DIRS} + PRIVATE ${PXSHAREDSDK_INCLUDE_DIRS} + PRIVATE ${TCLAP_INCLUDE_DIRS} + PRIVATE ${TINYOBJLOADER_INCLUDE_DIRS} + PRIVATE ${FBXSDK_INCLUDE_DIRS} +) + +TARGET_COMPILE_DEFINITIONS(AuthoringTool + PRIVATE ${AUTHORTINGTOOL_COMPILE_DEFS} +) + +SET_TARGET_PROPERTIES(AuthoringTool PROPERTIES + PDB_NAME_DEBUG "AuthoringTool${CMAKE_DEBUG_POSTFIX}" + PDB_NAME_CHECKED "AuthoringTool${CMAKE_CHECKED_POSTFIX}" + PDB_NAME_PROFILE "AuthoringTool${CMAKE_PROFILE_POSTFIX}" + PDB_NAME_RELEASE "AuthoringTool${CMAKE_RELEASE_POSTFIX}" +) + +# Do final direct sets after the target has been defined +TARGET_LINK_LIBRARIES(AuthoringTool + PRIVATE NvBlast NvBlastTk NvBlastExtSerialization NvBlastExtTkSerialization NvBlastExtPxSerialization NvBlastExtPhysX NvBlastExtExporter NvBlastExtAuthoring + PRIVATE ${FBXSDK_LIBRARIES} +) + +# Copy the dlls from the deps + +ADD_CUSTOM_COMMAND(TARGET AuthoringTool POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${APEXSDK_DLLS} ${PHYSXSDK_DLLS} ${PXSHAREDSDK_DLLS} + ${BL_EXE_OUTPUT_DIR} +) + diff --git a/tools/compiler/cmake/LegacyConverter.cmake b/tools/compiler/cmake/LegacyConverter.cmake old mode 100644 new mode 100755 index dde63d0..7a2c959 --- a/tools/compiler/cmake/LegacyConverter.cmake +++ b/tools/compiler/cmake/LegacyConverter.cmake @@ -1,63 +1,63 @@ -# -# Build LegacyConverter common -# - -SET(LEGACYCONVERTER_SOURCE_DIR ${PROJECT_SOURCE_DIR}/LegacyConverter/src) - -FIND_PACKAGE(tclap $ENV{PM_tclap_VERSION} REQUIRED) -FIND_PACKAGE(PhysXSDK $ENV{PM_PhysX_VERSION} REQUIRED) -FIND_PACKAGE(PxSharedSDK $ENV{PM_PxShared_VERSION} REQUIRED) - -# Include here after the directories are defined so that the platform specific file can use the variables. -include(${PROJECT_CMAKE_FILES_DIR}/${TARGET_BUILD_PLATFORM}/LegacyConverter.cmake) - -SET(COMMON_FILES - ${LEGACYCONVERTER_PLATFORM_COMMON_FILES} - - ${LEGACYCONVERTER_SOURCE_DIR}/Main.cpp -) - -ADD_EXECUTABLE(LegacyConverter - ${COMMON_FILES} -) - -set_target_properties(LegacyConverter - PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX} - CHECKED_POSTFIX ${CMAKE_CHECKED_POSTFIX} - RELEASE_POSTFIX ${CMAKE_RELEASE_POSTFIX} - PROFILE_POSTFIX ${CMAKE_PROFILE_POSTFIX} -) - - -SOURCE_GROUP("src" FILES ${COMMON_FILES}) - -# Target specific compile options - -TARGET_INCLUDE_DIRECTORIES(LegacyConverter - PRIVATE ${LEGACYCONVERTER_PLATFORM_INCLUDES} - PRIVATE ${PXSHAREDSDK_INCLUDE_DIRS} - PRIVATE ${BLAST_ROOT_DIR}/source/common - - PRIVATE ${TCLAP_INCLUDE_DIRS} -) - -TARGET_COMPILE_DEFINITIONS(LegacyConverter - PRIVATE ${LEGACYCONVERTER_COMPILE_DEFS} -) - -SET_TARGET_PROPERTIES(LegacyConverter PROPERTIES - PDB_NAME_DEBUG "LegacyConverter${CMAKE_DEBUG_POSTFIX}" - PDB_NAME_CHECKED "LegacyConverter${CMAKE_CHECKED_POSTFIX}" - PDB_NAME_PROFILE "LegacyConverter${CMAKE_PROFILE_POSTFIX}" - PDB_NAME_RELEASE "LegacyConverter${CMAKE_RELEASE_POSTFIX}" -) - -# Do final direct sets after the target has been defined -TARGET_LINK_LIBRARIES(LegacyConverter NvBlast NvBlastTk NvBlastExtPhysX NvBlastExtImport NvBlastExtExporter NvBlastExtSerialization NvBlastExtTkSerialization NvBlastExtPxSerialization) - - -ADD_CUSTOM_COMMAND(TARGET LegacyConverter POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${PHYSXSDK_DLLS} ${PXSHAREDSDK_DLLS} - ${BL_EXE_OUTPUT_DIR} -) +# +# Build LegacyConverter common +# + +SET(LEGACYCONVERTER_SOURCE_DIR ${PROJECT_SOURCE_DIR}/LegacyConverter/src) + +FIND_PACKAGE(tclap $ENV{PM_tclap_VERSION} REQUIRED) +FIND_PACKAGE(PhysXSDK $ENV{PM_PhysX_VERSION} REQUIRED) +FIND_PACKAGE(PxSharedSDK $ENV{PM_PxShared_VERSION} REQUIRED) + +# Include here after the directories are defined so that the platform specific file can use the variables. +include(${PROJECT_CMAKE_FILES_DIR}/${TARGET_BUILD_PLATFORM}/LegacyConverter.cmake) + +SET(COMMON_FILES + ${LEGACYCONVERTER_PLATFORM_COMMON_FILES} + + ${LEGACYCONVERTER_SOURCE_DIR}/Main.cpp +) + +ADD_EXECUTABLE(LegacyConverter + ${COMMON_FILES} +) + +set_target_properties(LegacyConverter + PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX} + CHECKED_POSTFIX ${CMAKE_CHECKED_POSTFIX} + RELEASE_POSTFIX ${CMAKE_RELEASE_POSTFIX} + PROFILE_POSTFIX ${CMAKE_PROFILE_POSTFIX} +) + + +SOURCE_GROUP("src" FILES ${COMMON_FILES}) + +# Target specific compile options + +TARGET_INCLUDE_DIRECTORIES(LegacyConverter + PRIVATE ${LEGACYCONVERTER_PLATFORM_INCLUDES} + PRIVATE ${PXSHAREDSDK_INCLUDE_DIRS} + PRIVATE ${BLAST_ROOT_DIR}/source/common + + PRIVATE ${TCLAP_INCLUDE_DIRS} +) + +TARGET_COMPILE_DEFINITIONS(LegacyConverter + PRIVATE ${LEGACYCONVERTER_COMPILE_DEFS} +) + +SET_TARGET_PROPERTIES(LegacyConverter PROPERTIES + PDB_NAME_DEBUG "LegacyConverter${CMAKE_DEBUG_POSTFIX}" + PDB_NAME_CHECKED "LegacyConverter${CMAKE_CHECKED_POSTFIX}" + PDB_NAME_PROFILE "LegacyConverter${CMAKE_PROFILE_POSTFIX}" + PDB_NAME_RELEASE "LegacyConverter${CMAKE_RELEASE_POSTFIX}" +) + +# Do final direct sets after the target has been defined +TARGET_LINK_LIBRARIES(LegacyConverter NvBlast NvBlastTk NvBlastExtPhysX NvBlastExtImport NvBlastExtExporter NvBlastExtSerialization NvBlastExtTkSerialization NvBlastExtPxSerialization) + + +ADD_CUSTOM_COMMAND(TARGET LegacyConverter POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${PHYSXSDK_DLLS} ${PXSHAREDSDK_DLLS} + ${BL_EXE_OUTPUT_DIR} +) diff --git a/tools/compiler/cmake/Windows/ApexImporter.cmake b/tools/compiler/cmake/Windows/ApexImporter.cmake old mode 100644 new mode 100755 index 6ed576d..17d4234 --- a/tools/compiler/cmake/Windows/ApexImporter.cmake +++ b/tools/compiler/cmake/Windows/ApexImporter.cmake @@ -1,20 +1,20 @@ -# -# Build ApexImporter Windows -# - -SET(APEXIMPORTER_PLATFORM_COMMON_FILES -) - -SET(APEXIMPORTER_PLATFORM_INCLUDES -) - -SET(APEXIMPORTER_COMPILE_DEFS - # Common to all configurations - ${BLASTTOOLS_SLN_COMPILE_DEFS};_CONSOLE - - $<$:${BLASTTOOLS_SLN_DEBUG_COMPILE_DEFS}> - $<$:${BLASTTOOLS_SLN_CHECKED_COMPILE_DEFS}> - $<$:${BLASTTOOLS_SLN_PROFILE_COMPILE_DEFS}> - $<$:${BLASTTOOLS_SLN_RELEASE_COMPILE_DEFS}> -) - +# +# Build ApexImporter Windows +# + +SET(APEXIMPORTER_PLATFORM_COMMON_FILES +) + +SET(APEXIMPORTER_PLATFORM_INCLUDES +) + +SET(APEXIMPORTER_COMPILE_DEFS + # Common to all configurations + ${BLASTTOOLS_SLN_COMPILE_DEFS};_CONSOLE + + $<$:${BLASTTOOLS_SLN_DEBUG_COMPILE_DEFS}> + $<$:${BLASTTOOLS_SLN_CHECKED_COMPILE_DEFS}> + $<$:${BLASTTOOLS_SLN_PROFILE_COMPILE_DEFS}> + $<$:${BLASTTOOLS_SLN_RELEASE_COMPILE_DEFS}> +) + diff --git a/tools/compiler/cmake/Windows/AuthoringTool.cmake b/tools/compiler/cmake/Windows/AuthoringTool.cmake old mode 100644 new mode 100755 index 3dfc954..d41b6e9 --- a/tools/compiler/cmake/Windows/AuthoringTool.cmake +++ b/tools/compiler/cmake/Windows/AuthoringTool.cmake @@ -1,20 +1,22 @@ -# -# Build AuthoringTool Windows -# - -SET(AUTHORTINGTOOL_PLATFORM_COMMON_FILES -) - -SET(AUTHORTINGTOOL_PLATFORM_INCLUDES -) - -SET(AUTHORTINGTOOL_COMPILE_DEFS - # Common to all configurations - ${BLASTTOOLS_SLN_COMPILE_DEFS};_CONSOLE - - $<$:${BLASTTOOLS_SLN_DEBUG_COMPILE_DEFS}> - $<$:${BLASTTOOLS_SLN_CHECKED_COMPILE_DEFS}> - $<$:${BLASTTOOLS_SLN_PROFILE_COMPILE_DEFS}> - $<$:${BLASTTOOLS_SLN_RELEASE_COMPILE_DEFS}> -) - +# +# Build AuthoringTool Windows +# + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244") + +SET(AUTHORTINGTOOL_PLATFORM_COMMON_FILES +) + +SET(AUTHORTINGTOOL_PLATFORM_INCLUDES +) + +SET(AUTHORTINGTOOL_COMPILE_DEFS + # Common to all configurations + ${BLASTTOOLS_SLN_COMPILE_DEFS};_CONSOLE + + $<$:${BLASTTOOLS_SLN_DEBUG_COMPILE_DEFS}> + $<$:${BLASTTOOLS_SLN_CHECKED_COMPILE_DEFS}> + $<$:${BLASTTOOLS_SLN_PROFILE_COMPILE_DEFS}> + $<$:${BLASTTOOLS_SLN_RELEASE_COMPILE_DEFS}> +) + diff --git a/tools/compiler/cmake/Windows/CMakeLists.txt b/tools/compiler/cmake/Windows/CMakeLists.txt old mode 100644 new mode 100755 index 00c8bbf..17b942e --- a/tools/compiler/cmake/Windows/CMakeLists.txt +++ b/tools/compiler/cmake/Windows/CMakeLists.txt @@ -1,51 +1,51 @@ -#Platform specific compile flags and project includes - -SET(CMAKE_CXX_FLAGS "/EHsc /GR- /GF /MP /Gy /d2Zi+ /errorReport:prompt /fp:fast /Gd /Gm- /GS- /nologo /W4 /WX /Zc:forScope /Zc:inline /Zc:wchar_t /Zi") - -# Are we using the static or dynamic RT library? Whatever we use, it needs to be the same in any dependencies -# we pull in or we're potentially having mismatch issues. -IF(STATIC_WINCRT) - SET(WINCRT_NDEBUG "/MT") - SET(WINCRT_DEBUG "/MTd") -ELSE() - SET(WINCRT_NDEBUG "/MD") - SET(WINCRT_DEBUG "/MDd") -ENDIF() - -SET(CMAKE_CXX_FLAGS_DEBUG "/Od /RTCsu ${WINCRT_DEBUG}") -SET(CMAKE_CXX_FLAGS_CHECKED "/Ox ${WINCRT_NDEBUG}") -SET(CMAKE_CXX_FLAGS_PROFILE "/Ox ${WINCRT_NDEBUG}") -SET(CMAKE_CXX_FLAGS_RELEASE "/Ox ${WINCRT_NDEBUG}") - -# Build PDBs for all configurations -SET(CMAKE_SHARED_LINKER_FLAGS "/DEBUG") - -IF(CMAKE_CL_64) - ADD_DEFINITIONS(-DWIN64) -ENDIF(CMAKE_CL_64) - -SET(BLASTTOOLS_SLN_COMPILE_DEFS WIN32;WIN64;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;) - -SET(BLASTTOOLS_SLN_DEBUG_COMPILE_DEFS _DEBUG;NV_DEBUG=1;) -SET(BLASTTOOLS_SLN_CHECKED_COMPILE_DEFS NDEBUG;NV_CHECKED=1;) -SET(BLASTTOOLS_SLN_PROFILE_COMPILE_DEFS NDEBUG;NV_PROFILE=1;) -SET(BLASTTOOLS_SLN_RELEASE_COMPILE_DEFS NDEBUG;) - -IF(CMAKE_CL_64) - SET(LIBPATH_SUFFIX "x64") -ELSE(CMAKE_CL_64) - SET(LIBPATH_SUFFIX "x86") -ENDIF(CMAKE_CL_64) - -SET(CMAKE_DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}_${LIBPATH_SUFFIX}") -SET(CMAKE_PROFILE_POSTFIX "${CMAKE_PROFILE_POSTFIX}_${LIBPATH_SUFFIX}") -SET(CMAKE_CHECKED_POSTFIX "${CMAKE_CHECKED_POSTFIX}_${LIBPATH_SUFFIX}") -SET(CMAKE_RELEASE_POSTFIX "${CMAKE_RELEASE_POSTFIX}_${LIBPATH_SUFFIX}") - -# Should this be here or in the common part? -#ADD_SUBDIRECTORY(${BLAST_ROOT_DIR}/sdk "${CMAKE_CURRENT_BINARY_DIR}/blast_bin") - -# Include all of the projects -INCLUDE(${PROJECT_CMAKE_FILES_DIR}/LegacyConverter.cmake) -INCLUDE(${PROJECT_CMAKE_FILES_DIR}/AuthoringTool.cmake) -INCLUDE(${PROJECT_CMAKE_FILES_DIR}/ApexImporter.cmake) +#Platform specific compile flags and project includes + +SET(CMAKE_CXX_FLAGS "/EHsc /GR- /GF /MP /Gy /d2Zi+ /errorReport:prompt /fp:fast /Gd /Gm- /GS- /nologo /W4 /WX /Zc:forScope /Zc:inline /Zc:wchar_t /Zi") + +# Are we using the static or dynamic RT library? Whatever we use, it needs to be the same in any dependencies +# we pull in or we're potentially having mismatch issues. +IF(STATIC_WINCRT) + SET(WINCRT_NDEBUG "/MT") + SET(WINCRT_DEBUG "/MTd") +ELSE() + SET(WINCRT_NDEBUG "/MD") + SET(WINCRT_DEBUG "/MDd") +ENDIF() + +SET(CMAKE_CXX_FLAGS_DEBUG "/Od /RTCsu ${WINCRT_DEBUG}") +SET(CMAKE_CXX_FLAGS_CHECKED "/Ox ${WINCRT_NDEBUG}") +SET(CMAKE_CXX_FLAGS_PROFILE "/Ox ${WINCRT_NDEBUG}") +SET(CMAKE_CXX_FLAGS_RELEASE "/Ox ${WINCRT_NDEBUG}") + +# Build PDBs for all configurations +SET(CMAKE_SHARED_LINKER_FLAGS "/DEBUG") + +IF(CMAKE_CL_64) + ADD_DEFINITIONS(-DWIN64) +ENDIF(CMAKE_CL_64) + +SET(BLASTTOOLS_SLN_COMPILE_DEFS WIN32;WIN64;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;) + +SET(BLASTTOOLS_SLN_DEBUG_COMPILE_DEFS _DEBUG;NV_DEBUG=1;) +SET(BLASTTOOLS_SLN_CHECKED_COMPILE_DEFS NDEBUG;NV_CHECKED=1;) +SET(BLASTTOOLS_SLN_PROFILE_COMPILE_DEFS NDEBUG;NV_PROFILE=1;) +SET(BLASTTOOLS_SLN_RELEASE_COMPILE_DEFS NDEBUG;) + +IF(CMAKE_CL_64) + SET(LIBPATH_SUFFIX "x64") +ELSE(CMAKE_CL_64) + SET(LIBPATH_SUFFIX "x86") +ENDIF(CMAKE_CL_64) + +SET(CMAKE_DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}_${LIBPATH_SUFFIX}") +SET(CMAKE_PROFILE_POSTFIX "${CMAKE_PROFILE_POSTFIX}_${LIBPATH_SUFFIX}") +SET(CMAKE_CHECKED_POSTFIX "${CMAKE_CHECKED_POSTFIX}_${LIBPATH_SUFFIX}") +SET(CMAKE_RELEASE_POSTFIX "${CMAKE_RELEASE_POSTFIX}_${LIBPATH_SUFFIX}") + +# Should this be here or in the common part? +#ADD_SUBDIRECTORY(${BLAST_ROOT_DIR}/sdk "${CMAKE_CURRENT_BINARY_DIR}/blast_bin") + +# Include all of the projects +INCLUDE(${PROJECT_CMAKE_FILES_DIR}/LegacyConverter.cmake) +INCLUDE(${PROJECT_CMAKE_FILES_DIR}/AuthoringTool.cmake) +INCLUDE(${PROJECT_CMAKE_FILES_DIR}/ApexImporter.cmake) diff --git a/tools/compiler/cmake/Windows/LegacyConverter.cmake b/tools/compiler/cmake/Windows/LegacyConverter.cmake old mode 100644 new mode 100755 index 5653bb9..512753c --- a/tools/compiler/cmake/Windows/LegacyConverter.cmake +++ b/tools/compiler/cmake/Windows/LegacyConverter.cmake @@ -1,20 +1,20 @@ -# -# Build LegacyConverter Windows -# - -SET(LEGACYCONVERTER_PLATFORM_COMMON_FILES -) - -SET(LEGACYCONVERTER_PLATFORM_INCLUDES -) - -SET(LEGACYCONVERTER_COMPILE_DEFS - # Common to all configurations - ${BLASTTOOLS_SLN_COMPILE_DEFS};_CONSOLE - - $<$:${BLASTTOOLS_SLN_DEBUG_COMPILE_DEFS}> - $<$:${BLASTTOOLS_SLN_CHECKED_COMPILE_DEFS}> - $<$:${BLASTTOOLS_SLN_PROFILE_COMPILE_DEFS}> - $<$:${BLASTTOOLS_SLN_RELEASE_COMPILE_DEFS}> -) - +# +# Build LegacyConverter Windows +# + +SET(LEGACYCONVERTER_PLATFORM_COMMON_FILES +) + +SET(LEGACYCONVERTER_PLATFORM_INCLUDES +) + +SET(LEGACYCONVERTER_COMPILE_DEFS + # Common to all configurations + ${BLASTTOOLS_SLN_COMPILE_DEFS};_CONSOLE + + $<$:${BLASTTOOLS_SLN_DEBUG_COMPILE_DEFS}> + $<$:${BLASTTOOLS_SLN_CHECKED_COMPILE_DEFS}> + $<$:${BLASTTOOLS_SLN_PROFILE_COMPILE_DEFS}> + $<$:${BLASTTOOLS_SLN_RELEASE_COMPILE_DEFS}> +) + -- cgit v1.2.3