Home | Namespaces | Hierarchy | Alphabetical List | Class list | Files | Namespace Members | Class members | File members | Tutorials

# SSkinMeshBuffer.h

Go to the documentation of this file.

    00001 // Copyright (C) 2002-2009 Nikolaus Gebhardt
    00002 // This file is part of the "Irrlicht Engine".
    00003 // For conditions of distribution and use, see copyright notice in irrlicht.h
    00004
    00005 #ifndef __I_SKIN_MESH_BUFFER_H_INCLUDED__
    00006 #define __I_SKIN_MESH_BUFFER_H_INCLUDED__
    00007
    00008 #include "IMeshBuffer.h"
    00009 #include "S3DVertex.h"
    00010
    00011
    00012 namespace irr
    00013 {
    00014 namespace scene
    00015 {
    00016
    00017
    00019 struct SSkinMeshBuffer : public IMeshBuffer
    00020 {
    00022         SSkinMeshBuffer(video::E_VERTEX_TYPE vt=video::EVT_STANDARD) :
    00023                 ChangedID_Vertex(1), ChangedID_Index(1), VertexType(vt),
    00024                 MappingHint_Vertex(EHM_NEVER), MappingHint_Index(EHM_NEVER),
    00025                 BoundingBoxNeedsRecalculated(true)
    00026         {
    00027                 #ifdef _DEBUG
    00028                 setDebugName("SSkinMeshBuffer");
    00029                 #endif
    00030         }
    00031
    00033         virtual const video::SMaterial& getMaterial() const
    00034         {
    00035                 return Material;
    00036         }
    00037
    00039         virtual video::SMaterial& getMaterial()
    00040         {
    00041                 return Material;
    00042         }
    00043
    00045         virtual video::S3DVertex *getVertex(u32 index)
    00046         {
    00047                 switch (VertexType)
    00048                 {
    00049                         case video::EVT_2TCOORDS:
    00050                                 return (video::S3DVertex*)&Vertices_2TCoords[index];
    00051                         case video::EVT_TANGENTS:
    00052                                 return (video::S3DVertex*)&Vertices_Tangents[index];
    00053                         default:
    00054                                 return &Vertices_Standard[index];
    00055                 }
    00056         }
    00057
    00059         virtual const void* getVertices() const
    00060         {
    00061                 switch (VertexType)
    00062                 {
    00063                         case video::EVT_2TCOORDS:
    00064                                 return Vertices_2TCoords.const_pointer();
    00065                         case video::EVT_TANGENTS:
    00066                                 return Vertices_Tangents.const_pointer();
    00067                         default:
    00068                                 return Vertices_Standard.const_pointer();
    00069                 }
    00070         }
    00071
    00073         virtual void* getVertices()
    00074         {
    00075                 switch (VertexType)
    00076                 {
    00077                         case video::EVT_2TCOORDS:
    00078                                 return Vertices_2TCoords.pointer();
    00079                         case video::EVT_TANGENTS:
    00080                                 return Vertices_Tangents.pointer();
    00081                         default:
    00082                                 return Vertices_Standard.pointer();
    00083                 }
    00084         }
    00085
    00087         virtual u32 getVertexCount() const
    00088         {
    00089                 switch (VertexType)
    00090                 {
    00091                         case video::EVT_2TCOORDS:
    00092                                 return Vertices_2TCoords.size();
    00093                         case video::EVT_TANGENTS:
    00094                                 return Vertices_Tangents.size();
    00095                         default:
    00096                                 return Vertices_Standard.size();
    00097                 }
    00098         }
    00099
    00101
    00102         virtual video::E_INDEX_TYPE getIndexType() const { return video::EIT_16BIT; }
    00103
    00105         virtual const u16* getIndices() const
    00106         {
    00107                 return Indices.const_pointer();
    00108         }
    00109
    00111         virtual u16* getIndices()
    00112         {
    00113                 return Indices.pointer();
    00114         }
    00115
    00117         virtual u32 getIndexCount() const
    00118         {
    00119                 return Indices.size();
    00120         }
    00121
    00123         virtual const core::aabbox3d<f32>& getBoundingBox() const
    00124         {
    00125                 return BoundingBox;
    00126         }
    00127
    00129         virtual void setBoundingBox( const core::aabbox3df& box)
    00130         {
    00131                 BoundingBox = box;
    00132         }
    00133
    00135         virtual void recalculateBoundingBox()
    00136         {
    00137                 if(!BoundingBoxNeedsRecalculated)
    00138                         return;
    00139
    00140                 BoundingBoxNeedsRecalculated = false;
    00141
    00142                 switch (VertexType)
    00143                 {
    00144                         case video::EVT_STANDARD:
    00145                         {
    00146                                 if (Vertices_Standard.empty())
    00147                                         BoundingBox.reset(0,0,0);
    00148                                 else
    00149                                 {
    00150                                         BoundingBox.reset(Vertices_Standard[0].Pos);
    00151                                         for (u32 i=1; i<Vertices_Standard.size(); ++i)
    00152                                                 BoundingBox.addInternalPoint(Vertices_Standard[i].Pos);
    00153                                 }
    00154                                 break;
    00155                         }
    00156                         case video::EVT_2TCOORDS:
    00157                         {
    00158                                 if (Vertices_2TCoords.empty())
    00159                                         BoundingBox.reset(0,0,0);
    00160                                 else
    00161                                 {
    00162                                         BoundingBox.reset(Vertices_2TCoords[0].Pos);
    00163                                         for (u32 i=1; i<Vertices_2TCoords.size(); ++i)
    00164                                                 BoundingBox.addInternalPoint(Vertices_2TCoords[i].Pos);
    00165                                 }
    00166                                 break;
    00167                         }
    00168                         case video::EVT_TANGENTS:
    00169                         {
    00170                                 if (Vertices_Tangents.empty())
    00171                                         BoundingBox.reset(0,0,0);
    00172                                 else
    00173                                 {
    00174                                         BoundingBox.reset(Vertices_Tangents[0].Pos);
    00175                                         for (u32 i=1; i<Vertices_Tangents.size(); ++i)
    00176                                                 BoundingBox.addInternalPoint(Vertices_Tangents[i].Pos);
    00177                                 }
    00178                                 break;
    00179                         }
    00180                 }
    00181         }
    00182
    00184         virtual video::E_VERTEX_TYPE getVertexType() const
    00185         {
    00186                 return VertexType;
    00187         }
    00188
    00190         virtual void MoveTo_2TCoords()
    00191         {
    00192                 if (VertexType==video::EVT_STANDARD)
    00193                 {
    00194                         for(u32 n=0;n<Vertices_Standard.size();++n)
    00195                         {
    00196                                 video::S3DVertex2TCoords Vertex;
    00197                                 Vertex.Color=Vertices_Standard[n].Color;
    00198                                 Vertex.Pos=Vertices_Standard[n].Pos;
    00199                                 Vertex.Normal=Vertices_Standard[n].Normal;
    00200                                 Vertex.TCoords=Vertices_Standard[n].TCoords;
    00201                                 Vertices_2TCoords.push_back(Vertex);
    00202                         }
    00203                         Vertices_Standard.clear();
    00204                         VertexType=video::EVT_2TCOORDS;
    00205                 }
    00206         }
    00207
    00209         virtual void MoveTo_Tangents()
    00210         {
    00211                 if (VertexType==video::EVT_STANDARD)
    00212                 {
    00213                         for(u32 n=0;n<Vertices_Standard.size();++n)
    00214                         {
    00215                                 video::S3DVertexTangents Vertex;
    00216                                 Vertex.Color=Vertices_Standard[n].Color;
    00217                                 Vertex.Pos=Vertices_Standard[n].Pos;
    00218                                 Vertex.Normal=Vertices_Standard[n].Normal;
    00219                                 Vertex.TCoords=Vertices_Standard[n].TCoords;
    00220                                 Vertices_Tangents.push_back(Vertex);
    00221                         }
    00222                         Vertices_Standard.clear();
    00223                         VertexType=video::EVT_TANGENTS;
    00224                 }
    00225                 else if (VertexType==video::EVT_2TCOORDS)
    00226                 {
    00227                         for(u32 n=0;n<Vertices_2TCoords.size();++n)
    00228                         {
    00229                                 video::S3DVertexTangents Vertex;
    00230                                 Vertex.Color=Vertices_2TCoords[n].Color;
    00231                                 Vertex.Pos=Vertices_2TCoords[n].Pos;
    00232                                 Vertex.Normal=Vertices_2TCoords[n].Normal;
    00233                                 Vertex.TCoords=Vertices_2TCoords[n].TCoords;
    00234                                 Vertices_Tangents.push_back(Vertex);
    00235                         }
    00236                         Vertices_2TCoords.clear();
    00237                         VertexType=video::EVT_TANGENTS;
    00238                 }
    00239         }
    00240
    00242         virtual const core::vector3df& getPosition(u32 i) const
    00243         {
    00244                 switch (VertexType)
    00245                 {
    00246                         case video::EVT_2TCOORDS:
    00247                                 return Vertices_2TCoords[i].Pos;
    00248                         case video::EVT_TANGENTS:
    00249                                 return Vertices_Tangents[i].Pos;
    00250                         default:
    00251                                 return Vertices_Standard[i].Pos;
    00252                 }
    00253         }
    00254
    00256         virtual core::vector3df& getPosition(u32 i)
    00257         {
    00258                 switch (VertexType)
    00259                 {
    00260                         case video::EVT_2TCOORDS:
    00261                                 return Vertices_2TCoords[i].Pos;
    00262                         case video::EVT_TANGENTS:
    00263                                 return Vertices_Tangents[i].Pos;
    00264                         default:
    00265                                 return Vertices_Standard[i].Pos;
    00266                 }
    00267         }
    00268
    00270         virtual const core::vector3df& getNormal(u32 i) const
    00271         {
    00272                 switch (VertexType)
    00273                 {
    00274                         case video::EVT_2TCOORDS:
    00275                                 return Vertices_2TCoords[i].Normal;
    00276                         case video::EVT_TANGENTS:
    00277                                 return Vertices_Tangents[i].Normal;
    00278                         default:
    00279                                 return Vertices_Standard[i].Normal;
    00280                 }
    00281         }
    00282
    00284         virtual core::vector3df& getNormal(u32 i)
    00285         {
    00286                 switch (VertexType)
    00287                 {
    00288                         case video::EVT_2TCOORDS:
    00289                                 return Vertices_2TCoords[i].Normal;
    00290                         case video::EVT_TANGENTS:
    00291                                 return Vertices_Tangents[i].Normal;
    00292                         default:
    00293                                 return Vertices_Standard[i].Normal;
    00294                 }
    00295         }
    00296
    00298         virtual const core::vector2df& getTCoords(u32 i) const
    00299         {
    00300                 switch (VertexType)
    00301                 {
    00302                         case video::EVT_2TCOORDS:
    00303                                 return Vertices_2TCoords[i].TCoords;
    00304                         case video::EVT_TANGENTS:
    00305                                 return Vertices_Tangents[i].TCoords;
    00306                         default:
    00307                                 return Vertices_Standard[i].TCoords;
    00308                 }
    00309         }
    00310
    00312         virtual core::vector2df& getTCoords(u32 i)
    00313         {
    00314                 switch (VertexType)
    00315                 {
    00316                         case video::EVT_2TCOORDS:
    00317                                 return Vertices_2TCoords[i].TCoords;
    00318                         case video::EVT_TANGENTS:
    00319                                 return Vertices_Tangents[i].TCoords;
    00320                         default:
    00321                                 return Vertices_Standard[i].TCoords;
    00322                 }
    00323         }
    00324
    00326         virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) {}
    00327
    00329         virtual void append(const IMeshBuffer* const other) {}
    00330
    00332         virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const
    00333         {
    00334                 return MappingHint_Vertex;
    00335         }
    00336
    00338         virtual E_HARDWARE_MAPPING getHardwareMappingHint_Index() const
    00339         {
    00340                 return MappingHint_Index;
    00341         }
    00342
    00344         virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX )
    00345         {
    00346                 if (Buffer==EBT_VERTEX)
    00347                         MappingHint_Vertex=NewMappingHint;
    00348                 else if (Buffer==EBT_INDEX)
    00349                         MappingHint_Index=NewMappingHint;
    00350                 else if (Buffer==EBT_VERTEX_AND_INDEX)
    00351                 {
    00352                         MappingHint_Vertex=NewMappingHint;
    00353                         MappingHint_Index=NewMappingHint;
    00354                 }
    00355         }
    00356
    00358         virtual void setDirty(E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX)
    00359         {
    00360                 if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_VERTEX)
    00361                         ++ChangedID_Vertex;
    00362                 if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_INDEX)
    00363                         ++ChangedID_Index;
    00364         }
    00365
    00366         virtual u32 getChangedID_Vertex() const {return ChangedID_Vertex;}
    00367
    00368         virtual u32 getChangedID_Index() const {return ChangedID_Index;}
    00369
    00371         void boundingBoxNeedsRecalculated(void) { BoundingBoxNeedsRecalculated = true; }
    00372
    00373         core::array<video::S3DVertexTangents> Vertices_Tangents;
    00374         core::array<video::S3DVertex2TCoords> Vertices_2TCoords;
    00375         core::array<video::S3DVertex> Vertices_Standard;
    00376         core::array<u16> Indices;
    00377
    00378         u32 ChangedID_Vertex;
    00379         u32 ChangedID_Index;
    00380
    00381         //ISkinnedMesh::SJoint *AttachedJoint;
    00382         core::matrix4 Transformation;
    00383
    00384         video::SMaterial Material;
    00385         video::E_VERTEX_TYPE VertexType;
    00386
    00387         core::aabbox3d<f32> BoundingBox;
    00388
    00389         // hardware mapping hint
    00390         E_HARDWARE_MAPPING MappingHint_Vertex:3;
    00391         E_HARDWARE_MAPPING MappingHint_Index:3;
    00392
    00393         bool BoundingBoxNeedsRecalculated:1;
    00394 };
    00395
    00396
    00397 } // end namespace scene
    00398 } // end namespace irr
    00399
    00400 #endif
    00401

| The Irrlicht Engine Documentation © 2003-2009 by Nikolaus Gebhardt. Generated on Sun Jan 10 09:24:05 2010 by Doxygen (1.5.6)