source: NonGTP/FCollada/FCDocument/FCDGeometryMesh.h @ 964

Revision 964, 11.0 KB checked in by igarcia, 18 years ago (diff)
Line 
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 FCDGeometryMesh.h
14        This file contains the FCDGeometryMesh class.
15*/
16
17#ifndef _FCD_GEOMETRY_MESH_H_
18#define _FCD_GEOMETRY_MESH_H_
19
20#include "FCDocument/FCDObject.h"
21#include "FUtils/FUDaeEnum.h"
22
23class FCDocument;
24class FCDGeometry;
25class FCDGeometryPolygons;
26class FCDGeometrySource;
27
28/** A dynamically-sized array of FCDGeometrySource objects. */
29typedef vector<FCDGeometrySource*> FCDGeometrySourceList;
30/** A dynamically-sized array of FCDGeometryPolygons objects. */
31typedef vector<FCDGeometryPolygons*> FCDGeometryPolygonsList;
32
33/**
34        A COLLADA geometric mesh.
35        A COLLADA geometric mesh is a list of vertices tied together in polygons.
36        A set of per-vertex data is used to determine the vertices of the mesh.
37        This data usually includes a single list: of vertex positions, but it may also
38        contain per-vertex colors, per-vertex normals or per-vertex texture coordinates.
39        The other data sources declare per-vertex-face data.
40
41        The faces of a mesh may be split across different groups, as they may have
42        different materials assigned to them. The FCDGeometryPolygons objects contains one such group
43        of faces.
44
45        @ingroup FCDGeometry
46*/
47class FCOLLADA_EXPORT FCDGeometryMesh : public FCDObject
48{
49private:
50        DeclareObjectType;
51
52        FCDGeometry* parent;
53        FCDGeometrySourceList sources;
54        FCDGeometryPolygonsList polygons;
55
56        FCDGeometrySourceList vertexSources;
57        size_t faceCount, holeCount;
58        size_t faceVertexCount;
59        bool isDoubleSided; // Maya-specific, defaults to true
60
61public:
62        /** Contructor: do not use directly. Use FCDGeometry::AddMesh instead.
63                @param document The COLLADA document which owns this mesh.
64                @param parent The geometry entity which contains this mesh. */
65        FCDGeometryMesh(FCDocument* document, FCDGeometry* parent);
66
67        /** Destructor: do not use directly. All geometric meshes are released with the geometry that they belong to. */
68        virtual ~FCDGeometryMesh();
69
70        /** Retrieves the number of faces within the geometric mesh.
71                @return The number of faces within the geometric mesh. */
72        inline size_t GetFaceCount() const { return faceCount; }
73
74        /** Retrieves the number of holes within the faces of the geometric mesh.
75                As one face may contain multiple holes, this value may be larger than the number of faces.
76                @return The number of holes within the faces of the geometric mesh. */
77        inline size_t GetHoleCount() const { return holeCount; }
78
79        /** Retrieves the total number of per-face vertices in the mesh.
80                This function makes no assumption about the uniqueness of the per-face vertices.
81                @return The total number of per-face vertices in the mesh. */
82        inline size_t GetFaceVertexCount() const { return faceVertexCount; }
83
84        /** Retrieves whether the mesh should be treated as double-sided.
85                This flag does not belong to COLLADA but is exported at the geometric-level by ColladaMaya.
86                @return Whether the mesh is double-sided. */
87        inline bool IsDoubleSided() const { return isDoubleSided; }
88
89        /** Retrieves the COLLADA id of the mesh.
90                This is a shortcut to the parent geometry's COLLADA id.
91                @return The COLLADA id of the mesh. */
92        const string& GetDaeId() const;
93
94        /** Retrieves the number of independent polygon groups.
95                Each polygon group is represented within a FCDGeometryPolygons object.
96                An independent polygon group is usually created to assign a different material to different parts of the mesh
97                or to assign partial texture coordinates and texture tangents to different parts of the mesh.
98                @return The number of independent polygon groups. */
99        inline size_t GetPolygonsCount() const { return polygons.size(); }
100
101        /** Retrieves a specific polygon group.
102                Each polygon group is represented within a FCDGeometryPolygons object.
103                An independent polygon group is usually created to assign a different material to different parts of the mesh
104                or to assign partial texture coordinates and texture tangents to different parts of the mesh.
105                @param index The index of the polygon group. This index should be less than the number
106                        of independent polygon groups returned by the GetPolygonsCount function.
107                @return The polygon group. This pointer will be NULL if the index is out-of-bounds. */
108        inline FCDGeometryPolygons* GetPolygons(size_t index) { FUAssert(index < GetPolygonsCount(), return NULL); return polygons.at(index); }
109        inline const FCDGeometryPolygons* GetPolygons(size_t index) const { FUAssert(index < GetPolygonsCount(), return NULL); return polygons.at(index); } /**< See above. */
110
111        /** Creates a new polygon group.
112                Each polygon group is represented within a FCDGeometryPolygons object.
113                The new polygon group will be assigned all the existing per-vertex data sources.
114                No material will be assigned to the new polygon group.
115                @return The new polygon group. This pointer should never be NULL. */
116        FCDGeometryPolygons* AddPolygons();
117
118        /** [INTERNAL] Retrieves the list of per-vertex data sources.
119                There should usually be one per-vertex data source that contains positions.
120                All the sources within this list are also present within the data source list.
121                @return The list of per-vertex data sources. */
122        inline FCDGeometrySourceList& GetVertexSources() { return vertexSources; }
123        inline const FCDGeometrySourceList& GetVertexSources() const { return vertexSources; } /**< See above. */
124
125        /** Retrieves the number of per-vertex data sources.
126                This number should always be lesser or equal to the number of data sources, as each per-vertex
127                data source is also included within the list of data sources.
128                @return The number of per-vertex data sources. */
129        inline size_t GetVertexSourceCount() const { return vertexSources.size(); }
130
131        /** Retrieves a specific per-vertex data source.
132                All the per-vertex data sources are also included in the list of data sources.
133                @param index The index of the per-vertex data source. This index should be less than the number of
134                        per-vertex data sources returns by the GetVertexSourceCount function.
135                @return The per-vertex data source. This pointer will be NULL if the index is out-of-bounds. */
136        inline FCDGeometrySource* GetVertexSource(size_t index) { FUAssert(index < GetVertexSourceCount(), return NULL); return vertexSources.at(index); }
137        inline const FCDGeometrySource* GetVertexSource(size_t index) const { FUAssert(index < GetVertexSourceCount(), return NULL); return vertexSources.at(index); } /**< See above. */
138
139        /** Creates a new per-vertex data source for this geometric mesh.
140                The per-vertex data source will be added to both the per-vertex data source list and the data source list.
141                The new per-vertex data source will automatically be added to all the existing polygon groups.
142                @return The new per-vertex data source. This pointer should never be NULL. */
143        FCDGeometrySource* AddVertexSource();
144
145        /** [INTERNAL] Retrieves the data source that matches the given COLLADA id.
146                @param id A valid COLLADA id.
147                @return The data source. This pointer will be NULL if no matching data source was found. */             
148        FCDGeometrySource* FindSourceById(const string& id);
149        const FCDGeometrySource* FindSourceById(const string& id) const; /**< See above. */
150
151        /** Retrieves the per-vertex data that specifically contains the vertex positions.
152                If there are more than one per-vertex data source that contains vertex positions, the first one is returned.
153                @return A per-vertex data source that contains vertex positions. This pointer will be NULL
154                        in the unlikely possibility that there are no per-vertex data source that contains vertex positions. */
155        FCDGeometrySource* GetPositionSource();
156        const FCDGeometrySource* GetPositionSource() const; /**< See above. */
157
158        /** Retrieves the number of data sources contained within this geometric mesh.
159                @return The number of data sources within the mesh. */
160        inline size_t GetSourceCount() const { return sources.size(); }
161
162        /** Retrieves a specific data source.
163                @param index The index of the data source. This index should be less than the number of
164                        data sources returns by the GetSourceCount function.
165                @return The data source. This pointer will be NULL if the index is out-of-bounds. */
166        inline FCDGeometrySource* GetSource(size_t index) { FUAssert(index < GetSourceCount(), return NULL); return sources.at(index); }
167        inline const FCDGeometrySource* GetSource(size_t index) const { FUAssert(index < GetSourceCount(), return NULL); return sources.at(index); } /**< See above. */
168
169        /** Creates a new data source for this geometric mesh.
170                The new data source will not be added to any of the existing polygon groups.
171                @return The new per-vertex data source. This pointer should never be NULL. */
172        FCDGeometrySource* AddSource();
173
174        /** Triangulates the mesh.
175                A simple fanning techique is currently used: holes will not be triangulated correctly. */
176        void Triangulate();
177
178        /** [INTERNAL] Forces the recalculation of the hole count, vertex count, face-vertex counts and their offsets.
179                Since the counts and offsets are buffered at the geometric mesh object level, this function allows the polygon
180                groups to force the recalculation of the buffered values, when they are modified. */
181        void Recalculate();
182       
183        /** [INTERNAL] Creates a copy of this mesh. You may use the FCDGeometry::Clone function instead of this function.
184                Creates a full copy of the geometry, with the vertices overwritten
185                by the given data: this is used when importing COLLADA 1.3 skin controllers.
186                You will need to release the cloned entity.
187                @see FCDGeometry::Clone.
188                @param newPositions The list of vertex position that will
189                        overwrite the current mesh vertex positions. This list may be empty.
190                @param newPositionsStride The stride, in bytes, of the newPositions list.
191                        For an empty newPositions list, this value is discarded.
192                @param newNormals The list of vertex normals that will overwrite
193                        the current mesh vertex normals. This list may be empty.
194                @param newNormalsStride The stride, in bytes, of the newNormals list.
195                        For an empty newNormals list, this value is discarded.
196                @return The cloned geometry entity. You will need to release this pointer. */
197        FCDGeometryMesh* Clone(FloatList& newPositions, uint32 newPositionsStride, FloatList& newNormals, uint32 newNormalsStride);
198
199        /** [INTERNAL] Reads in the \<mesh\> element from a given COLLADA XML tree node.
200                @param meshNode The COLLADA XML tree node.
201                @return The status of the import. If the status is not successful,
202                        it may be dangerous to extract information from the geometric mesh.*/
203        FUStatus LoadFromXML(xmlNode* meshNode);
204
205        /** [INTERNAL] Writes out the \<mesh\> element to the given COLLADA XML tree node.
206                @param parentNode The COLLADA XML parent node in which to insert the geometric mesh.
207                @return The created \<mesh\> element XML tree node. */
208        xmlNode* WriteToXML(xmlNode* parentNode) const;
209};
210
211#endif // _FCD_GEOMETRY_MESH_H_
Note: See TracBrowser for help on using the repository browser.