1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #ifndef __I_SKIN_MESH_BUFFER_H_INCLUDED__
\r
6 #define __I_SKIN_MESH_BUFFER_H_INCLUDED__
\r
8 #include "IMeshBuffer.h"
\r
9 #include "S3DVertex.h"
\r
18 //! A mesh buffer able to choose between S3DVertex2TCoords, S3DVertex and S3DVertexTangents at runtime
\r
19 struct SSkinMeshBuffer : public IMeshBuffer
\r
21 //! Default constructor
\r
22 SSkinMeshBuffer(video::E_VERTEX_TYPE vt=video::EVT_STANDARD) :
\r
23 ChangedID_Vertex(1), ChangedID_Index(1), VertexType(vt),
\r
24 PrimitiveType(EPT_TRIANGLES),
\r
25 MappingHint_Vertex(EHM_NEVER), MappingHint_Index(EHM_NEVER),
\r
26 BoundingBoxNeedsRecalculated(true)
\r
29 setDebugName("SSkinMeshBuffer");
\r
33 //! Get Material of this buffer.
\r
34 virtual const video::SMaterial& getMaterial() const _IRR_OVERRIDE_
\r
39 //! Get Material of this buffer.
\r
40 virtual video::SMaterial& getMaterial() _IRR_OVERRIDE_
\r
45 //! Get standard vertex at given index
\r
46 virtual video::S3DVertex *getVertex(u32 index)
\r
50 case video::EVT_2TCOORDS:
\r
51 return (video::S3DVertex*)&Vertices_2TCoords[index];
\r
52 case video::EVT_TANGENTS:
\r
53 return (video::S3DVertex*)&Vertices_Tangents[index];
\r
55 return &Vertices_Standard[index];
\r
59 //! Get pointer to vertex array
\r
60 virtual const void* getVertices() const _IRR_OVERRIDE_
\r
64 case video::EVT_2TCOORDS:
\r
65 return Vertices_2TCoords.const_pointer();
\r
66 case video::EVT_TANGENTS:
\r
67 return Vertices_Tangents.const_pointer();
\r
69 return Vertices_Standard.const_pointer();
\r
73 //! Get pointer to vertex array
\r
74 virtual void* getVertices() _IRR_OVERRIDE_
\r
78 case video::EVT_2TCOORDS:
\r
79 return Vertices_2TCoords.pointer();
\r
80 case video::EVT_TANGENTS:
\r
81 return Vertices_Tangents.pointer();
\r
83 return Vertices_Standard.pointer();
\r
87 //! Get vertex count
\r
88 virtual u32 getVertexCount() const _IRR_OVERRIDE_
\r
92 case video::EVT_2TCOORDS:
\r
93 return Vertices_2TCoords.size();
\r
94 case video::EVT_TANGENTS:
\r
95 return Vertices_Tangents.size();
\r
97 return Vertices_Standard.size();
\r
101 //! Get type of index data which is stored in this meshbuffer.
\r
102 /** \return Index type of this buffer. */
\r
103 virtual video::E_INDEX_TYPE getIndexType() const _IRR_OVERRIDE_
\r
105 return video::EIT_16BIT;
\r
108 //! Get pointer to index array
\r
109 virtual const u16* getIndices() const _IRR_OVERRIDE_
\r
111 return Indices.const_pointer();
\r
114 //! Get pointer to index array
\r
115 virtual u16* getIndices() _IRR_OVERRIDE_
\r
117 return Indices.pointer();
\r
120 //! Get index count
\r
121 virtual u32 getIndexCount() const _IRR_OVERRIDE_
\r
123 return Indices.size();
\r
126 //! Get bounding box
\r
127 virtual const core::aabbox3d<f32>& getBoundingBox() const _IRR_OVERRIDE_
\r
129 return BoundingBox;
\r
132 //! Set bounding box
\r
133 virtual void setBoundingBox( const core::aabbox3df& box) _IRR_OVERRIDE_
\r
138 //! Recalculate bounding box
\r
139 virtual void recalculateBoundingBox() _IRR_OVERRIDE_
\r
141 if(!BoundingBoxNeedsRecalculated)
\r
144 BoundingBoxNeedsRecalculated = false;
\r
146 switch (VertexType)
\r
148 case video::EVT_STANDARD:
\r
150 if (Vertices_Standard.empty())
\r
151 BoundingBox.reset(0,0,0);
\r
154 BoundingBox.reset(Vertices_Standard[0].Pos);
\r
155 for (u32 i=1; i<Vertices_Standard.size(); ++i)
\r
156 BoundingBox.addInternalPoint(Vertices_Standard[i].Pos);
\r
160 case video::EVT_2TCOORDS:
\r
162 if (Vertices_2TCoords.empty())
\r
163 BoundingBox.reset(0,0,0);
\r
166 BoundingBox.reset(Vertices_2TCoords[0].Pos);
\r
167 for (u32 i=1; i<Vertices_2TCoords.size(); ++i)
\r
168 BoundingBox.addInternalPoint(Vertices_2TCoords[i].Pos);
\r
172 case video::EVT_TANGENTS:
\r
174 if (Vertices_Tangents.empty())
\r
175 BoundingBox.reset(0,0,0);
\r
178 BoundingBox.reset(Vertices_Tangents[0].Pos);
\r
179 for (u32 i=1; i<Vertices_Tangents.size(); ++i)
\r
180 BoundingBox.addInternalPoint(Vertices_Tangents[i].Pos);
\r
187 //! Get vertex type
\r
188 virtual video::E_VERTEX_TYPE getVertexType() const _IRR_OVERRIDE_
\r
193 //! Convert to 2tcoords vertex type
\r
194 void convertTo2TCoords()
\r
196 if (VertexType==video::EVT_STANDARD)
\r
198 for(u32 n=0;n<Vertices_Standard.size();++n)
\r
200 video::S3DVertex2TCoords Vertex;
\r
201 Vertex.Color=Vertices_Standard[n].Color;
\r
202 Vertex.Pos=Vertices_Standard[n].Pos;
\r
203 Vertex.Normal=Vertices_Standard[n].Normal;
\r
204 Vertex.TCoords=Vertices_Standard[n].TCoords;
\r
205 Vertices_2TCoords.push_back(Vertex);
\r
207 Vertices_Standard.clear();
\r
208 VertexType=video::EVT_2TCOORDS;
\r
212 //! Convert to tangents vertex type
\r
213 void convertToTangents()
\r
215 if (VertexType==video::EVT_STANDARD)
\r
217 for(u32 n=0;n<Vertices_Standard.size();++n)
\r
219 video::S3DVertexTangents Vertex;
\r
220 Vertex.Color=Vertices_Standard[n].Color;
\r
221 Vertex.Pos=Vertices_Standard[n].Pos;
\r
222 Vertex.Normal=Vertices_Standard[n].Normal;
\r
223 Vertex.TCoords=Vertices_Standard[n].TCoords;
\r
224 Vertices_Tangents.push_back(Vertex);
\r
226 Vertices_Standard.clear();
\r
227 VertexType=video::EVT_TANGENTS;
\r
229 else if (VertexType==video::EVT_2TCOORDS)
\r
231 for(u32 n=0;n<Vertices_2TCoords.size();++n)
\r
233 video::S3DVertexTangents Vertex;
\r
234 Vertex.Color=Vertices_2TCoords[n].Color;
\r
235 Vertex.Pos=Vertices_2TCoords[n].Pos;
\r
236 Vertex.Normal=Vertices_2TCoords[n].Normal;
\r
237 Vertex.TCoords=Vertices_2TCoords[n].TCoords;
\r
238 Vertices_Tangents.push_back(Vertex);
\r
240 Vertices_2TCoords.clear();
\r
241 VertexType=video::EVT_TANGENTS;
\r
245 //! returns position of vertex i
\r
246 virtual const core::vector3df& getPosition(u32 i) const _IRR_OVERRIDE_
\r
248 switch (VertexType)
\r
250 case video::EVT_2TCOORDS:
\r
251 return Vertices_2TCoords[i].Pos;
\r
252 case video::EVT_TANGENTS:
\r
253 return Vertices_Tangents[i].Pos;
\r
255 return Vertices_Standard[i].Pos;
\r
259 //! returns position of vertex i
\r
260 virtual core::vector3df& getPosition(u32 i) _IRR_OVERRIDE_
\r
262 switch (VertexType)
\r
264 case video::EVT_2TCOORDS:
\r
265 return Vertices_2TCoords[i].Pos;
\r
266 case video::EVT_TANGENTS:
\r
267 return Vertices_Tangents[i].Pos;
\r
269 return Vertices_Standard[i].Pos;
\r
273 //! returns normal of vertex i
\r
274 virtual const core::vector3df& getNormal(u32 i) const _IRR_OVERRIDE_
\r
276 switch (VertexType)
\r
278 case video::EVT_2TCOORDS:
\r
279 return Vertices_2TCoords[i].Normal;
\r
280 case video::EVT_TANGENTS:
\r
281 return Vertices_Tangents[i].Normal;
\r
283 return Vertices_Standard[i].Normal;
\r
287 //! returns normal of vertex i
\r
288 virtual core::vector3df& getNormal(u32 i) _IRR_OVERRIDE_
\r
290 switch (VertexType)
\r
292 case video::EVT_2TCOORDS:
\r
293 return Vertices_2TCoords[i].Normal;
\r
294 case video::EVT_TANGENTS:
\r
295 return Vertices_Tangents[i].Normal;
\r
297 return Vertices_Standard[i].Normal;
\r
301 //! returns texture coords of vertex i
\r
302 virtual const core::vector2df& getTCoords(u32 i) const _IRR_OVERRIDE_
\r
304 switch (VertexType)
\r
306 case video::EVT_2TCOORDS:
\r
307 return Vertices_2TCoords[i].TCoords;
\r
308 case video::EVT_TANGENTS:
\r
309 return Vertices_Tangents[i].TCoords;
\r
311 return Vertices_Standard[i].TCoords;
\r
315 //! returns texture coords of vertex i
\r
316 virtual core::vector2df& getTCoords(u32 i) _IRR_OVERRIDE_
\r
318 switch (VertexType)
\r
320 case video::EVT_2TCOORDS:
\r
321 return Vertices_2TCoords[i].TCoords;
\r
322 case video::EVT_TANGENTS:
\r
323 return Vertices_Tangents[i].TCoords;
\r
325 return Vertices_Standard[i].TCoords;
\r
329 //! append the vertices and indices to the current buffer
\r
330 virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) _IRR_OVERRIDE_ {}
\r
332 //! append the meshbuffer to the current buffer
\r
333 virtual void append(const IMeshBuffer* const other) _IRR_OVERRIDE_ {}
\r
335 //! get the current hardware mapping hint for vertex buffers
\r
336 virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const _IRR_OVERRIDE_
\r
338 return MappingHint_Vertex;
\r
341 //! get the current hardware mapping hint for index buffers
\r
342 virtual E_HARDWARE_MAPPING getHardwareMappingHint_Index() const _IRR_OVERRIDE_
\r
344 return MappingHint_Index;
\r
347 //! set the hardware mapping hint, for driver
\r
348 virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX ) _IRR_OVERRIDE_
\r
350 if (Buffer==EBT_VERTEX)
\r
351 MappingHint_Vertex=NewMappingHint;
\r
352 else if (Buffer==EBT_INDEX)
\r
353 MappingHint_Index=NewMappingHint;
\r
354 else if (Buffer==EBT_VERTEX_AND_INDEX)
\r
356 MappingHint_Vertex=NewMappingHint;
\r
357 MappingHint_Index=NewMappingHint;
\r
361 //! Describe what kind of primitive geometry is used by the meshbuffer
\r
362 virtual void setPrimitiveType(E_PRIMITIVE_TYPE type) _IRR_OVERRIDE_
\r
364 PrimitiveType = type;
\r
367 //! Get the kind of primitive geometry which is used by the meshbuffer
\r
368 virtual E_PRIMITIVE_TYPE getPrimitiveType() const _IRR_OVERRIDE_
\r
370 return PrimitiveType;
\r
373 //! flags the mesh as changed, reloads hardware buffers
\r
374 virtual void setDirty(E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX) _IRR_OVERRIDE_
\r
376 if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_VERTEX)
\r
377 ++ChangedID_Vertex;
\r
378 if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_INDEX)
\r
382 virtual u32 getChangedID_Vertex() const _IRR_OVERRIDE_ {return ChangedID_Vertex;}
\r
384 virtual u32 getChangedID_Index() const _IRR_OVERRIDE_ {return ChangedID_Index;}
\r
386 //! Call this after changing the positions of any vertex.
\r
387 void boundingBoxNeedsRecalculated(void) { BoundingBoxNeedsRecalculated = true; }
\r
389 core::array<video::S3DVertexTangents> Vertices_Tangents;
\r
390 core::array<video::S3DVertex2TCoords> Vertices_2TCoords;
\r
391 core::array<video::S3DVertex> Vertices_Standard;
\r
392 core::array<u16> Indices;
\r
394 u32 ChangedID_Vertex;
\r
395 u32 ChangedID_Index;
\r
397 //ISkinnedMesh::SJoint *AttachedJoint;
\r
398 core::matrix4 Transformation;
\r
400 video::SMaterial Material;
\r
401 video::E_VERTEX_TYPE VertexType;
\r
403 core::aabbox3d<f32> BoundingBox;
\r
405 //! Primitive type used for rendering (triangles, lines, ...)
\r
406 E_PRIMITIVE_TYPE PrimitiveType;
\r
408 // hardware mapping hint
\r
409 E_HARDWARE_MAPPING MappingHint_Vertex:3;
\r
410 E_HARDWARE_MAPPING MappingHint_Index:3;
\r
412 bool BoundingBoxNeedsRecalculated:1;
\r
416 } // end namespace scene
\r
417 } // end namespace irr
\r