sdk/extensions/authoring/include/NvBlastExtAuthoringTypes.h

Go to the documentation of this file.
00001 // This code contains NVIDIA Confidential Information and is disclosed to you
00002 // under a form of NVIDIA software license agreement provided separately to you.
00003 //
00004 // Notice
00005 // NVIDIA Corporation and its licensors retain all intellectual property and
00006 // proprietary rights in and to this software and related documentation and
00007 // any modifications thereto. Any use, reproduction, disclosure, or
00008 // distribution of this software and related documentation without an express
00009 // license agreement from NVIDIA Corporation is strictly prohibited.
00010 //
00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
00015 //
00016 // Information and code furnished is believed to be accurate and reliable.
00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
00018 // information or for any infringement of patents or other rights of third parties that may
00019 // result from its use. No license is granted by implication or otherwise under any patent
00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
00021 // This code supersedes and replaces all information previously supplied.
00022 // NVIDIA Corporation products are not authorized for use as critical
00023 // components in life support devices or systems without express written approval of
00024 // NVIDIA Corporation.
00025 //
00026 // Copyright (c) 2016-2018 NVIDIA Corporation. All rights reserved.
00027 
00028 
00029 #ifndef NVBLASTAUTHORINGTYPES_H
00030 #define NVBLASTAUTHORINGTYPES_H
00031 
00032 #include <PxVec3.h>
00033 #include <PxVec2.h>
00034 #include <PxBounds3.h>
00035 #include "NvBlastTypes.h"
00036 
00037 #define NOT_VALID_VERTEX INT32_MAX
00038 
00039 namespace Nv
00040 {
00041 namespace Blast
00042 {
00043 
00047 struct Edge
00048 {
00049     uint32_t s, e;
00050     Edge() : s(NOT_VALID_VERTEX), e(NOT_VALID_VERTEX){}
00051     Edge(int s, int e) : s(s), e(e) {}
00052     bool operator<(const Edge& b) const
00053     {
00054         if (s == b.s)
00055             return e < b.e;
00056         else
00057             return s < b.s;
00058     }
00059 };
00060 
00064 struct Vertex
00065 {
00066     physx::PxVec3 p; // Position
00067     physx::PxVec3 n; // Normal
00068     physx::PxVec2 uv[1]; // UV-coordinates array, currently supported only one UV coordinate.
00069 };
00070 
00071 
00072 // Interior material ID
00073 #define MATERIAL_INTERIOR 1000
00074 #define SMOOTHING_GROUP_INTERIOR 1000
00075 
00076 
00077 
00081 struct Triangle
00082 {
00083     Triangle() {};
00084     Triangle(Vertex a, Vertex b, Vertex c) : a(a), b(b), c(c) {};
00085     Vertex a, b, c;
00086     int32_t userData;
00087     int32_t materialId;
00088     int32_t smoothingGroup;
00089     physx::PxVec3 getNormal() const
00090     {
00091         return ((b.p - a.p).cross(c.p - a.p));
00092     }
00093     inline Vertex& getVertex(uint32_t index)
00094     {
00095         return (&a)[index];
00096     }
00097     inline const Vertex& getVertex(uint32_t index) const
00098     {
00099         return (&a)[index];
00100     }
00101 };
00102 
00103 
00107 struct TriangleIndexed
00108 {
00109     TriangleIndexed() {};
00110     TriangleIndexed(uint32_t a, uint32_t b, uint32_t c) : ea(a), eb(b), ec(c) {};
00111 
00112     uint32_t getOpposite(uint32_t a, uint32_t b)
00113     {
00114         if (ea != a && ea != b)
00115             return ea;
00116         if (eb != a && eb != b)
00117             return eb;
00118         if (ec != a && ec != b)
00119             return ec;
00120         return NOT_VALID_VERTEX;
00121     }
00122 
00123     bool isContainEdge(uint32_t a, uint32_t b)
00124     {
00125         return (a == ea || a == eb || a == ec) && (b == ea || b == eb || b == ec);
00126     }
00127 
00128     Triangle convertToTriangle(Vertex* vertices)
00129     {
00130         Triangle tr;
00131         tr.a = vertices[ea];
00132         tr.b = vertices[eb];
00133         tr.c = vertices[ec];
00134         
00135         tr.userData = userData;
00136         tr.materialId = materialId;
00137         tr.smoothingGroup = smoothingGroup;
00138         return tr;
00139     }
00140 
00141     uint32_t ea, eb, ec;
00142     int32_t materialId;
00143     int32_t smoothingGroup;
00144     int32_t userData;
00145 };
00146 
00147 
00148 
00149 
00153 struct Facet
00154 {
00155     int32_t     firstEdgeNumber;
00156     uint32_t    edgesCount;
00157     int64_t     userData;
00158     int32_t     materialId;
00159     int32_t     smoothingGroup;
00160 
00161     Facet(int32_t fEdge = 0, uint32_t eCount = 0, int32_t materialId = 0, int64_t userData = 0, int32_t smoothingGroup = 0) : firstEdgeNumber(fEdge), edgesCount(eCount), userData(userData), materialId(materialId), smoothingGroup(smoothingGroup) {}
00162 };
00163 
00167 class RandomGeneratorBase
00168 {
00169 public:
00170     // Generates uniformly distributed value in [0, 1] range. 
00171     virtual float   getRandomValue() = 0;
00172     // Seeds random value generator
00173     virtual void    seed(int32_t seed) = 0;
00174     virtual ~RandomGeneratorBase() {};
00175 };
00176 
00180 struct CollisionHull
00181 {
00185     struct HullPolygon
00186     {
00187         // Polygon base plane
00188         float       mPlane[4];
00189         // Number vertices in polygon
00190         uint16_t    mNbVerts;
00191         // First index in CollisionHull.indices array for this polygon
00192         uint16_t    mIndexBase;
00193     };
00195 
00196     uint32_t        pointsCount;
00197     uint32_t        indicesCount;
00198     uint32_t        polygonDataCount;
00199     physx::PxVec3*  points;
00200     uint32_t*       indices;
00201     HullPolygon*    polygonData;
00202 
00203     virtual ~CollisionHull() {}
00204 
00205     virtual void release() = 0;
00206 };
00207 
00211 struct AuthoringResult
00212 {
00213     uint32_t                chunkCount; //Number of chunks in Blast asset
00214 
00215     uint32_t                bondCount; //Number of bonds in Blast asset
00216 
00217     NvBlastAsset*           asset; //Blast asset
00218 
00223     uint32_t*               assetToFractureChunkIdMap;
00224 
00230     uint32_t*               geometryOffset;
00231 
00232     Triangle*               geometry; //Raw array of Triangle for all chunks
00233 
00234     NvBlastChunkDesc*       chunkDescs; //Array of chunk descriptors. Contains chunkCount elements
00235 
00236     NvBlastBondDesc*        bondDescs; //Array of bond descriptors. Contains bondCount elements
00237 
00243     uint32_t*               collisionHullOffset;
00244 
00245     CollisionHull**         collisionHull; //Raw array of pointers to collision hull for all chunks.
00246 
00250     struct ExtPxChunk*      physicsChunks;
00251 
00256     struct ExtPxSubchunk*   physicsSubchunks;
00257 
00261     const char** materialNames;
00266     uint32_t materialCount;
00267 
00269     virtual ~AuthoringResult() {}
00270 
00274     virtual void releaseCollisionHulls() = 0;
00275 
00279     virtual void release() = 0;
00280 };
00281 
00282 
00283 } // namespace Blast
00284 } // namespace Nv
00285 
00286 
00287 #endif // ifndef NVBLASTAUTHORINGTYPES_H