Nirtcpp 2.1.0
Nirtcpp is a high-performance c++ graphics engine.
Loading...
Searching...
No Matches
SMesh.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_MESH_HPP_INCLUDED
6#define S_MESH_HPP_INCLUDED
7
8#include <nirtcpp/core/engine/IMesh.hpp>
9#include <nirtcpp/core/engine/IMeshBuffer.hpp>
10#include <nirtcpp/core/engine/aabbox3d.hpp>
11#include <nirtcpp/core/engine/irrArray.hpp>
12
13namespace nirt
14{
15namespace scene
16{
18 class SMesh : public IMesh
19 {
20 public:
23 {
24 #ifdef _DEBUG
25 setDebugName("SMesh");
26 #endif
27 }
28
29 public:
31 virtual ~SMesh()
32 {
33 // drop buffers
34 for (u32 i=0; i<MeshBuffers.size(); ++i)
35 MeshBuffers[i]->drop();
36 }
37
38 public:
40 virtual void clear()
41 {
42 for (u32 i=0; i<MeshBuffers.size(); ++i)
43 MeshBuffers[i]->drop();
44 MeshBuffers.clear();
45 BoundingBox.reset ( 0.f, 0.f, 0.f );
46 }
47
48
50 virtual u32 getMeshBufferCount() const override
51 {
52 return MeshBuffers.size();
53 }
54
56 virtual IMeshBuffer* getMeshBuffer(u32 nr) const override
57 {
58 return MeshBuffers[nr];
59 }
60
62
63 virtual IMeshBuffer* getMeshBuffer( const video::SMaterial & material) const override
64 {
65 for (s32 i = (s32)MeshBuffers.size()-1; i >= 0; --i)
66 {
67 if ( material == MeshBuffers[i]->getMaterial())
68 return MeshBuffers[i];
69 }
70
71 return 0;
72 }
73
75 virtual const core::aabbox3d<f32>& getBoundingBox() const override
76 {
77 return BoundingBox;
78 }
79
81 virtual void setBoundingBox( const core::aabbox3df& box) override
82 {
83 BoundingBox = box;
84 }
85
88 {
89 bool hasMeshBufferBBox = false;
90 for (u32 i=0; i<MeshBuffers.size(); ++i)
91 {
92 const core::aabbox3df& bb = MeshBuffers[i]->getBoundingBox();
93 if ( !bb.isEmpty() )
94 {
95 if ( !hasMeshBufferBBox )
96 {
97 hasMeshBufferBBox = true;
98 BoundingBox = bb;
99 }
100 else
101 {
103 }
104
105 }
106 }
107
108 if ( !hasMeshBufferBBox )
109 BoundingBox.reset(0.0f, 0.0f, 0.0f);
110 }
111
113
115 {
116 if (buf)
117 {
118 buf->grab();
119 MeshBuffers.push_back(buf);
120 }
121 }
122
124 virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue) override
125 {
126 for (u32 i=0; i<MeshBuffers.size(); ++i)
127 MeshBuffers[i]->getMaterial().setFlag(flag, newvalue);
128 }
129
131 virtual void setHardwareMappingHint( E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX ) override
132 {
133 for (u32 i=0; i<MeshBuffers.size(); ++i)
134 MeshBuffers[i]->setHardwareMappingHint(newMappingHint, buffer);
135 }
136
138 virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) override
139 {
140 for (u32 i=0; i<MeshBuffers.size(); ++i)
141 MeshBuffers[i]->setDirty(buffer);
142 }
143
144 public:
147
150 };
151
152} // end namespace scene
153} // end namespace nirt
154
155#endif
void setDebugName(const c8 *newName)
Sets the debug name of the object.
Definition IReferenceCounted.hpp:163
bool drop() const
Drops the object. Decrements the reference counter by one.
Definition IReferenceCounted.hpp:126
void grab() const
Grabs the object. Increments the reference counter by one.
Definition IReferenceCounted.hpp:96
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.hpp:22
bool isEmpty() const
Check if the box is empty.
Definition aabbox3d.hpp:129
void addInternalBox(const aabbox3d< T > &b)
Adds another bounding box.
Definition aabbox3d.hpp:82
void reset(T x, T y, T z)
Resets the bounding box to a one-point box.
Definition aabbox3d.hpp:50
Class for holding a mesh with a single material.
Definition IMeshBuffer.hpp:41
Class which holds the geometry of an object.
Definition IMesh.hpp:72
Simple implementation of the IMesh interface.
Definition SMesh.hpp:19
virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) override
flags the meshbuffer as changed, reloads hardware buffers
Definition SMesh.hpp:138
virtual const core::aabbox3d< f32 > & getBoundingBox() const override
returns an axis aligned bounding box
Definition SMesh.hpp:75
virtual IMeshBuffer * getMeshBuffer(u32 nr) const override
returns pointer to a mesh buffer
Definition SMesh.hpp:56
void addMeshBuffer(IMeshBuffer *buf)
adds a MeshBuffer
Definition SMesh.hpp:114
void recalculateBoundingBox()
recalculates the bounding box
Definition SMesh.hpp:87
SMesh()
constructor
Definition SMesh.hpp:22
virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue) override
sets a flag of all contained materials to a new value
Definition SMesh.hpp:124
virtual void clear()
clean mesh
Definition SMesh.hpp:40
virtual void setBoundingBox(const core::aabbox3df &box) override
set user axis aligned bounding box
Definition SMesh.hpp:81
virtual ~SMesh()
destructor
Definition SMesh.hpp:31
virtual void setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) override
set the hardware mapping hint, for driver
Definition SMesh.hpp:131
virtual u32 getMeshBufferCount() const override
returns amount of mesh buffers.
Definition SMesh.hpp:50
core::array< IMeshBuffer * > MeshBuffers
The meshbuffers of this mesh.
Definition SMesh.hpp:146
virtual IMeshBuffer * getMeshBuffer(const video::SMaterial &material) const override
returns a meshbuffer which fits a material
Definition SMesh.hpp:63
core::aabbox3d< f32 > BoundingBox
The bounding box of this mesh.
Definition SMesh.hpp:149
Class 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
E_HARDWARE_MAPPING
Definition EHardwareBufferFlags.hpp:14
E_MATERIAL_FLAG
Material flags.
Definition EMaterialFlags.hpp:15
As of Nirtcpp 1.6, position2d is a synonym for vector2d.
Definition vector3d.hpp:11
signed int s32
32 bit signed variable.
Definition irrTypes.hpp:72
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.hpp:64

Nirtcpp    @cppfx.xyz

Esvcpp    esv::print