APEX Framework: RenderMeshAsset.h Source File

NVIDIA APEX

RenderMeshAsset.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008-2017, NVIDIA CORPORATION.  All rights reserved.
00003  *
00004  * NVIDIA CORPORATION and its licensors retain all intellectual property
00005  * and proprietary rights in and to this software, related documentation
00006  * and any modifications thereto.  Any use, reproduction, disclosure or
00007  * distribution of this software and related documentation without an express
00008  * license agreement from NVIDIA CORPORATION is strictly prohibited.
00009  */
00010 
00011 
00012 #ifndef RENDER_MESH_ASSET_H
00013 #define RENDER_MESH_ASSET_H
00014 
00020 #include "ApexUsingNamespace.h"
00021 #include "VertexFormat.h"
00022 #include "Asset.h"
00023 #include "RenderBufferData.h"
00024 #include "RenderMesh.h"
00025 
00026 namespace nvidia
00027 {
00028 namespace apex
00029 {
00030 
00031 PX_PUSH_PACK_DEFAULT
00032 
00033 class RenderMeshActor;
00034 class RenderMeshActorDesc;
00035 class CustomBufferIterator;
00036 
00038 #define RENDER_MESH_AUTHORING_TYPE_NAME "ApexRenderMesh"
00039 
00043 struct RenderMeshAssetStats
00044 {
00045     uint32_t    totalBytes;             
00046     uint32_t    submeshCount;           
00047     uint32_t    partCount;              
00048     uint32_t    vertexCount;            
00049     uint32_t    indexCount;             
00050     uint32_t    vertexBufferBytes;      
00051     uint32_t    indexBufferBytes;       
00052 };
00053 
00057 struct RenderMeshAssetInstanceMode
00058 {
00062     enum Enum
00063     {
00064         POSE_SCALE = 0,
00065         POS_VEL_LIFE,
00066 
00067         NUM_MODES
00068     };
00069 };
00070 
00071 
00075 struct VertexColor
00076 {
00077 public:
00078 
00079     PX_INLINE                   VertexColor()   {}
00080 
00084     PX_INLINE                   VertexColor(const ColorRGBA c)
00085     {
00086         const float recip255 = 1 / (float)255;
00087         set((float)c.r * recip255, (float)c.g * recip255, (float)c.b * recip255, (float)c.a * recip255);
00088     }
00089 
00093     PX_INLINE   VertexColor&    operator = (const VertexColor& c)
00094     {
00095         r = c.r;
00096         g = c.g;
00097         b = c.b;
00098         a = c.a;
00099         return *this;
00100     }
00101 
00103     PX_INLINE   void            set(float _r, float _g, float _b, float _a)
00104     {
00105         r = _r;
00106         g = _g;
00107         b = _b;
00108         a = _a;
00109     }
00110 
00112     PX_INLINE   ColorRGBA       toColorRGBA() const
00113     {
00114         return ColorRGBA((uint8_t)(255 * r + (float)0.5),
00115                            (uint8_t)(255 * g + (float)0.5),
00116                            (uint8_t)(255 * b + (float)0.5),
00117                            (uint8_t)(255 * a + (float)0.5));
00118     }
00119 
00120     float r;        
00121     float g;        
00122     float b;        
00123     float a;        
00124 };
00125 
00126 
00130 struct VertexUV
00131 {
00132     VertexUV() {}
00133 
00137     VertexUV(float _u, float _v)
00138     {
00139         set(_u, _v);
00140     }
00141 
00145     VertexUV(const float uv[])
00146     {
00147         set(uv);
00148     }
00149 
00153     void            set(float _u, float _v)
00154     {
00155         u = _u;
00156         v = _v;
00157     }
00158 
00162     void            set(const float uv[])
00163     {
00164         u = uv[0];
00165         v = uv[1];
00166     }
00167 
00171     float&          operator [](int i)
00172     {
00173         PX_ASSERT(i >= 0 && i <= 1);
00174         return (&u)[i];
00175     }
00176 
00180     const float&    operator [](int i) const
00181     {
00182         PX_ASSERT(i >= 0 && i <= 1);
00183         return (&u)[i];
00184     }
00185 
00187     float   u;
00189     float   v;
00190 };
00191 
00192 
00196 struct Vertex
00197 {
00198     PxVec3      position;       
00199     PxVec3      normal;         
00200     PxVec3      tangent;        
00201     PxVec3      binormal;       
00202     VertexUV    uv[VertexFormat::MAX_UV_COUNT]; 
00203     VertexColor color;          
00204     uint16_t    boneIndices[VertexFormat::MAX_BONE_PER_VERTEX_COUNT]; 
00205     float       boneWeights[VertexFormat::MAX_BONE_PER_VERTEX_COUNT]; 
00206     uint16_t    displacementFlags; 
00207 
00211     Vertex()
00212     {
00213         memset(this, 0, sizeof(Vertex));
00214     }
00215 };
00216 
00217 
00221 struct ExplicitRenderTriangle
00222 {
00223     Vertex      vertices[3];        
00224     int32_t     submeshIndex;       
00225     uint32_t    smoothingMask;      
00226     uint32_t    extraDataIndex;     
00227 
00231     PxVec3  calculateNormal() const
00232     {
00233         return (vertices[1].position - vertices[0].position).cross(vertices[2].position - vertices[0].position);
00234     }
00235 };
00236 
00237 
00238 
00242 struct RenderMeshPartData
00243 {
00244     RenderMeshPartData() : triangleCount(0), userData(NULL) {}
00245 
00249     RenderMeshPartData(uint32_t _triCount, void* _data) : triangleCount(_triCount), userData(_data) {}
00250 
00251     uint32_t        triangleCount;  
00252     void*           userData;       
00253 };
00254 
00255 
00259 class RenderMeshAssetAuthoring : public AssetAuthoring
00260 {
00261 public:
00263     class VertexBuffer : public RenderBufferData<RenderVertexSemantic, RenderVertexSemantic::Enum> {};
00264 
00266     struct Primitive
00267     {
00271         enum Enum
00272         {
00273             TRIANGLE_LIST,
00274             //      TRIANGLE_STRIP, // Not supported for now
00275             //      TRIANGLE_FAN,   // Not supported for now
00276 
00277             COUNT
00278         };
00279     };
00280 
00282     struct IndexType
00283     {
00287         enum Enum
00288         {
00289             UINT,
00290             USHORT,
00291 
00292             COUNT
00293         };
00294     };
00295 
00298     class SubmeshDesc
00299     {
00300     public:
00302         const char*             m_materialName;
00303 
00305         const VertexBuffer*     m_vertexBuffers;
00306 
00308         uint32_t                m_numVertexBuffers;
00309 
00311         uint32_t                m_numVertices;
00312 
00314         Primitive::Enum         m_primitive;
00315 
00317         IndexType::Enum         m_indexType;
00318 
00320         const void*             m_vertexIndices;
00321 
00323         uint32_t                m_numIndices;
00324 
00329         uint32_t*               m_smoothingGroups;
00330 
00332         uint32_t                m_firstVertex;
00333 
00335         const void*             m_partIndices;
00336 
00338         uint32_t                m_numParts;
00339 
00341         RenderCullMode::Enum    m_cullMode;
00342 
00344         SubmeshDesc()
00345         {
00346             memset(this, 0, sizeof(SubmeshDesc));
00347         }
00348 
00350         bool    isValid() const
00351         {
00352             return  m_materialName != NULL &&
00353                     m_vertexBuffers != NULL &&  // BRG - todo: check the vertex buffers for validity
00354                     m_numVertexBuffers > 0 &&
00355                     m_numVertices > 0 &&
00356                     m_primitive >= (Primitive::Enum)0 && m_primitive < Primitive::COUNT &&
00357                     m_indexType >= (IndexType::Enum)0 && m_indexType < IndexType::COUNT &&
00358                     m_numIndices > 0 &&
00359                     (m_partIndices == NULL || m_numParts > 0) &&
00360                     (m_cullMode == RenderCullMode::CLOCKWISE || m_cullMode == RenderCullMode::COUNTER_CLOCKWISE || m_cullMode == RenderCullMode::NONE);
00361         }
00362     };
00363 
00365     class MeshDesc
00366     {
00367     public:
00369         const SubmeshDesc*      m_submeshes;
00370 
00372         uint32_t                m_numSubmeshes;
00373 
00375         TextureUVOrigin::Enum   m_uvOrigin;
00376 
00377 
00378 
00380         MeshDesc() : m_submeshes(NULL), m_numSubmeshes(0), m_uvOrigin(TextureUVOrigin::ORIGIN_TOP_LEFT) {}
00381 
00383         bool    isValid() const
00384         {
00385             return  m_submeshes != NULL &&
00386                     m_numSubmeshes > 0;
00387         }
00388     };
00389 
00390 
00396     virtual void                    createRenderMesh(const MeshDesc& meshDesc, bool createMappingInformation) = 0;
00397 
00398 
00407     virtual uint32_t                createReductionMap(uint32_t* map, const Vertex* vertices, const uint32_t* smoothingGroups, uint32_t vertexCount,
00408                                                        const PxVec3& positionTolerance, float normalTolerance, float UVTolerance) = 0;
00409 
00410 
00414     virtual void                    deleteStaticBuffersAfterUse(bool set)   = 0;
00415 
00420     /* Public access to RenderMeshAsset get methods */
00421 
00423     virtual uint32_t                getSubmeshCount() const = 0;
00425     virtual uint32_t                getPartCount() const = 0;
00427     virtual const char*             getMaterialName(uint32_t submeshIndex) const = 0;
00429     virtual void                    setMaterialName(uint32_t submeshIndex, const char* name) = 0;
00431     virtual void                    setWindingOrder(uint32_t submeshIndex, RenderCullMode::Enum winding) = 0;
00433     virtual RenderCullMode::Enum    getWindingOrder(uint32_t submeshIndex) const = 0;
00435     virtual const RenderSubmesh&    getSubmesh(uint32_t submeshIndex) const = 0;
00437     virtual RenderSubmesh&          getSubmeshWritable(uint32_t submeshIndex) = 0;
00439     virtual const PxBounds3&        getBounds(uint32_t partIndex = 0) const = 0;
00441     virtual void                    getStats(RenderMeshAssetStats& stats) const = 0;
00442 };
00443 
00444 
00450 class RenderMeshAsset : public Asset
00451 {
00452 public:
00453 
00459     virtual RenderMeshActor*        createActor(const RenderMeshActorDesc& desc) = 0;
00460 
00464     virtual void                    releaseActor(RenderMeshActor&) = 0;
00465 
00471     virtual uint32_t                getSubmeshCount() const = 0;
00472 
00478     virtual uint32_t                getPartCount() const = 0;
00479 
00483     virtual const char*             getMaterialName(uint32_t submeshIndex) const = 0;
00484 
00491     virtual const RenderSubmesh&    getSubmesh(uint32_t submeshIndex) const = 0;
00492 
00498     virtual const PxBounds3&        getBounds(uint32_t partIndex = 0) const = 0;
00499 
00505     virtual void                    getStats(RenderMeshAssetStats& stats) const = 0;
00506 
00510     virtual UserOpaqueMesh*         getOpaqueMesh(void) const = 0;
00511 
00512 protected:
00513     virtual                         ~RenderMeshAsset() {}
00514 };
00515 
00516 PX_POP_PACK
00517 
00518 }
00519 } // end namespace nvidia::apex
00520 
00521 #endif // RENDER_MESH_ASSET_H

Generated on Fri Dec 15 2017 13:58:35
Copyright © 2012-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved.