~baltix/+junk/irrlicht-test

« back to all changes in this revision

Viewing changes to include/SAnimatedMesh.h

  • Committer: Mantas Kriaučiūnas
  • Date: 2011-07-18 13:06:25 UTC
  • Revision ID: mantas@akl.lt-20110718130625-c5pvifp61e7kj1ol
Included whole irrlicht SVN libraries to work around launchpad recipe issue with quilt, see https://answers.launchpad.net/launchpad/+question/165193

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
 
2
// This file is part of the "Irrlicht Engine".
 
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
 
4
 
 
5
#ifndef __S_ANIMATED_MESH_H_INCLUDED__
 
6
#define __S_ANIMATED_MESH_H_INCLUDED__
 
7
 
 
8
#include "IAnimatedMesh.h"
 
9
#include "IMesh.h"
 
10
#include "aabbox3d.h"
 
11
#include "irrArray.h"
 
12
 
 
13
namespace irr
 
14
{
 
15
namespace scene
 
16
{
 
17
 
 
18
        //! Simple implementation of the IAnimatedMesh interface.
 
19
        struct SAnimatedMesh : public IAnimatedMesh
 
20
        {
 
21
                //! constructor
 
22
                SAnimatedMesh(scene::IMesh* mesh=0, scene::E_ANIMATED_MESH_TYPE type=scene::EAMT_UNKNOWN) : IAnimatedMesh(), Type(type)
 
23
                {
 
24
                        #ifdef _DEBUG
 
25
                        setDebugName("SAnimatedMesh");
 
26
                        #endif
 
27
                        addMesh(mesh);
 
28
                        recalculateBoundingBox();
 
29
                }
 
30
 
 
31
 
 
32
                //! destructor
 
33
                virtual ~SAnimatedMesh()
 
34
                {
 
35
                        // drop meshes
 
36
                        for (u32 i=0; i<Meshes.size(); ++i)
 
37
                                Meshes[i]->drop();
 
38
                }
 
39
 
 
40
 
 
41
                //! Gets the frame count of the animated mesh.
 
42
                /** \return Amount of frames. If the amount is 1, it is a static, non animated mesh. */
 
43
                virtual u32 getFrameCount() const
 
44
                {
 
45
                        return Meshes.size();
 
46
                }
 
47
 
 
48
 
 
49
                //! Returns the IMesh interface for a frame.
 
50
                /** \param frame: Frame number as zero based index. The maximum frame number is
 
51
                getFrameCount() - 1;
 
52
                \param detailLevel: Level of detail. 0 is the lowest,
 
53
                255 the highest level of detail. Most meshes will ignore the detail level.
 
54
                \param startFrameLoop: start frame
 
55
                \param endFrameLoop: end frame
 
56
                \return The animated mesh based on a detail level. */
 
57
                virtual IMesh* getMesh(s32 frame, s32 detailLevel, s32 startFrameLoop=-1, s32 endFrameLoop=-1)
 
58
                {
 
59
                        if (Meshes.empty())
 
60
                                return 0;
 
61
 
 
62
                        return Meshes[frame];
 
63
                }
 
64
 
 
65
 
 
66
                //! adds a Mesh
 
67
                void addMesh(IMesh* mesh)
 
68
                {
 
69
                        if (mesh)
 
70
                        {
 
71
                                mesh->grab();
 
72
                                Meshes.push_back(mesh);
 
73
                        }
 
74
                }
 
75
 
 
76
 
 
77
                //! Returns an axis aligned bounding box of the mesh.
 
78
                /** \return A bounding box of this mesh is returned. */
 
79
                virtual const core::aabbox3d<f32>& getBoundingBox() const
 
80
                {
 
81
                        return Box;
 
82
                }
 
83
 
 
84
 
 
85
                //! set user axis aligned bounding box
 
86
                virtual void setBoundingBox(const core::aabbox3df& box)
 
87
                {
 
88
                        Box = box;
 
89
                }
 
90
 
 
91
                //! Recalculates the bounding box.
 
92
                void recalculateBoundingBox()
 
93
                {
 
94
                        Box.reset(0,0,0);
 
95
 
 
96
                        if (Meshes.empty())
 
97
                                return;
 
98
 
 
99
                        Box = Meshes[0]->getBoundingBox();
 
100
 
 
101
                        for (u32 i=1; i<Meshes.size(); ++i)
 
102
                                Box.addInternalBox(Meshes[i]->getBoundingBox());
 
103
                }
 
104
 
 
105
 
 
106
                //! Returns the type of the animated mesh.
 
107
                virtual E_ANIMATED_MESH_TYPE getMeshType() const
 
108
                {
 
109
                        return Type;
 
110
                }
 
111
 
 
112
 
 
113
                //! returns amount of mesh buffers.
 
114
                virtual u32 getMeshBufferCount() const
 
115
                {
 
116
                        if (Meshes.empty())
 
117
                                return 0;
 
118
 
 
119
                        return Meshes[0]->getMeshBufferCount();
 
120
                }
 
121
 
 
122
 
 
123
                //! returns pointer to a mesh buffer
 
124
                virtual IMeshBuffer* getMeshBuffer(u32 nr) const
 
125
                {
 
126
                        if (Meshes.empty())
 
127
                                return 0;
 
128
 
 
129
                        return Meshes[0]->getMeshBuffer(nr);
 
130
                }
 
131
 
 
132
 
 
133
                //! Returns pointer to a mesh buffer which fits a material
 
134
                /** \param material: material to search for
 
135
                \return Returns the pointer to the mesh buffer or
 
136
                NULL if there is no such mesh buffer. */
 
137
                virtual IMeshBuffer* getMeshBuffer( const video::SMaterial &material) const
 
138
                {
 
139
                        if (Meshes.empty())
 
140
                                return 0;
 
141
 
 
142
                        return Meshes[0]->getMeshBuffer(material);
 
143
                }
 
144
 
 
145
 
 
146
                //! Set a material flag for all meshbuffers of this mesh.
 
147
                virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
 
148
                {
 
149
                        for (u32 i=0; i<Meshes.size(); ++i)
 
150
                                Meshes[i]->setMaterialFlag(flag, newvalue);
 
151
                }
 
152
 
 
153
                //! set the hardware mapping hint, for driver
 
154
                virtual void setHardwareMappingHint( E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX )
 
155
                {
 
156
                        for (u32 i=0; i<Meshes.size(); ++i)
 
157
                                Meshes[i]->setHardwareMappingHint(newMappingHint, buffer);
 
158
                }
 
159
 
 
160
                //! flags the meshbuffer as changed, reloads hardware buffers
 
161
                virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX)
 
162
                {
 
163
                        for (u32 i=0; i<Meshes.size(); ++i)
 
164
                                Meshes[i]->setDirty(buffer);
 
165
                }
 
166
 
 
167
                //! All meshes defining the animated mesh
 
168
                core::array<IMesh*> Meshes;
 
169
 
 
170
                //! The bounding box of this mesh
 
171
                core::aabbox3d<f32> Box;
 
172
 
 
173
                //! Tyhe type fo the mesh.
 
174
                E_ANIMATED_MESH_TYPE Type;
 
175
        };
 
176
 
 
177
 
 
178
} // end namespace scene
 
179
} // end namespace irr
 
180
 
 
181
#endif
 
182