1 | /*
|
---|
2 | Copyright (C) 2005-2006 Feeling Software Inc.
|
---|
3 | MIT License: http://www.opensource.org/licenses/mit-license.php
|
---|
4 | */
|
---|
5 | /*
|
---|
6 | Based on the FS Import classes:
|
---|
7 | Copyright (C) 2005-2006 Feeling Software Inc
|
---|
8 | Copyright (C) 2005-2006 Autodesk Media Entertainment
|
---|
9 | MIT License: http://www.opensource.org/licenses/mit-license.php
|
---|
10 | */
|
---|
11 |
|
---|
12 | /**
|
---|
13 | @file FCDGeometryPolygons.h
|
---|
14 | This file defines the FCDGeometryPolygons and the FCDGeometryPolygonsInput classes.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #ifndef _FCD_GEOMETRY_POLYGONS_H_
|
---|
18 | #define _FCD_GEOMETRY_POLYGONS_H_
|
---|
19 |
|
---|
20 | #include "FCDocument/FCDObject.h"
|
---|
21 | #include "FUtils/FUDaeEnum.h"
|
---|
22 |
|
---|
23 | class FCDocument;
|
---|
24 | class FRMeshPolygons;
|
---|
25 | class FCDMaterial;
|
---|
26 | class FCDGeometryMesh;
|
---|
27 | class FCDGeometrySource;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | An input data source for one mesh polygons set.
|
---|
31 | This structure knows the type of input data in the data source
|
---|
32 | as well as the set and offset for the data. It also contains a
|
---|
33 | pointer to the mesh data source.
|
---|
34 |
|
---|
35 | Many polygon set inputs may have the same offset (or 'idx') when multiple
|
---|
36 | data sources are compressed together within the COLLADA document.
|
---|
37 | In this case, one and only one of the polygon set input will have
|
---|
38 | the 'ownsIdx' flag set. A polygon set input with this flag set will
|
---|
39 | contain valid indices. To find the indices of any polygon set input,
|
---|
40 | it is recommended that you use the FCDGeometryPolygons::FindIndicesForIdx function.
|
---|
41 |
|
---|
42 | @ingroup FCDGeometry
|
---|
43 | */
|
---|
44 | class FCDGeometryPolygonsInput
|
---|
45 | {
|
---|
46 | public:
|
---|
47 | /** Constructor. */
|
---|
48 | FCDGeometryPolygonsInput();
|
---|
49 |
|
---|
50 | /** Determines the type of data to input. */
|
---|
51 | FUDaeGeometryInput::Semantic semantic;
|
---|
52 |
|
---|
53 | /** Offset within the COLLADA document for this input.
|
---|
54 | All the inputs with the same offset value use the same indices within the COLLADA document. */
|
---|
55 | uint32 idx;
|
---|
56 |
|
---|
57 | /** [INTERNAL] Offset owner flags. One and only one polygon set input will have this flag set for each offset value.
|
---|
58 | A polygon set input with this flag set will contain valid indices within the 'indices' member variable.
|
---|
59 | You should not set or access this flag directly. Instead, use the FCDGeometryPolygons::FindIndicesForIdx function. */
|
---|
60 | bool ownsIdx;
|
---|
61 |
|
---|
62 | /** [INTERNAL] Tessellation indices. Use these indices to generate a list of unique vertices and generate your vertex buffers.
|
---|
63 | You should not set or access the indices directly. Instead, use the FCDGeometryPolygons::FindIndicesForIdx function. */
|
---|
64 | UInt32List indices;
|
---|
65 |
|
---|
66 | /** Data source. This is the data source into which the indices are indexing. You need to take the data source
|
---|
67 | stride into consideration when unindexing the data. */
|
---|
68 | FCDGeometrySource* source;
|
---|
69 |
|
---|
70 | /** Input set. Used to group together the texture coordinates with the texture tangents and binormals.
|
---|
71 | ColladaMax: this value should also represent the map channel index or texture coordinates
|
---|
72 | and vertex color channels. */
|
---|
73 | int32 set;
|
---|
74 | };
|
---|
75 |
|
---|
76 | /** A dynamically-sized array of FCDGeometryPolygonsInput objects. */
|
---|
77 | typedef vector<FCDGeometryPolygonsInput*> FCDGeometryPolygonsInputList;
|
---|
78 |
|
---|
79 | /**
|
---|
80 | A mesh polygon set.
|
---|
81 | Each polygon set contains a list of inputs and the tessellation information
|
---|
82 | to make polygons out of the data and indices of the input. FCollada
|
---|
83 | supports triangle lists as well as polygon lists and lists of polygons with holes.
|
---|
84 | This implies that each face has an undeterminate number of vertices.
|
---|
85 | The tessellation information creates polygons, but may also creates holes within the polygons.
|
---|
86 |
|
---|
87 | @ingroup FCDGeometry
|
---|
88 | */
|
---|
89 | class FCOLLADA_EXPORT FCDGeometryPolygons : public FCDObject
|
---|
90 | {
|
---|
91 | private:
|
---|
92 | DeclareObjectType;
|
---|
93 | FCDGeometryPolygonsInputList inputs;
|
---|
94 | FCDGeometryPolygonsInputList idxOwners;
|
---|
95 | UInt32List faceVertexCounts;
|
---|
96 | FCDGeometryMesh* parent;
|
---|
97 | size_t faceVertexCount;
|
---|
98 | UInt32List holeFaces;
|
---|
99 |
|
---|
100 | // Buffered statistics
|
---|
101 | size_t faceOffset;
|
---|
102 | size_t faceVertexOffset;
|
---|
103 | size_t holeOffset;
|
---|
104 |
|
---|
105 | // Material for this set of polygons
|
---|
106 | fstring materialSemantic;
|
---|
107 |
|
---|
108 | public:
|
---|
109 | /** Constructor: do not use directly. Instead, use the FCDGeometryMesh::AddPolygons function
|
---|
110 | to create new polygon sets.
|
---|
111 | @param document The COLLADA document which owns this polygon set.
|
---|
112 | @param parent The geometric mesh which contains this polygon set.*/
|
---|
113 | FCDGeometryPolygons(FCDocument* document, FCDGeometryMesh* parent);
|
---|
114 |
|
---|
115 | /** Destructor: do not use directly.
|
---|
116 | The mesh which contains this polygon set will handle its release. */
|
---|
117 | virtual ~FCDGeometryPolygons();
|
---|
118 |
|
---|
119 | /** Retrieves the geometry that contains this polygons.
|
---|
120 | @return The parent geometry. */
|
---|
121 | inline FCDGeometryMesh* GetParent() { return parent; }
|
---|
122 | inline const FCDGeometryMesh* GetParent() const { return parent; } /**< See above. */
|
---|
123 |
|
---|
124 | /** Retrieves the list of face-vertex counts. Each face within the polygon set
|
---|
125 | has one or more entry within this list, depending on the number of holes within that face.
|
---|
126 | Each face-vertex count indicates the number of ordered indices
|
---|
127 | within the polygon set inputs that are used to generate a face or its holes.
|
---|
128 | To find out if a face-vertex count represents a face or its holes, check
|
---|
129 | the hole-faces list retrieved using the GetHoleFaces function.
|
---|
130 | Indirectly, the face-vertex count indicates the degree of the polygon.
|
---|
131 | @see GetHoleFaces @see GetHoleCount
|
---|
132 | @return The list of face-vertex counts.*/
|
---|
133 | inline const UInt32List& GetFaceVertexCounts() const { return faceVertexCounts; }
|
---|
134 |
|
---|
135 | /** Retrieves the number of holes within the faces of the polygon set.
|
---|
136 | @return The number of holes within the faces of the polygon set. */
|
---|
137 | inline size_t GetHoleCount() const { return holeFaces.size(); }
|
---|
138 |
|
---|
139 | /** Retrieves the number of faces within the polygon set.
|
---|
140 | @return The number of faces within the polygon set. */
|
---|
141 | inline size_t GetFaceCount() const { return faceVertexCounts.size() - GetHoleCount(); }
|
---|
142 |
|
---|
143 | /** Retrieves the number of faces which appear before this polygon set within the geometric mesh.
|
---|
144 | This value is useful when traversing all the faces of a geometric mesh.
|
---|
145 | @return The number of faces in previous polygon sets. */
|
---|
146 | inline size_t GetFaceOffset() const { return faceOffset; }
|
---|
147 |
|
---|
148 | /** Retrieves the total number of face-vertex pairs within the polygon set.
|
---|
149 | This value is the total of all the values within the face-vertex count list.
|
---|
150 | Do remember that the list of face-vertex pairs includes holes.
|
---|
151 | @return The total number of face-vertex pairs within the polygon set. */
|
---|
152 | inline size_t GetFaceVertexCount() const { return faceVertexCount; }
|
---|
153 |
|
---|
154 | /** Retrieves the number of face-vertex pairs for a given face.
|
---|
155 | This value includes face-vertex pairs that create the polygon and its holes.
|
---|
156 | @param index A face index.
|
---|
157 | @return The number of face-vertex pairs for a given face. */
|
---|
158 | size_t GetFaceVertexCount(size_t index) const;
|
---|
159 |
|
---|
160 | /** Retrieves the total number of face-vertex pairs which appear
|
---|
161 | before this polygon set within the geometric mesh.
|
---|
162 | This value is useful when traversing all the face-vertex pairs of a geometric mesh.
|
---|
163 | @return The number of face-vertex pairs in previous polygon sets. */
|
---|
164 | inline size_t GetFaceVertexOffset() const { return faceVertexOffset; }
|
---|
165 |
|
---|
166 | /** Retrieves the number of holes which appear before this polygon set.
|
---|
167 | This value is useful when traversing all the face-vertex pairs of a geometric mesh. */
|
---|
168 | inline size_t GetHoleOffset() const { return holeOffset; }
|
---|
169 |
|
---|
170 | /** Retrieves the number of face-vertex pairs which appear
|
---|
171 | before a given face within the polygon set.
|
---|
172 | This value is useful when doing per-vertex mesh operations within the polygon set.
|
---|
173 | @param index The index of the face.
|
---|
174 | @return The number of face-vertex pairs before the given face, within the polygon set. */
|
---|
175 | size_t GetFaceVertexOffset(size_t index) const;
|
---|
176 |
|
---|
177 | /** [INTERNAL] Sets the number of faces in previous polygon sets.
|
---|
178 | Used by the FCDGeometryMesh::Recalculate function.
|
---|
179 | @param offset The number of faces in previous polygon sets. */
|
---|
180 | inline void SetFaceOffset(size_t offset) { faceOffset = offset; }
|
---|
181 |
|
---|
182 | /** [INTERNAL] Sets the number of face-vertex pairs in previous polygon sets.
|
---|
183 | Used by the FCDGeometryMesh::Recalculate function.
|
---|
184 | @param offset The number of face-vertex pairs in previous polygon sets. */
|
---|
185 | inline void SetFaceVertexOffset(size_t offset) { faceVertexOffset = offset; }
|
---|
186 |
|
---|
187 | /** [INTERNAL] Sets the number of holes in previous polygon sets.
|
---|
188 | Used by the FCDGeometryMesh::Recalculate function.
|
---|
189 | @param offset The number of holes in previous polygon sets. */
|
---|
190 | inline void SetHoleOffset(size_t offset) { holeOffset = offset; }
|
---|
191 |
|
---|
192 | /** Creates a new face.
|
---|
193 | Enough indices to fill the face will be added to the polygon set inputs: you will
|
---|
194 | want to overwrite those, as they will all be set to zero.
|
---|
195 | @param degree The degree of the polygon. This number implies the number of indices
|
---|
196 | that will be expected, in order, within each of the input index lists. */
|
---|
197 | void AddFace(uint32 degree);
|
---|
198 |
|
---|
199 | /** Removes a face
|
---|
200 | @param index The index of the face to remove. All the indices associated
|
---|
201 | with this face will also be removed. */
|
---|
202 | void RemoveFace(size_t index);
|
---|
203 |
|
---|
204 | /** Retrieves the list of polygon set inputs.
|
---|
205 | @see FCDGeometryPolygonsInput
|
---|
206 | @return The list of polygon set inputs. */
|
---|
207 | inline FCDGeometryPolygonsInputList& GetInputs() { return inputs; }
|
---|
208 | inline const FCDGeometryPolygonsInputList& GetInputs() const { return inputs; } /**< See above. */
|
---|
209 |
|
---|
210 | /** Retrieves the number of polygon set inputs.
|
---|
211 | @return The number of polygon set inputs. */
|
---|
212 | inline size_t GetInputCount() const { return inputs.size(); }
|
---|
213 |
|
---|
214 | /** Retrieves a specific polygon set input.
|
---|
215 | @param index The index of the polygon set input. This index should
|
---|
216 | not be greater than or equal to the number of polygon set inputs.
|
---|
217 | @return The specific polygon set input. This pointer will be NULL if the index is out-of-bounds. */
|
---|
218 | inline FCDGeometryPolygonsInput* GetInput(size_t index) { FUAssert(index < GetInputCount(), return NULL); return inputs.at(index); }
|
---|
219 | inline const FCDGeometryPolygonsInput* GetInput(size_t index) const { FUAssert(index < GetInputCount(), return NULL); return inputs.at(index); } /**< See above. */
|
---|
220 |
|
---|
221 | /** Creates a new polygon set input.
|
---|
222 | @param source The data source for the polygon set input.
|
---|
223 | @param offset The tessellation indices offset for the polygon set input.
|
---|
224 | If this value is new to the list of polygon inputs, you will need to fill in the indices.
|
---|
225 | Please use the FindIndices function to verify that the offset is new and that indices need
|
---|
226 | to be provided. The offset of zero is reserved for per-vertex data sources.
|
---|
227 | @return The new polygon set input. */
|
---|
228 | FCDGeometryPolygonsInput* AddInput(FCDGeometrySource* source, uint32 offset);
|
---|
229 |
|
---|
230 | /** Deletes a polygon set input.
|
---|
231 | This function releases the memory held by the polygon set input as well as moves
|
---|
232 | the indices to another polygon set input with the same offset, if the offset is re-used.
|
---|
233 | @param input The polygon set input to delete. */
|
---|
234 | void ReleaseInput(FCDGeometryPolygonsInput* input);
|
---|
235 |
|
---|
236 | /** Retrieves the list of entries within the face-vertex count list
|
---|
237 | that are considered holes. COLLADA does not support holes within holes,
|
---|
238 | so each entry within this list implies a hole within the previous face.
|
---|
239 | @see GetFaceVertexCounts
|
---|
240 | @return The list of hole entries within the face-vertex counts. */
|
---|
241 | inline const UInt32List& GetHoleFaces() const { return holeFaces; }
|
---|
242 |
|
---|
243 | /** Retrieves the number of holes within faces of the polygon set that appear
|
---|
244 | before the given face index. This value is useful when trying to access
|
---|
245 | a specific face of a mesh, as holes and faces appear together within the
|
---|
246 | face-vertex degree list.
|
---|
247 | @param index A face index.
|
---|
248 | @return The number of holes within the polygon set that appear
|
---|
249 | before the given face index. */
|
---|
250 | size_t GetHoleCountBefore(size_t index) const;
|
---|
251 |
|
---|
252 | /** Retrieves the number of holes within a given face.
|
---|
253 | @param index A face index.
|
---|
254 | @return The number of holes within the given face. */
|
---|
255 | size_t GetHoleCount(size_t index) const;
|
---|
256 |
|
---|
257 | /** Retrieves the first polygon set input found that has the given data type.
|
---|
258 | @param semantic A type of geometry data.
|
---|
259 | @return The polygon set input. This pointer will be NULL if
|
---|
260 | no polygon set input matches the data type. */
|
---|
261 | FCDGeometryPolygonsInput* FindInput(FUDaeGeometryInput::Semantic semantic);
|
---|
262 | const FCDGeometryPolygonsInput* FindInput(FUDaeGeometryInput::Semantic semantic) const; /**< See above. */
|
---|
263 |
|
---|
264 | /** Retrieves the polygon set input that points towards a given data source.
|
---|
265 | @param source A geometry data source.
|
---|
266 | @return The polygon set input. This pointer will be NULL if
|
---|
267 | no polygon set input matches the data source. */
|
---|
268 | FCDGeometryPolygonsInput* FindInput(FCDGeometrySource* source);
|
---|
269 | const FCDGeometryPolygonsInput* FindInput(const FCDGeometrySource* source) const; /**< See above. */
|
---|
270 |
|
---|
271 | /** [INTERNAL] Retrieves the polygon set input that points towards a given data source.
|
---|
272 | @param sourceId The COLLADA id of a geometry data source.
|
---|
273 | @return The polygon set input. This pointer will be NULL if
|
---|
274 | no polygon set input matches the COLLADA id. */
|
---|
275 | FCDGeometryPolygonsInput* FindInput(const string& sourceId);
|
---|
276 |
|
---|
277 | /** Retrieves all the polygon set inputs that have the given data type.
|
---|
278 | @param semantic A type of geometry data.
|
---|
279 | @param inputs A list of polygon set inputs to fill in. This list is not emptied by the function
|
---|
280 | and may remain untouched, if no polygon set input matches the given data type. */
|
---|
281 | void FindInputs(FUDaeGeometryInput::Semantic semantic, FCDGeometryPolygonsInputList& inputs);
|
---|
282 |
|
---|
283 | /** Retrieves the tessellation indices for a given polygon set input offset.
|
---|
284 | @deprecated Instead, use the FindIndices function.
|
---|
285 | @param idx A polygon set input offset.
|
---|
286 | @return The tessellation indices corresponding to the offset. This pointer
|
---|
287 | will be NULL if there are no polygon set input which uses the given offset. */
|
---|
288 | UInt32List* FindIndicesForIdx(uint32 idx);
|
---|
289 | const UInt32List* FindIndicesForIdx(uint32 idx) const; /**< See above. */
|
---|
290 |
|
---|
291 | /** Retrieves the first tessellation index list for a given data source.
|
---|
292 | @param source A data source.
|
---|
293 | @return The first tessellation index list corresponding to the data source. This pointer
|
---|
294 | will be NULL if the data source is not used within this polygon set. */
|
---|
295 | UInt32List* FindIndices(FCDGeometrySource* source);
|
---|
296 | const UInt32List* FindIndices(const FCDGeometrySource* source) const; /**< See above. */
|
---|
297 |
|
---|
298 | /** Retrieves the tessellation indices for a given polygon set input.
|
---|
299 | @param input A given polygon set input.
|
---|
300 | @return The tessellation indices corresponding to the polygon set input. This pointer
|
---|
301 | will be NULL if the polygon set input is not used within this polygon set. */
|
---|
302 | UInt32List* FindIndices(FCDGeometryPolygonsInput* input);
|
---|
303 | const UInt32List* FindIndices(const FCDGeometryPolygonsInput* input) const; /**< See above. */
|
---|
304 |
|
---|
305 | /** Retrieves the symbolic name for the material used on this polygon set.
|
---|
306 | Match this symbolic name within a FCDGeometryInstance to get the
|
---|
307 | correct material instance.
|
---|
308 | @return A symbolic material name. */
|
---|
309 | inline const fstring& GetMaterialSemantic() const { return materialSemantic; }
|
---|
310 |
|
---|
311 | /** Sets a symbolic name for the material used on this polygon set.
|
---|
312 | This symbolic name will be matched within a FCDGeometryInstance to assign
|
---|
313 | the correct material.
|
---|
314 | @param semantic The symbolic material name. */
|
---|
315 | inline void SetMaterialSemantic(const fchar* semantic) { materialSemantic = semantic; }
|
---|
316 | inline void SetMaterialSemantic(const fstring& semantic) { materialSemantic = semantic; } /**< See above. */
|
---|
317 |
|
---|
318 | /** Triangulates the polygon set.
|
---|
319 | A simple fanning techique is currently used: holes will not be triangulated correctly. */
|
---|
320 | void Triangulate();
|
---|
321 |
|
---|
322 | /** [INTERNAL] Recalculates the buffered offset and count values for this polygon set. */
|
---|
323 | void Recalculate();
|
---|
324 |
|
---|
325 | /** [INTERNAL] Reads in the polygon set element from a given COLLADA XML tree node.
|
---|
326 | COLLADA has multiple polygon set elements. The most common ones are \<triangles\> and \<polylist\>.
|
---|
327 | @param polygonNode The COLLADA XML tree node.
|
---|
328 | @return The status of the import. If the status is not successful,
|
---|
329 | it may be dangerous to extract information from the polygon set.*/
|
---|
330 | FUStatus LoadFromXML(xmlNode* polygonNode);
|
---|
331 |
|
---|
332 | /** [INTERNAL] Writes out the correct polygon set element to the given COLLADA XML tree node.
|
---|
333 | COLLADA has multiple polygon set elements. The most common ones are \<triangles\> and \<polylist\>.
|
---|
334 | @param parentNode The COLLADA XML parent node in which to insert the geometric mesh.
|
---|
335 | @return The created XML tree node. */
|
---|
336 | xmlNode* WriteToXML(xmlNode* parentNode) const;
|
---|
337 |
|
---|
338 | /** [INTERNAL] Creates a copy of this mesh.
|
---|
339 | You should use the FCDGeometry::Clone function instead of this function.
|
---|
340 | You will need to release the cloned entity.
|
---|
341 | @param cloneParent The geometric mesh which will contain the cloned polygon set.
|
---|
342 | @return An identical copy of the polygon set. */
|
---|
343 | FCDGeometryPolygons* Clone(FCDGeometryMesh* cloneParent);
|
---|
344 |
|
---|
345 | private:
|
---|
346 | // Performs operations needed before tessellation
|
---|
347 | bool InitTessellation(xmlNode* itNode,
|
---|
348 | uint32* localFaceVertexCount, UInt32List& allIndices,
|
---|
349 | const char* content, xmlNode*& holeNode, uint32 idxCount,
|
---|
350 | bool* failed);
|
---|
351 | };
|
---|
352 |
|
---|
353 | #endif // _FCD_GEOMETRY_POLYGONS_H_
|
---|