RenderMeshAsset.h
Go to the documentation of this file.
00001 //
00002 // Redistribution and use in source and binary forms, with or without
00003 // modification, are permitted provided that the following conditions
00004 // are met:
00005 //  * Redistributions of source code must retain the above copyright
00006 //    notice, this list of conditions and the following disclaimer.
00007 //  * Redistributions in binary form must reproduce the above copyright
00008 //    notice, this list of conditions and the following disclaimer in the
00009 //    documentation and/or other materials provided with the distribution.
00010 //  * Neither the name of NVIDIA CORPORATION nor the names of its
00011 //    contributors may be used to endorse or promote products derived
00012 //    from this software without specific prior written permission.
00013 //
00014 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
00015 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00016 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00017 // PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00018 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00019 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00020 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00021 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00022 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00023 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00024 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 //
00026 // Copyright (c) 2018 NVIDIA Corporation. All rights reserved.
00027 
00028 
00029 
00030 #ifndef RENDER_MESH_ASSET_H
00031 #define RENDER_MESH_ASSET_H
00032 
00038 #include "ApexUsingNamespace.h"
00039 #include "VertexFormat.h"
00040 #include "Asset.h"
00041 #include "RenderBufferData.h"
00042 #include "RenderMesh.h"
00043 
00044 namespace nvidia
00045 {
00046 namespace apex
00047 {
00048 
00049 PX_PUSH_PACK_DEFAULT
00050 
00051 class RenderMeshActor;
00052 class RenderMeshActorDesc;
00053 class CustomBufferIterator;
00054 
00056 #define RENDER_MESH_AUTHORING_TYPE_NAME "ApexRenderMesh"
00057 
00061 struct RenderMeshAssetStats
00062 {
00063     uint32_t    totalBytes;             
00064     uint32_t    submeshCount;           
00065     uint32_t    partCount;              
00066     uint32_t    vertexCount;            
00067     uint32_t    indexCount;             
00068     uint32_t    vertexBufferBytes;      
00069     uint32_t    indexBufferBytes;       
00070 };
00071 
00075 struct RenderMeshAssetInstanceMode
00076 {
00080     enum Enum
00081     {
00082         POSE_SCALE = 0,
00083         POS_VEL_LIFE,
00084 
00085         NUM_MODES
00086     };
00087 };
00088 
00089 
00093 struct VertexColor
00094 {
00095 public:
00096 
00097     PX_INLINE                   VertexColor()   {}
00098 
00102     PX_INLINE                   VertexColor(const ColorRGBA c)
00103     {
00104         const float recip255 = 1 / (float)255;
00105         set((float)c.r * recip255, (float)c.g * recip255, (float)c.b * recip255, (float)c.a * recip255);
00106     }
00107 
00111     PX_INLINE   VertexColor&    operator = (const VertexColor& c)
00112     {
00113         r = c.r;
00114         g = c.g;
00115         b = c.b;
00116         a = c.a;
00117         return *this;
00118     }
00119 
00121     PX_INLINE   void            set(float _r, float _g, float _b, float _a)
00122     {
00123         r = _r;
00124         g = _g;
00125         b = _b;
00126         a = _a;
00127     }
00128 
00130     PX_INLINE   ColorRGBA       toColorRGBA() const
00131     {
00132         return ColorRGBA((uint8_t)(255 * r + (float)0.5),
00133                            (uint8_t)(255 * g + (float)0.5),
00134                            (uint8_t)(255 * b + (float)0.5),
00135                            (uint8_t)(255 * a + (float)0.5));
00136     }
00137 
00138     float r;        
00139     float g;        
00140     float b;        
00141     float a;        
00142 };
00143 
00144 
00148 struct VertexUV
00149 {
00150     VertexUV() {}
00151 
00155     VertexUV(float _u, float _v)
00156     {
00157         set(_u, _v);
00158     }
00159 
00163     VertexUV(const float uv[])
00164     {
00165         set(uv);
00166     }
00167 
00171     void            set(float _u, float _v)
00172     {
00173         u = _u;
00174         v = _v;
00175     }
00176 
00180     void            set(const float uv[])
00181     {
00182         u = uv[0];
00183         v = uv[1];
00184     }
00185 
00189     float&          operator [](int i)
00190     {
00191         PX_ASSERT(i >= 0 && i <= 1);
00192         return (&u)[i];
00193     }
00194 
00198     const float&    operator [](int i) const
00199     {
00200         PX_ASSERT(i >= 0 && i <= 1);
00201         return (&u)[i];
00202     }
00203 
00205     float   u;
00207     float   v;
00208 };
00209 
00210 
00214 struct Vertex
00215 {
00216     PxVec3      position;       
00217     PxVec3      normal;         
00218     PxVec3      tangent;        
00219     PxVec3      binormal;       
00220     VertexUV    uv[VertexFormat::MAX_UV_COUNT]; 
00221     VertexColor color;          
00222     uint16_t    boneIndices[VertexFormat::MAX_BONE_PER_VERTEX_COUNT]; 
00223     float       boneWeights[VertexFormat::MAX_BONE_PER_VERTEX_COUNT]; 
00224     uint16_t    displacementFlags; 
00225 
00229     Vertex()
00230     {
00231         memset(this, 0, sizeof(Vertex));
00232     }
00233 };
00234 
00235 
00239 struct ExplicitRenderTriangle
00240 {
00241     Vertex      vertices[3];        
00242     int32_t     submeshIndex;       
00243     uint32_t    smoothingMask;      
00244     uint32_t    extraDataIndex;     
00245 
00249     PxVec3  calculateNormal() const
00250     {
00251         return (vertices[1].position - vertices[0].position).cross(vertices[2].position - vertices[0].position);
00252     }
00253 };
00254 
00255 
00256 
00260 struct RenderMeshPartData
00261 {
00262     RenderMeshPartData() : triangleCount(0), userData(NULL) {}
00263 
00267     RenderMeshPartData(uint32_t _triCount, void* _data) : triangleCount(_triCount), userData(_data) {}
00268 
00269     uint32_t        triangleCount;  
00270     void*           userData;       
00271 };
00272 
00273 
00277 class RenderMeshAssetAuthoring : public AssetAuthoring
00278 {
00279 public:
00281     class VertexBuffer : public RenderBufferData<RenderVertexSemantic, RenderVertexSemantic::Enum> {};
00282 
00284     struct Primitive
00285     {
00289         enum Enum
00290         {
00291             TRIANGLE_LIST,
00292             //      TRIANGLE_STRIP, // Not supported for now
00293             //      TRIANGLE_FAN,   // Not supported for now
00294 
00295             COUNT
00296         };
00297     };
00298 
00300     struct IndexType
00301     {
00305         enum Enum
00306         {
00307             UINT,
00308             USHORT,
00309 
00310             COUNT
00311         };
00312     };
00313 
00316     class SubmeshDesc
00317     {
00318     public:
00320         const char*             m_materialName;
00321 
00323         const VertexBuffer*     m_vertexBuffers;
00324 
00326         uint32_t                m_numVertexBuffers;
00327 
00329         uint32_t                m_numVertices;
00330 
00332         Primitive::Enum         m_primitive;
00333 
00335         IndexType::Enum         m_indexType;
00336 
00338         const void*             m_vertexIndices;
00339 
00341         uint32_t                m_numIndices;
00342 
00347         uint32_t*               m_smoothingGroups;
00348 
00350         uint32_t                m_firstVertex;
00351 
00353         const void*             m_partIndices;
00354 
00356         uint32_t                m_numParts;
00357 
00359         RenderCullMode::Enum    m_cullMode;
00360 
00362         SubmeshDesc()
00363         {
00364             memset(this, 0, sizeof(SubmeshDesc));
00365         }
00366 
00368         bool    isValid() const
00369         {
00370             return  m_materialName != NULL &&
00371                     m_vertexBuffers != NULL &&  // BRG - todo: check the vertex buffers for validity
00372                     m_numVertexBuffers > 0 &&
00373                     m_numVertices > 0 &&
00374                     m_primitive >= (Primitive::Enum)0 && m_primitive < Primitive::COUNT &&
00375                     m_indexType >= (IndexType::Enum)0 && m_indexType < IndexType::COUNT &&
00376                     m_numIndices > 0 &&
00377                     (m_partIndices == NULL || m_numParts > 0) &&
00378                     (m_cullMode == RenderCullMode::CLOCKWISE || m_cullMode == RenderCullMode::COUNTER_CLOCKWISE || m_cullMode == RenderCullMode::NONE);
00379         }
00380     };
00381 
00383     class MeshDesc
00384     {
00385     public:
00387         const SubmeshDesc*      m_submeshes;
00388 
00390         uint32_t                m_numSubmeshes;
00391 
00393         TextureUVOrigin::Enum   m_uvOrigin;
00394 
00395 
00396 
00398         MeshDesc() : m_submeshes(NULL), m_numSubmeshes(0), m_uvOrigin(TextureUVOrigin::ORIGIN_TOP_LEFT) {}
00399 
00401         bool    isValid() const
00402         {
00403             return  m_submeshes != NULL &&
00404                     m_numSubmeshes > 0;
00405         }
00406     };
00407 
00408 
00414     virtual void                    createRenderMesh(const MeshDesc& meshDesc, bool createMappingInformation) = 0;
00415 
00416 
00425     virtual uint32_t                createReductionMap(uint32_t* map, const Vertex* vertices, const uint32_t* smoothingGroups, uint32_t vertexCount,
00426                                                        const PxVec3& positionTolerance, float normalTolerance, float UVTolerance) = 0;
00427 
00428 
00432     virtual void                    deleteStaticBuffersAfterUse(bool set)   = 0;
00433 
00438     /* Public access to RenderMeshAsset get methods */
00439 
00441     virtual uint32_t                getSubmeshCount() const = 0;
00443     virtual uint32_t                getPartCount() const = 0;
00445     virtual const char*             getMaterialName(uint32_t submeshIndex) const = 0;
00447     virtual void                    setMaterialName(uint32_t submeshIndex, const char* name) = 0;
00449     virtual void                    setWindingOrder(uint32_t submeshIndex, RenderCullMode::Enum winding) = 0;
00451     virtual RenderCullMode::Enum    getWindingOrder(uint32_t submeshIndex) const = 0;
00453     virtual const RenderSubmesh&    getSubmesh(uint32_t submeshIndex) const = 0;
00455     virtual RenderSubmesh&          getSubmeshWritable(uint32_t submeshIndex) = 0;
00457     virtual const PxBounds3&        getBounds(uint32_t partIndex = 0) const = 0;
00459     virtual void                    getStats(RenderMeshAssetStats& stats) const = 0;
00460 };
00461 
00462 
00468 class RenderMeshAsset : public Asset
00469 {
00470 public:
00471 
00477     virtual RenderMeshActor*        createActor(const RenderMeshActorDesc& desc) = 0;
00478 
00482     virtual void                    releaseActor(RenderMeshActor&) = 0;
00483 
00489     virtual uint32_t                getSubmeshCount() const = 0;
00490 
00496     virtual uint32_t                getPartCount() const = 0;
00497 
00501     virtual const char*             getMaterialName(uint32_t submeshIndex) const = 0;
00502 
00509     virtual const RenderSubmesh&    getSubmesh(uint32_t submeshIndex) const = 0;
00510 
00516     virtual const PxBounds3&        getBounds(uint32_t partIndex = 0) const = 0;
00517 
00523     virtual void                    getStats(RenderMeshAssetStats& stats) const = 0;
00524 
00528     virtual UserOpaqueMesh*         getOpaqueMesh(void) const = 0;
00529 
00530 protected:
00531     virtual                         ~RenderMeshAsset() {}
00532 };
00533 
00534 PX_POP_PACK
00535 
00536 }
00537 } // end namespace nvidia::apex
00538 
00539 #endif // RENDER_MESH_ASSET_H

Generated on Sat Dec 1 2018 15:52:06

Copyright © 2012-2018 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved.