Nirtcpp 2.1.0
Nirtcpp is a high-performance c++ graphics engine.
Loading...
Searching...
No Matches
SSkinMeshBuffer.hpp
1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in nirtcpp/nirtcpp.hpp
4
5#ifndef S_SKIN_MESH_BUFFER_HPP_INCLUDED
6#define S_SKIN_MESH_BUFFER_HPP_INCLUDED
7
8#include <nirtcpp/core/engine/IMeshBuffer.hpp>
9#include <nirtcpp/core/engine/S3DVertex.hpp>
10
11
12namespace nirt
13{
14namespace scene
15{
16
17
20{
21public:
24 ChangedID_Vertex(1), ChangedID_Index(1), VertexType(vt),
26 MappingHint_Vertex(EHM_NEVER), MappingHint_Index(EHM_NEVER),
27 BoundingBoxNeedsRecalculated(true)
28 {
29 #ifdef _DEBUG
30 setDebugName("SSkinMeshBuffer");
31 #endif
32 }
33
35 virtual const video::SMaterial& getMaterial() const override
36 {
37 return Material;
38 }
39
41 virtual video::SMaterial& getMaterial() override
42 {
43 return Material;
44 }
45
48 {
49 switch (VertexType)
50 {
52 return (video::S3DVertex*)&Vertices_2TCoords[index];
54 return (video::S3DVertex*)&Vertices_Tangents[index];
55 default:
56 return &Vertices_Standard[index];
57 }
58 }
59
61 virtual const void* getVertices() const override
62 {
63 switch (VertexType)
64 {
66 return Vertices_2TCoords.const_pointer();
68 return Vertices_Tangents.const_pointer();
69 default:
70 return Vertices_Standard.const_pointer();
71 }
72 }
73
75 virtual void* getVertices() override
76 {
77 switch (VertexType)
78 {
80 return Vertices_2TCoords.pointer();
82 return Vertices_Tangents.pointer();
83 default:
84 return Vertices_Standard.pointer();
85 }
86 }
87
89 virtual u32 getVertexCount() const override
90 {
91 switch (VertexType)
92 {
94 return Vertices_2TCoords.size();
96 return Vertices_Tangents.size();
97 default:
98 return Vertices_Standard.size();
99 }
100 }
101
103
104 virtual video::E_INDEX_TYPE getIndexType() const override
105 {
106 return video::EIT_16BIT;
107 }
108
110 virtual const u16* getIndices() const override
111 {
112 return Indices.const_pointer();
113 }
114
116 virtual u16* getIndices() override
117 {
118 return Indices.pointer();
119 }
120
122 virtual u32 getIndexCount() const override
123 {
124 return Indices.size();
125 }
126
128 virtual const core::aabbox3d<f32>& getBoundingBox() const override
129 {
130 return BoundingBox;
131 }
132
134 virtual void setBoundingBox( const core::aabbox3df& box) override
135 {
136 BoundingBox = box;
137 }
138
140 virtual void recalculateBoundingBox() override
141 {
142 if(!BoundingBoxNeedsRecalculated)
143 return;
144
145 BoundingBoxNeedsRecalculated = false;
146
147 switch (VertexType)
148 {
150 {
151 if (Vertices_Standard.empty())
152 BoundingBox.reset(0,0,0);
153 else
154 {
155 BoundingBox.reset(Vertices_Standard[0].Pos);
156 for (u32 i=1; i<Vertices_Standard.size(); ++i)
157 BoundingBox.addInternalPoint(Vertices_Standard[i].Pos);
158 }
159 break;
160 }
162 {
163 if (Vertices_2TCoords.empty())
164 BoundingBox.reset(0,0,0);
165 else
166 {
167 BoundingBox.reset(Vertices_2TCoords[0].Pos);
168 for (u32 i=1; i<Vertices_2TCoords.size(); ++i)
169 BoundingBox.addInternalPoint(Vertices_2TCoords[i].Pos);
170 }
171 break;
172 }
174 {
175 if (Vertices_Tangents.empty())
176 BoundingBox.reset(0,0,0);
177 else
178 {
179 BoundingBox.reset(Vertices_Tangents[0].Pos);
180 for (u32 i=1; i<Vertices_Tangents.size(); ++i)
181 BoundingBox.addInternalPoint(Vertices_Tangents[i].Pos);
182 }
183 break;
184 }
185 }
186 }
187
189 virtual video::E_VERTEX_TYPE getVertexType() const override
190 {
191 return VertexType;
192 }
193
196 {
197 if (VertexType==video::EVT_STANDARD)
198 {
199 for(u32 n=0;n<Vertices_Standard.size();++n)
200 {
202 Vertex.Color=Vertices_Standard[n].Color;
203 Vertex.Pos=Vertices_Standard[n].Pos;
204 Vertex.Normal=Vertices_Standard[n].Normal;
205 Vertex.TCoords=Vertices_Standard[n].TCoords;
206 Vertices_2TCoords.push_back(Vertex);
207 }
208 Vertices_Standard.clear();
209 VertexType=video::EVT_2TCOORDS;
210 }
211 }
212
215 {
216 if (VertexType==video::EVT_STANDARD)
217 {
218 for(u32 n=0;n<Vertices_Standard.size();++n)
219 {
221 Vertex.Color=Vertices_Standard[n].Color;
222 Vertex.Pos=Vertices_Standard[n].Pos;
223 Vertex.Normal=Vertices_Standard[n].Normal;
224 Vertex.TCoords=Vertices_Standard[n].TCoords;
225 Vertices_Tangents.push_back(Vertex);
226 }
227 Vertices_Standard.clear();
228 VertexType=video::EVT_TANGENTS;
229 }
230 else if (VertexType==video::EVT_2TCOORDS)
231 {
232 for(u32 n=0;n<Vertices_2TCoords.size();++n)
233 {
235 Vertex.Color=Vertices_2TCoords[n].Color;
236 Vertex.Pos=Vertices_2TCoords[n].Pos;
237 Vertex.Normal=Vertices_2TCoords[n].Normal;
238 Vertex.TCoords=Vertices_2TCoords[n].TCoords;
239 Vertices_Tangents.push_back(Vertex);
240 }
241 Vertices_2TCoords.clear();
242 VertexType=video::EVT_TANGENTS;
243 }
244 }
245
247 virtual const core::vector3df& getPosition(u32 i) const override
248 {
249 switch (VertexType)
250 {
252 return Vertices_2TCoords[i].Pos;
254 return Vertices_Tangents[i].Pos;
255 default:
256 return Vertices_Standard[i].Pos;
257 }
258 }
259
261 virtual core::vector3df& getPosition(u32 i) override
262 {
263 switch (VertexType)
264 {
266 return Vertices_2TCoords[i].Pos;
268 return Vertices_Tangents[i].Pos;
269 default:
270 return Vertices_Standard[i].Pos;
271 }
272 }
273
275 virtual const core::vector3df& getNormal(u32 i) const override
276 {
277 switch (VertexType)
278 {
280 return Vertices_2TCoords[i].Normal;
282 return Vertices_Tangents[i].Normal;
283 default:
284 return Vertices_Standard[i].Normal;
285 }
286 }
287
289 virtual core::vector3df& getNormal(u32 i) override
290 {
291 switch (VertexType)
292 {
294 return Vertices_2TCoords[i].Normal;
296 return Vertices_Tangents[i].Normal;
297 default:
298 return Vertices_Standard[i].Normal;
299 }
300 }
301
303 virtual const core::vector2df& getTCoords(u32 i) const override
304 {
305 switch (VertexType)
306 {
308 return Vertices_2TCoords[i].TCoords;
310 return Vertices_Tangents[i].TCoords;
311 default:
312 return Vertices_Standard[i].TCoords;
313 }
314 }
315
317 virtual core::vector2df& getTCoords(u32 i) override
318 {
319 switch (VertexType)
320 {
322 return Vertices_2TCoords[i].TCoords;
324 return Vertices_Tangents[i].TCoords;
325 default:
326 return Vertices_Standard[i].TCoords;
327 }
328 }
329
331 virtual video::SColor& getColor(u32 i) override
332 {
333 switch (VertexType)
334 {
336 return Vertices_2TCoords[i].Color;
338 return Vertices_Tangents[i].Color;
339 default:
340 return Vertices_Standard[i].Color;
341 }
342 }
343
345 virtual const video::SColor& getColor(u32 i) const override
346 {
347 switch (VertexType)
348 {
350 return Vertices_2TCoords[i].Color;
352 return Vertices_Tangents[i].Color;
353 default:
354 return Vertices_Standard[i].Color;
355 }
356 }
357
359 virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) override {}
360
362 virtual void append(const IMeshBuffer* const other) override {}
363
366 {
367 return MappingHint_Vertex;
368 }
369
372 {
373 return MappingHint_Index;
374 }
375
377 virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX ) override
378 {
379 if (Buffer==EBT_VERTEX)
380 MappingHint_Vertex=NewMappingHint;
381 else if (Buffer==EBT_INDEX)
382 MappingHint_Index=NewMappingHint;
383 else if (Buffer==EBT_VERTEX_AND_INDEX)
384 {
385 MappingHint_Vertex=NewMappingHint;
386 MappingHint_Index=NewMappingHint;
387 }
388 }
389
391 virtual void setPrimitiveType(E_PRIMITIVE_TYPE type) override
392 {
393 PrimitiveType = type;
394 }
395
397 virtual E_PRIMITIVE_TYPE getPrimitiveType() const override
398 {
399 return PrimitiveType;
400 }
401
403 virtual void setDirty(E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX) override
404 {
405 if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_VERTEX)
406 ++ChangedID_Vertex;
407 if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_INDEX)
408 ++ChangedID_Index;
409 }
410
411 virtual u32 getChangedID_Vertex() const override {return ChangedID_Vertex;}
412
413 virtual u32 getChangedID_Index() const override {return ChangedID_Index;}
414
416 virtual EMESH_BUFFER_TYPE getType() const override
417 {
418 return EMBT_SKIN;
419 }
420
422 virtual IMeshBuffer* createClone(int cloneFlags) const override
423 {
424 SSkinMeshBuffer* clone = new SSkinMeshBuffer(VertexType);
425
426 if (cloneFlags & ECF_VERTICES)
427 {
428 clone->Vertices_Tangents = Vertices_Tangents;
429 clone->Vertices_2TCoords = Vertices_2TCoords;
430 clone->Vertices_Standard = Vertices_Standard;
431
432 clone->BoundingBox = BoundingBox;
433 clone->BoundingBoxNeedsRecalculated = BoundingBoxNeedsRecalculated;
434 }
435
436 if (cloneFlags & ECF_INDICES)
437 {
438 clone->Indices = Indices;
439 }
440
441 clone->Transformation = Transformation;
442 clone->Material = getMaterial();
444 clone->MappingHint_Vertex = MappingHint_Vertex;
445 clone->MappingHint_Index = MappingHint_Index;
446
447 return clone;
448 }
449
451 void boundingBoxNeedsRecalculated(void) { BoundingBoxNeedsRecalculated = true; }
452
455 core::array<video::S3DVertex> Vertices_Standard;
456 core::array<u16> Indices;
457
458 u32 ChangedID_Vertex;
459 u32 ChangedID_Index;
460
461 //ISkinnedMesh::SJoint *AttachedJoint;
462 core::matrix4 Transformation;
463
464 video::SMaterial Material;
465 video::E_VERTEX_TYPE VertexType;
466
467 core::aabbox3d<f32> BoundingBox;
468
471
472 // hardware mapping hint
473 E_HARDWARE_MAPPING MappingHint_Vertex:3;
474 E_HARDWARE_MAPPING MappingHint_Index:3;
475
476 bool BoundingBoxNeedsRecalculated:1;
477};
478
479
480} // end namespace scene
481} // end namespace nirt
482
483#endif
void setDebugName(const c8 *newName)
Sets the debug name of the object.
Definition IReferenceCounted.hpp:163
4x4 matrix. Mostly used as transformation matrix for 3d calculations.
Definition matrix4.hpp:49
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.hpp:22
void addInternalPoint(const vector3d< T > &p)
Adds a point to the bounding box.
Definition aabbox3d.hpp:74
void reset(T x, T y, T z)
Resets the bounding box to a one-point box.
Definition aabbox3d.hpp:50
u32 size() const
Get number of occupied elements of the array.
Definition irrArray.hpp:397
const T * const_pointer() const
Gets a const pointer to the array.
Definition irrArray.hpp:389
T * pointer()
Gets a pointer to the array.
Definition irrArray.hpp:381
Struct for holding a mesh with a single material.
Definition IMeshBuffer.hpp:41
@ ECF_INDICES
clone the vertices (or copy pointer for SSharedMeshBuffer)
Definition IMeshBuffer.hpp:205
A mesh buffer able to choose between S3DVertex2TCoords, S3DVertex and S3DVertexTangents at runtime.
Definition SSkinMeshBuffer.hpp:20
virtual video::E_INDEX_TYPE getIndexType() const override
Get type of index data which is stored in this meshbuffer.
Definition SSkinMeshBuffer.hpp:104
virtual const core::vector2df & getTCoords(u32 i) const override
returns texture coords of vertex i
Definition SSkinMeshBuffer.hpp:303
SSkinMeshBuffer(video::E_VERTEX_TYPE vt=video::EVT_STANDARD)
Default constructor.
Definition SSkinMeshBuffer.hpp:23
virtual u16 * getIndices() override
Get pointer to index array.
Definition SSkinMeshBuffer.hpp:116
void boundingBoxNeedsRecalculated(void)
Call this after changing the positions of any vertex.
Definition SSkinMeshBuffer.hpp:451
E_PRIMITIVE_TYPE PrimitiveType
Primitive type used for rendering (triangles, lines, ...)
Definition SSkinMeshBuffer.hpp:470
virtual video::SColor & getColor(u32 i) override
returns color of vertex i
Definition SSkinMeshBuffer.hpp:331
void convertToTangents()
Convert to tangents vertex type.
Definition SSkinMeshBuffer.hpp:214
virtual u32 getIndexCount() const override
Get index count.
Definition SSkinMeshBuffer.hpp:122
virtual EMESH_BUFFER_TYPE getType() const override
Returns type of the class implementing the IMeshBuffer.
Definition SSkinMeshBuffer.hpp:416
virtual void append(const IMeshBuffer *const other) override
append the meshbuffer to the current buffer
Definition SSkinMeshBuffer.hpp:362
virtual void setHardwareMappingHint(E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX) override
set the hardware mapping hint, for driver
Definition SSkinMeshBuffer.hpp:377
virtual void recalculateBoundingBox() override
Recalculate bounding box.
Definition SSkinMeshBuffer.hpp:140
virtual u32 getChangedID_Vertex() const override
Get the currently used ID for identification of changes.
Definition SSkinMeshBuffer.hpp:411
virtual u32 getChangedID_Index() const override
Get the currently used ID for identification of changes.
Definition SSkinMeshBuffer.hpp:413
virtual IMeshBuffer * createClone(int cloneFlags) const override
Create copy of the meshbuffer.
Definition SSkinMeshBuffer.hpp:422
virtual void append(const void *const vertices, u32 numVertices, const u16 *const indices, u32 numIndices) override
append the vertices and indices to the current buffer
Definition SSkinMeshBuffer.hpp:359
virtual void setBoundingBox(const core::aabbox3df &box) override
Set bounding box.
Definition SSkinMeshBuffer.hpp:134
virtual core::vector3df & getNormal(u32 i) override
returns normal of vertex i
Definition SSkinMeshBuffer.hpp:289
virtual u32 getVertexCount() const override
Get vertex count.
Definition SSkinMeshBuffer.hpp:89
virtual void * getVertices() override
Get pointer to vertex array.
Definition SSkinMeshBuffer.hpp:75
virtual const core::vector3df & getNormal(u32 i) const override
returns normal of vertex i
Definition SSkinMeshBuffer.hpp:275
virtual const video::SMaterial & getMaterial() const override
Get Material of this buffer.
Definition SSkinMeshBuffer.hpp:35
void convertTo2TCoords()
Convert to 2tcoords vertex type.
Definition SSkinMeshBuffer.hpp:195
virtual const core::aabbox3d< f32 > & getBoundingBox() const override
Get bounding box.
Definition SSkinMeshBuffer.hpp:128
virtual const video::SColor & getColor(u32 i) const override
returns color of vertex i
Definition SSkinMeshBuffer.hpp:345
virtual core::vector3df & getPosition(u32 i) override
returns position of vertex i
Definition SSkinMeshBuffer.hpp:261
virtual video::S3DVertex * getVertex(u32 index)
Get standard vertex at given index.
Definition SSkinMeshBuffer.hpp:47
virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const override
get the current hardware mapping hint for vertex buffers
Definition SSkinMeshBuffer.hpp:365
virtual E_PRIMITIVE_TYPE getPrimitiveType() const override
Get the kind of primitive geometry which is used by the meshbuffer.
Definition SSkinMeshBuffer.hpp:397
virtual const core::vector3df & getPosition(u32 i) const override
returns position of vertex i
Definition SSkinMeshBuffer.hpp:247
virtual video::SMaterial & getMaterial() override
Get Material of this buffer.
Definition SSkinMeshBuffer.hpp:41
virtual const u16 * getIndices() const override
Get pointer to index array.
Definition SSkinMeshBuffer.hpp:110
virtual const void * getVertices() const override
Get pointer to vertex array.
Definition SSkinMeshBuffer.hpp:61
virtual video::E_VERTEX_TYPE getVertexType() const override
Get vertex type.
Definition SSkinMeshBuffer.hpp:189
virtual E_HARDWARE_MAPPING getHardwareMappingHint_Index() const override
get the current hardware mapping hint for index buffers
Definition SSkinMeshBuffer.hpp:371
virtual core::vector2df & getTCoords(u32 i) override
returns texture coords of vertex i
Definition SSkinMeshBuffer.hpp:317
virtual void setDirty(E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX) override
flags the mesh as changed, reloads hardware buffers
Definition SSkinMeshBuffer.hpp:403
virtual void setPrimitiveType(E_PRIMITIVE_TYPE type) override
Describe what kind of primitive geometry is used by the meshbuffer.
Definition SSkinMeshBuffer.hpp:391
Vertex with two texture coordinates.
Definition S3DVertex.hpp:116
Vertex with a tangent and binormal vector.
Definition S3DVertex.hpp:199
standard vertex used by the Nirtcpp engine.
Definition S3DVertex.hpp:45
core::vector3df Normal
Normal vector.
Definition S3DVertex.hpp:64
SColor Color
Color.
Definition S3DVertex.hpp:67
core::vector2d< f32 > TCoords
Texture coordinates.
Definition S3DVertex.hpp:70
core::vector3df Pos
Position.
Definition S3DVertex.hpp:61
Class representing a 32 bit ARGB color.
Definition SColor.hpp:317
Struct for holding parameters for a material renderer.
Definition SMaterial.hpp:304
E_BUFFER_TYPE
Definition EHardwareBufferFlags.hpp:29
@ EBT_VERTEX_AND_INDEX
Change both vertex and index mapping to the same value.
Definition EHardwareBufferFlags.hpp:37
@ EBT_INDEX
Change the index mapping.
Definition EHardwareBufferFlags.hpp:35
@ EBT_VERTEX
Change the vertex mapping.
Definition EHardwareBufferFlags.hpp:33
E_PRIMITIVE_TYPE
Enumeration for all primitive types there are.
Definition EPrimitiveTypes.hpp:15
@ EPT_TRIANGLES
Explicitly set all vertices for each triangle.
Definition EPrimitiveTypes.hpp:37
E_HARDWARE_MAPPING
Definition EHardwareBufferFlags.hpp:14
@ EHM_NEVER
Don't store on the hardware.
Definition EHardwareBufferFlags.hpp:16
EMESH_BUFFER_TYPE
An enumeration for all types of built-in mesh buffers.
Definition EMeshBufferTypes.hpp:18
E_VERTEX_TYPE
Enumeration for all vertex types there are.
Definition S3DVertex.hpp:19
@ EVT_2TCOORDS
Vertex with two texture coordinates, video::S3DVertex2TCoords.
Definition S3DVertex.hpp:25
@ EVT_STANDARD
Standard vertex type used by the Nirtcpp engine, video::S3DVertex.
Definition S3DVertex.hpp:21
@ EVT_TANGENTS
Vertex with a tangent and binormal vector, video::S3DVertexTangents.
Definition S3DVertex.hpp:31
As of Nirtcpp 1.6, position2d is a synonym for vector2d.
Definition vector3d.hpp:11
unsigned short u16
16 bit unsigned variable.
Definition irrTypes.hpp:46
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.hpp:64

Nirtcpp    @cppfx.xyz

Utxcpp    utx::print