1 | /** |
---|
2 | * This source file is part of OgreColladaPlugin |
---|
3 | * an addon for OGRE (Object-oriented Graphics Rendering Engine) |
---|
4 | * For the latest info, see http://www.ogre3d.org/ |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify it under |
---|
7 | * the terms of the GNU Lesser General Public License as published by the Free Software |
---|
8 | * Foundation; either version 2 of the License, or (at your option) any later |
---|
9 | * version. |
---|
10 | |
---|
11 | * This program is distributed in the hope that it will be useful, but WITHOUT |
---|
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
13 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
14 | |
---|
15 | * You should have received a copy of the GNU Lesser General Public License along with |
---|
16 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
17 | * Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
18 | * http://www.gnu.org/copyleft/lesser.txt. |
---|
19 | * |
---|
20 | * @author Philipp Hartl |
---|
21 | * @see README |
---|
22 | */ |
---|
23 | |
---|
24 | #ifndef __COLLADA_GEOMETRY_H__ |
---|
25 | #define __COLLADA_GEOMETRY_H__ |
---|
26 | |
---|
27 | #include "OgreColladaPrerequisites.h" |
---|
28 | #include "OgreColladaEntity.h" |
---|
29 | |
---|
30 | namespace Ogre |
---|
31 | { |
---|
32 | struct ColladaGeometryPolygon; |
---|
33 | struct ColladaGeometryInputData; |
---|
34 | struct ColladaGeometrySource; |
---|
35 | struct ColladaGeometryOgreMesh; |
---|
36 | struct ColladaGeometryIndexData; |
---|
37 | |
---|
38 | typedef std::vector<ColladaGeometryPolygon *> ColladaGeometryPolygonPtrVector; |
---|
39 | typedef std::vector<ColladaGeometryInputData *> ColladaGeometryInputDataPtrVector; |
---|
40 | typedef std::vector<ColladaGeometrySource *> ColladaGeometrySourcePtrVector; |
---|
41 | typedef std::vector<ColladaGeometryIndexData *> ColladaGeometryOgreMeshIndexData; |
---|
42 | |
---|
43 | namespace ColladaGeometrySpecific |
---|
44 | { |
---|
45 | /** |
---|
46 | * <input semantic="..."> |
---|
47 | */ |
---|
48 | enum Semantic |
---|
49 | { |
---|
50 | POSITION = 0, |
---|
51 | VERTEX, |
---|
52 | NORMAL, |
---|
53 | TEXCOORD, |
---|
54 | COLOR, |
---|
55 | UV, |
---|
56 | |
---|
57 | UNKNOWN = -1 |
---|
58 | }; |
---|
59 | |
---|
60 | /** |
---|
61 | * compare the string with collada syntax |
---|
62 | * |
---|
63 | * @param s the semantic string we have |
---|
64 | * @return the corresponding semantic type |
---|
65 | */ |
---|
66 | Semantic getSemantic(const String &s); |
---|
67 | } |
---|
68 | |
---|
69 | /** |
---|
70 | * a geometry object |
---|
71 | * holds information about: collada <geometry> node |
---|
72 | * id, name, vertices, polygons, ... |
---|
73 | */ |
---|
74 | class ColladaGeometry : public ColladaEntity |
---|
75 | { |
---|
76 | public: |
---|
77 | ColladaGeometry(ColladaDocument *doc, xmlNode *n); |
---|
78 | virtual ~ColladaGeometry(void); |
---|
79 | |
---|
80 | // ogre instance |
---|
81 | virtual MovableObject *getOgreInstance(void) const; |
---|
82 | |
---|
83 | /** |
---|
84 | * import <geometry> node |
---|
85 | * |
---|
86 | * @see base class |
---|
87 | */ |
---|
88 | virtual bool doImport(void); |
---|
89 | |
---|
90 | virtual EntityTypes getEntityType(void) const { return GEOMETRY; } |
---|
91 | |
---|
92 | /** |
---|
93 | * reset the bounding box for the manually created mesh |
---|
94 | * iff b != NULL |
---|
95 | * |
---|
96 | * @param b the boundingbox from the collada scene node, see ColladaScene |
---|
97 | * @return void |
---|
98 | */ |
---|
99 | void setBoundingBox(ColladaBoundingBox *b); |
---|
100 | |
---|
101 | /** |
---|
102 | * the name of an entity in a scene graph should be unique |
---|
103 | * (e.g. there could be more than one geometry instance with the same MeshPtr reference) |
---|
104 | * this function should be called before ogre instantiation |
---|
105 | * |
---|
106 | * @param s the unique name of the entity |
---|
107 | * @return void |
---|
108 | */ |
---|
109 | void setEntityName(const String &s) { mEntityName = s; } |
---|
110 | |
---|
111 | private: |
---|
112 | // the primitives render operation type |
---|
113 | enum RenderType { POLYGONS, TRIANGLES }; |
---|
114 | |
---|
115 | ColladaGeometryPolygonPtrVector mPolygons; |
---|
116 | ColladaGeometrySourcePtrVector mSources; |
---|
117 | ColladaGeometryInputDataPtrVector mVertexInputs; |
---|
118 | RenderType mType; |
---|
119 | String mEntityName; // this name must be unique in the scene graph |
---|
120 | ColladaBoundingBox *mBB; |
---|
121 | bool mBBReset; // if AABB was resetted by collada scene node |
---|
122 | |
---|
123 | ColladaGeometryOgreMesh *mOgreMesh; |
---|
124 | |
---|
125 | /** |
---|
126 | * calculate AABB from imported vertex data |
---|
127 | * the triangulated ogremesh could be greater than the vertices from collada |
---|
128 | * |
---|
129 | * @param none |
---|
130 | * @return none |
---|
131 | */ |
---|
132 | void calcBoundingBox(void); |
---|
133 | |
---|
134 | /** |
---|
135 | * create and load an ogre mesh instance |
---|
136 | * |
---|
137 | * @param none |
---|
138 | * @return void |
---|
139 | */ |
---|
140 | void createOgreMesh(void) const; |
---|
141 | |
---|
142 | /** |
---|
143 | * convert all vertex and index data from collada |
---|
144 | * primitves into ogre triangle list |
---|
145 | * currently only <polygons> and <triangles> primitives are supported |
---|
146 | * |
---|
147 | * @param void |
---|
148 | * @return void |
---|
149 | */ |
---|
150 | void createTriangleList(void); |
---|
151 | |
---|
152 | /** |
---|
153 | * import extra information of geometry |
---|
154 | * |
---|
155 | * @param node <extra> node |
---|
156 | * @return void |
---|
157 | */ |
---|
158 | void importExtra(xmlNode *extraNode); |
---|
159 | |
---|
160 | /** |
---|
161 | * import all geometry data |
---|
162 | * including vertices, normals, texcoords, indices, ... |
---|
163 | * currently only polygons are implemented |
---|
164 | * |
---|
165 | * @param node <mesh> node |
---|
166 | * @return true if all sub-imports succeeds |
---|
167 | */ |
---|
168 | bool importMesh(xmlNode *meshNode); |
---|
169 | |
---|
170 | /** |
---|
171 | * look for <polygons> or <triangles> nodes |
---|
172 | * dependent on param primitive |
---|
173 | * fill up the mInputPolygonsDataList |
---|
174 | * |
---|
175 | * @param meshNode <mesh> node |
---|
176 | * @param primitive polygons or triangles |
---|
177 | * @return true if <polygons> imported |
---|
178 | */ |
---|
179 | bool importPolygonsNodes(xmlNode *meshNode, const String &primitive); |
---|
180 | |
---|
181 | /** |
---|
182 | * import <source> nodes (vertices, normals, texcoords, ...) |
---|
183 | * |
---|
184 | * @param sourceNode <source> node to load |
---|
185 | * @return a pointer at loaded source record, NULL otherwise |
---|
186 | */ |
---|
187 | ColladaGeometrySource *importSourceNode(xmlNode *sourceNode); |
---|
188 | |
---|
189 | /** |
---|
190 | * look for <vertices> node |
---|
191 | * fill up mVertexInputs |
---|
192 | * |
---|
193 | * @param meshNode <mesh> node |
---|
194 | * @return true if <vertices> imported |
---|
195 | */ |
---|
196 | bool importVerticesNode(xmlNode *meshNode); |
---|
197 | |
---|
198 | /** |
---|
199 | * only for debugging purpose |
---|
200 | * to see the values |
---|
201 | */ |
---|
202 | void printIndices(void); |
---|
203 | void printVertices(const unsigned short x); |
---|
204 | }; |
---|
205 | |
---|
206 | /** |
---|
207 | * holds <input semantic="" source="" idx="" /> data |
---|
208 | * if <input> child of <vertices> then idx and indices are not used |
---|
209 | */ |
---|
210 | struct ColladaGeometryInputData |
---|
211 | { |
---|
212 | uint idx; // unique index, used for indices offset |
---|
213 | intVector indices; // indices (vertex, normal, texcoord, ...) |
---|
214 | ColladaGeometrySource *source; // pointer at source record, accessed by indices, for VERTEX it is NULL |
---|
215 | ColladaGeometrySpecific::Semantic semantic; // semantic type |
---|
216 | }; |
---|
217 | |
---|
218 | /** |
---|
219 | * holds <polygons> data |
---|
220 | */ |
---|
221 | struct ColladaGeometryPolygon |
---|
222 | { |
---|
223 | bool setMaterial; // can material be attached? |
---|
224 | ColladaMaterial *material; // a ColladaMaterial pointer, with assigned name |
---|
225 | uint primitiveCount; // the total amount of polygon primitives |
---|
226 | uint vertexCount; // the number of vertices used by a polygon primitive |
---|
227 | uint inputCount; // the total amount of inputs |
---|
228 | ColladaGeometryInputDataPtrVector inputs; // a vector with polygon <input> |
---|
229 | }; |
---|
230 | |
---|
231 | /** |
---|
232 | * holds <source> data |
---|
233 | */ |
---|
234 | struct ColladaGeometrySource |
---|
235 | { |
---|
236 | String id; // the source identifier |
---|
237 | uint count; // the number of times the array is accessed |
---|
238 | uint stride; // the number of values to access per count iteration |
---|
239 | floatVector data; // the floating data vector |
---|
240 | }; |
---|
241 | |
---|
242 | /** |
---|
243 | * indices and material properties |
---|
244 | * needed by ColladaGeometryOgreMesh |
---|
245 | */ |
---|
246 | struct ColladaGeometryIndexData |
---|
247 | { |
---|
248 | String material; |
---|
249 | uint count; |
---|
250 | unsigned short *indices; |
---|
251 | }; |
---|
252 | |
---|
253 | /** |
---|
254 | * optimized ogre mesh data for hardware buffers |
---|
255 | * there is only one meshdata, but there could be more index data, mutlimaterial e.g. |
---|
256 | */ |
---|
257 | struct ColladaGeometryOgreMesh |
---|
258 | { |
---|
259 | bool drawNormals, drawTexCoords; |
---|
260 | uint vertexCount; // the number of vertices |
---|
261 | float *vertices; // vertices, [normals], [texcoords] |
---|
262 | ColladaGeometryOgreMeshIndexData indices; |
---|
263 | }; |
---|
264 | } |
---|
265 | |
---|
266 | #endif // __COLLADA_GEOMETRY_H__ |
---|