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

Revision 964, 7.8 KB checked in by igarcia, 19 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 FCDMorphController.h
14        This file contains the FCDMorphController and the FCDMorphTarget classes.
15*/
16
17#ifndef _FCD_MORPH_CONTROLLER_H_
18#define _FCD_MORPH_CONTROLLER_H_
19
20#include "FUtils/FUDaeEnum.h"
21#include "FCDocument/FCDObject.h"
22
23class FCDocument;
24class FCDController;
25class FCDGeometry;
26class FCDMorphController;
27
28/**
29        A COLLADA morph target.
30        A morph target is just a geometric entity with a weight assigned.
31        The weight may be animated.
32*/
33class FCOLLADA_EXPORT FCDMorphTarget : public FCDObject
34{
35private:
36        DeclareObjectType;
37        FCDMorphController* parent;
38        FCDGeometry* geometry;
39        float weight;
40
41public:
42        /** Constructor: do not use directly.
43                Instead, use the FCDMorphController::AddTarget function.
44                @param document The COLLADA document that owns the morph target.
45                @param parent The morph controller that contains the morph target. */
46        FCDMorphTarget(FCDocument* document, FCDMorphController* parent);
47
48        /** Destructor. */
49        virtual ~FCDMorphTarget();
50
51        /** Retrieves the morph controller which contains this target.
52                @return The parent morpher. */
53        FCDMorphController* GetParent() { return parent; }
54        const FCDMorphController* GetParent() const { return parent; } /**< See above. */
55
56        /** Retrieves the target geometry.
57                This is what the morphed geometry should look like if
58                the morphing weight is set to 1.0f.
59                @return The target geometry. */
60        FCDGeometry* GetGeometry() { return geometry; }
61        const FCDGeometry* GetGeometry() const { return geometry; } /**< See above. */
62
63        /** Sets the target geometry.
64                This is what the morphed geometry should look like if
65                the morphing weight is set to 1.0f. As such, the target geometry
66                should be similar to the base target geometry. You can verify
67                this using the FCDMorphController::IsSimilar function.
68                @param geometry The target geometry. */
69        void SetGeometry(FCDGeometry* geometry);
70
71        /** Retrieves the morphing weight.
72                @return The morphing weight. */
73        float& GetWeight() { return weight; }
74        const float& GetWeight() const { return weight; } /**< See above. */
75
76        /** Sets the morphing weight.
77                This function has no impact on any animations that target the morphing weight.
78                @param _weight The morphing weight. */
79        void SetWeight(float _weight) { weight = _weight; }
80
81        /** Retrieves whether the morphing weight is animated.
82                @return Whether the morphing weight is animated. */
83        bool IsAnimated() const;
84
85        /** Retrieves the animation associated with the morphing weight.
86                @return The animated value associated with the morphing weight.
87                        This pointer will be NULL if the morphing weight is not animated. */
88        FCDAnimated* GetAnimatedWeight();
89        const FCDAnimated* GetAnimatedWeight() const; /**< See above. */
90};
91
92/** A dynamically-sized array of morph targets. */
93typedef vector<FCDMorphTarget*> FCDMorphTargetList;
94
95/**
96        A COLLADA morpher.
97
98        A morpher holds a base geometry and a set of morph targets
99        that contains a geometry and a weight. The geometry must be similar to the
100        base geometry and the weights are used to interpolate the vertex positions
101        of the base geometry. To be similar, two meshes must have the same number of
102        vertices and two splines must have the same number of control points.
103        The morphing weights can be animated.
104       
105        There are two interpolation functions defined in COLLADA.
106        See the FUDaeMorphMethod::Method enumerated type for more information.
107
108        @see FCDMorphTarget FUDaeMorphMethod
109        @ingroup FCDGeometry
110*/
111class FCOLLADA_EXPORT FCDMorphController : public FCDObject
112{
113private:
114        DeclareObjectType;
115        FCDController* parent;
116        FCDocument* document;
117
118        FUDaeMorphMethod::Method method;
119        FCDEntity* baseTarget;
120        FCDMorphTargetList morphTargets;
121
122public:
123        /** Constructor: do not use directly.
124                Instead, use the FCDController::CreateMorphController function.
125                @param document The COLLADA document that owns the morpher.
126                @param parent The COLLADA controller that contains this morpher. */
127        FCDMorphController(FCDocument* document, FCDController* parent);
128
129        /** Destructor: do not use directly.
130                Instead, release the parent controller or create a new skin/morpher. */
131        virtual ~FCDMorphController();
132
133        /** Retrieves the base entity controlled by this morpher.
134                This entity may be a geometry or another controller.
135                @return The base target. */
136        FCDEntity* GetBaseTarget() { return baseTarget; }
137        const FCDEntity* GetBaseTarget() const { return baseTarget; } /**< See above. */
138
139        /** Sets the base entity controlled by this morpher.
140                This entity may be a geometry or another controller.
141                Since the morph targets must be similar to this entity,
142                all the morph targets that are not similar to the new base entity will be removed.
143                @param entity The new base entity. */
144        void SetBaseTarget(FCDEntity* entity);
145
146        /** Retrieves the list of the morph targets.
147                All the morph target geometries should be similar to the base entity.
148                @return The morph targets. */
149        FCDMorphTargetList& GetTargets() { return morphTargets; }
150        const FCDMorphTargetList& GetTargets() const { return morphTargets; } /**< See above. */
151
152        /** Retrieves the number of morph targets.
153                @return The number of morph targets. */
154        size_t GetTargetCount() const { return morphTargets.size(); }
155
156        /** Retrieves a specific morph target.
157                @param index The index of the morph target.
158                @return The morph target. This pointer will be NULL if the index is out-of-bounds. */
159        FCDMorphTarget* GetTarget(size_t index) { FUAssert(index < GetTargetCount(), return NULL); return morphTargets.at(index); }
160        const FCDMorphTarget* GetTarget(size_t index) const { FUAssert(index < GetTargetCount(), return NULL); return morphTargets.at(index); } /**< See above. */
161
162        /** Adds a new morph target.
163                @param geometry The morph target geometry.
164                @param weight The morphing weight.
165                @return The new morph target. */
166        FCDMorphTarget* AddTarget(FCDGeometry* geometry = NULL, float weight = 0.0f);
167
168        /** Releases a morph target used in this morpher.
169                @param target The morph target to release. */
170        void ReleaseTarget(FCDMorphTarget* target);
171
172        /** Retrieves the method used to interpolate between the different morph targets.
173                @return The interpolation method. */
174        FUDaeMorphMethod::Method GetMethod() const { return method; }
175
176        /** Sets the method used to interpolate between the different morph targets.
177                @param _method The interpolation method. */
178        void SetMethod(FUDaeMorphMethod::Method _method) { method = _method; }
179
180        /** Retrieves whether a given entity is similar to the base target.
181                Entities must be similar to be able to morph between them.
182                @param entity An entity.
183                @return Whether the given entity is similar to the base target. */
184        bool IsSimilar(FCDEntity* entity);
185
186        /** [INTERNAL] Reads in the \<morph\> element from a given COLLADA XML tree node.
187                @param morphNode The COLLADA XML tree node.
188                @return The status of the import. If the status is not successful,
189                        it may be dangerous to extract information from the morpher.*/
190        FUStatus LoadFromXML(xmlNode* morphNode);
191
192        /** [INTERNAL] Writes out the \<morph\> element to the given COLLADA XML tree node.
193                @param parentNode The COLLADA XML parent node in which to insert the morphing information.
194                @return The created element XML tree node. */
195        xmlNode* WriteToXML(xmlNode* parentNode) const;
196
197        /** [INTERNAL] Links the controller with its entities.
198                Since geometries are loaded before the controllers, no linkage is necessary.
199                @return The status of the linkage: always successful. */
200        FUStatus Link();
201};
202
203#endif // _FCD_MORPH_CONTROLLER_H_
204
Note: See TracBrowser for help on using the repository browser.