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

Revision 964, 18.6 KB checked in by igarcia, 19 years ago (diff)
RevLine 
[964]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 FCDEffectStandard.h
14        This file contains the FCDEffectStandard class.
15*/
16
17#ifndef _FCD_MATERIAL_STANDARD_H_
18#define _FCD_MATERIAL_STANDARD_H_
19
20#include "FUtils/FUDaeEnum.h"
21#include "FCDocument/FCDEffectProfile.h"
22
23class FCDocument;
24class FCDEffect;
25class FCDEffectParameter;
26class FCDTexture;
27class FCDEffectParameterList;
28
29/** A dynamically-sized array of texture objects. */
30typedef vector<FCDTexture*> FCDTextureList;
31
32/**
33        A COMMON profile effect description.
34       
35        The COMMON effect profile holds the information necessary
36        to render your polygon sets using the well-defined lighting models.
37
38        COLLADA supports four lighting models: constant, Lambert, Phong and Blinn.
39
40        @ingroup FCDEffect
41*/
42class FCOLLADA_EXPORT FCDEffectStandard : public FCDEffectProfile
43{
44public:
45        /** The list of the lighting models supported by the COMMON profile of COLLADA. */
46        enum LightingType
47        {
48                /** The constant lighting model.
49                        This lighting model uses the emissive color everywhere, without
50                        any complex lighting calculations. It also uses the translucency
51                        factor and the translucency color, by multiplying them together
52                        and applying them to your standard alpha channel according to the
53                        final lighting color.*/
54                CONSTANT,
55
56                /** The Lambert lighting model.
57                        This lighting model improves on the constant lighting model by
58                        using the dot-product between the normalized light vectors and the
59                        polygon normals to determine how much light should affect each polygon.
60                        This value is multiplied to the diffuse color and (1 + the ambient color). */
61                LAMBERT,
62
63                /** The Phong lighting model.
64                        This lighting model improves on the Lambert lighting model by
65                        calculating how much light is reflected by the polygons into the viewer's eye.
66                        For this calculation, the shininess, the specular color and the reflectivity is used. */
67                PHONG,
68
69                /** The Blinn lighting model.
70                        This lighting model improves on the Lambert lighting model by
71                        calculating how much light is reflected by the polygons into the viewer's eye.
72                        For this calculation, the shininess, the specular color and the reflectivity is used. */
73                BLINN,
74
75                /** Not a valid lighting model. */
76                UNKNOWN
77        };
78
79private:
80        DeclareObjectType;
81        LightingType type;
82        FCDTextureList* textureBuckets;
83
84        // Common material parameter: Emission
85        FMVector3 emissionColor;
86        float emissionFactor; // Max-specific
87       
88        // Common material parameter: Translucency
89        FMVector3 translucencyColor;
90        float translucencyFactor;
91
92        // Lambert material parameters
93        FMVector3 diffuseColor;
94        FMVector3 ambientColor;
95
96        // Phong material parameters: Specular
97        FMVector3 specularColor;
98        float specularFactor; // Max-specific
99        float shininess;
100
101        // Phong material parameter: Reflectivity
102        FMVector3 reflectivityColor; // Maya-specific
103        float reflectivityFactor; // Maya-specific
104
105        // Geometry modifier
106        bool isFaceted; // Max-specific
107        bool isDoubleSided; // Max-specific for now
108        bool isWireframe; // Max-specific
109        bool isFaceMap; // Max-specific
110        bool isEmissionFactor; // Max-specific
111
112public:
113        /** Constructor: do not use directly. Instead, use the FCDEffect::AddProfile function
114                with the FUDaeProfileType::COMMON parameter.
115                @param document The COLLADA document that owns this effect profile.
116                @param parent The effect that contains this profile. */
117        FCDEffectStandard(FCDocument* document, FCDEffect* parent);
118
119        /** Destructor: do not use directly.
120                Instead, use the FCDEffect::ReleaseProfile function. */
121        virtual ~FCDEffectStandard();
122
123        /** Retrieves the lighting model to be used for this profile.
124                @return The lighting model. */
125        inline LightingType GetLightingType() const { return type; }
126
127        /** Sets the lighting model to be used for this profile.
128                Note that which parameters are exported depends on the lighting model.
129                @param _type The lighting model. */
130        inline void SetLightingType(LightingType _type) { type = _type; }
131
132        /** Retrieves the profile type for this effect.
133                This function is a part of the FCDEffectProfile interface and allows you
134                to up-cast an effect profile pointer safely to this class.
135                @return The profile type: COMMON. */
136        virtual FUDaeProfileType::Type GetType() const { return FUDaeProfileType::COMMON; }
137
138        /** Retrieves the list of textures belonging to a specific channel.
139                @param bucket A texture channel index. This index should match one
140                        of the values in the FUDaeTextureChannel enum.
141                @return The list of textures for this channel. */
142        const FCDTextureList& GetTextureBucket(uint32 bucket) const;
143
144        /** Retrieves the number of textures belonging to a specific channel.
145                @param bucket A texture channel index. This index should match one
146                        of the values in the FUDaeTextureChannel enum.
147                @return The number of textures in that channel. */
148        size_t GetTextureCount(uint32 bucket) const { FUAssert(bucket < FUDaeTextureChannel::COUNT, return 0); return textureBuckets[bucket].size(); }
149
150        /** Retrieves a texture
151                @param bucket A texture channel index. This index should match one
152                        of the values in the FUDaeTextureChannel enum.
153                @param index The index of a texture within this channel.
154                @return The texture. This pointer will be NULL if either the bucket or the index is out-of-bounds. */
155        inline FCDTexture* GetTexture(uint32 bucket, size_t index) { FUAssert(index < GetTextureCount(bucket), return NULL); return textureBuckets[bucket].at(index); }
156        inline const FCDTexture* GetTexture(uint32 bucket, size_t index) const { FUAssert(index < GetTextureCount(bucket), return NULL); return textureBuckets[bucket].at(index); } /**< See above. */
157
158        /** Adds a texture to a specific channel.
159                @param bucket A texture channel index. This index should match one
160                        of the values in the FUDaeTextureChannel enum.
161                @return The new texture. This pointer will be NULL if the bucket is out-of-bounds. */
162        FCDTexture* AddTexture(uint32 bucket);
163
164        /** Releases a texture contained within this effect profile.
165                @param texture The texture to release. */
166        void ReleaseTexture(FCDTexture* texture);
167
168        /** Retrieves the base translucency color.
169                This value must be multiplied with the translucency factor
170                to get the real translucency color.
171                This value is used in all lighting models.
172                @return The base translucency color. */
173        inline const FMVector3& GetTranslucencyColor() const { return translucencyColor; }
174
175        /** Sets the base translucency color.
176                @param color The base translucency color. */
177        inline void SetTranslucencyColor(const FMVector3& color) { translucencyColor = color; }
178
179        /** Retrieves the translucency factor.
180                This value must be multiplied with the translucency color
181                to get the real translucency color.
182                This value is used in all lighting models.
183                @return The translucency factor. */
184        inline const float& GetTranslucencyFactor() const { return translucencyFactor; }
185
186        /** Sets the translucency factor.
187                @param factor The translucency factor. */
188        inline void SetTranslucencyFactor(float factor) { translucencyFactor = factor; }
189
190        /** Retrieves the flat opacity.
191                This is a calculated value and will not take into consideration any animations
192                that affect either the base translucency color or the translucency factor.
193                This value can be used in all lighting models.
194                @return The flat opacity. */
195        float GetOpacity() const;
196
197        /** Retrieves the base emission/self-illumination color.
198                This value must be multiplied with the emission factor to get the real emission color.
199                This value is used in all lighting models.
200                @return The base emission color. */
201        inline const FMVector3& GetEmissionColor() const { return emissionColor; }
202
203        /** Sets the base emission/self-illumination color.
204                @param color The base emission color. */
205        inline void SetEmissionColor(const FMVector3& color) { emissionColor = color; }
206
207    /** Retrieves the emission/self-illumination factor.
208                This value must be multiplied with the base emission color to get the real emission color.
209                @return The emission factor. */
210        inline const float& GetEmissionFactor() const { return emissionFactor; }
211
212        /** Sets the emission/self-illumination factor.
213                @param factor The emission factor. */
214        inline void SetEmissionFactor(float factor) { emissionFactor = factor; }
215
216        /** Retrieves whether the emission factor was used, rather than the emission color.
217                This value is used in conjunction with 3dsMax, in which the self-illumination color
218                and the self-illumination factor are mutually exclusive.
219                @return Whether the emission factor is to be used. */
220        inline bool IsEmissionFactor() const { return isEmissionFactor; }
221
222        /** Sets whether the emission factor is to be used, rather than the emission color.
223                This value is used in conjunction with 3dsMax, in which the self-illumination color
224                and the self-illumination factor are mutually exclusive.
225                @param useFactor Whether the emission factor should be used. */
226        inline void SetIsEmissionFactor(bool useFactor) { isEmissionFactor = useFactor; }
227
228        /** Retrieves the diffuse color.
229                This value is used in the Lambert lighting model.
230                @return The diffuse color. */
231        inline const FMVector3& GetDiffuseColor() const { return diffuseColor; }
232
233        /** Sets the diffuse color.
234                @param color The diffuse color. */
235        inline void SetDiffuseColor(const FMVector3& color) { diffuseColor = color; }
236
237        /** Retrieves the ambient color.
238                This value is used in the Lambert lighting model.
239                @return The ambient color. */
240        inline const FMVector3& GetAmbientColor() const { return ambientColor; }
241
242        /** Sets the ambient color.
243                @param color The ambient color. */
244        inline void SetAmbientColor(const FMVector3& color) { ambientColor = color; }
245
246        /** Retrieves the base specular color.
247                This value must be multiplied with the specular factor
248                to get the real specular color.
249                This value is used in the Phong and Blinn lighting models.
250                @return The specular color. */
251        inline const FMVector3& GetSpecularColor() const { return specularColor; }
252
253        /** Sets the specular color.
254                @param color The specular color. */
255        inline void SetSpecularColor(const FMVector3& color) { specularColor = color; }
256
257        /** Retrieves the specular factor.
258                This value must be multiplied with the base specular color
259                to get the real specular color.
260                This value is used in the Phong and Blinn lighting models.
261                @return The specular factor. */
262        inline const float& GetSpecularFactor() const { return specularFactor; }
263
264        /** Sets the specular factor.
265                @param factor The specular factor. */
266        inline void SetSpecularFactor(float factor) { specularFactor = factor; }
267
268        /** Retrieves the specular shininess.
269                This value represents the exponent to which you must raise
270                the dot-product between the view vector and reflected light vectors:
271                as such, it is usually a number greater than 1.
272                This value is used in the Phong and Blinn lighting models.
273                @return The specular shininess. */
274        inline const float& GetShininess() const { return shininess; }
275
276        /** Sets the specular shininess.
277                This value represents the exponent to which you must raise
278                the dot-product between the view vector and reflected light vectors:
279                as such, it is usually a number greater than 1.
280                @param _shininess The specular shininess. */
281        inline void SetShininess(float _shininess) { shininess = _shininess; }
282
283        /** Retrieves the base reflectivity color.
284                This value must be multiplied to the reflectivity factor to
285                get the real reflectivity color.
286                This value is used in the Phong and Blinn lighting models.
287                @return The base reflectivity color. */
288    inline const FMVector3& GetReflectivityColor() const { return reflectivityColor; }
289
290        /** Sets the base reflectivity color.
291                @param color The base reflectivity color. */
292        inline void SetReflectivityColor(const FMVector3& color) { reflectivityColor = color; }
293       
294        /** Retrieves the reflectivity factor.
295                This value must be multiplied to the base reflectivity color
296                to get the real reflectivity color.
297                This value is used in the Phong and Blinn lighting models.
298                @return The reflectivity factor. */
299        inline const float& GetReflectivityFactor() const { return reflectivityFactor; }
300
301        /** Sets the reflectivity factor.
302                @param factor The reflectivity factor. */
303        inline void SetReflectivityFactor(float factor) { reflectivityFactor = factor; }
304
305        /** Retrieves the flat reflectivity.
306                This is a calculated value and will not take into consideration any animations
307                that affect either the base reflectivity color or the reflectivity factor.
308                This value can be used in the Phong and Blinn lighting models.
309                @return The flat reflectivity. */
310        float GetReflectivity() const;
311
312        /** Retrieves the 'faceted' flag.
313                This flag is used in conjunction with 3dsMax. It represents whether all the edges
314                of the polygon sets using this effect profile should be hard. The final result
315                of using this flag is a mesh where all the faces stand out.
316                @return The status of the 'faceted' flag. */
317    inline bool GetFacetedFlag() const { return isFaceted; }
318
319        /** Sets the 'faceted' flag.
320                This flag is used in conjunction with 3dsMax. It represents whether all the edges
321                of the polygon sets using this effect profile should be hard. The final result
322                of using this flag is a mesh where all the faces stand out.
323                @param flag The status of the 'faceted' flag. */
324        inline void SetFacetedFlag(bool flag) { isFaceted = flag; }
325
326        /** Retrieves the 'double-sided' flag.
327                This flag is used in conjunction with 3dsMax. It represents whether all the faces
328                of the polygon sets should be treated as two-sided and have normals in both directions.
329                @return The status of the 'double-sided' flag. */
330        inline bool GetDoubleSidedFlag() const { return isDoubleSided; }
331
332        /** Sets the 'double-sided' flag.
333                This flag is used in conjunction with 3dsMax. It represents whether all the faces
334                of the polygon sets should be treated as two-sided and have normals in both directions.
335                @param flag The status of the 'double-sided' flag. */
336        inline bool SetDoubleSidedFlag(bool flag) { isDoubleSided = flag; }
337
338        /** Retrieves the 'wireframe' flag.
339                This flag is used in conjunction with 3dsMax. It represents whether all the edges
340                of the polygon sets should be rendered, rather than the faces.
341                @return The status of the 'wireframe' flag. */
342        inline bool GetWireframeFlag() const { return isWireframe; }
343
344        /** Sets the 'wireframe' flag.
345                This flag is used in conjunction with 3dsMax. It represents whether all the edges
346                of the polygon sets should be rendered, rather than the faces.
347                @param flag The status of the 'wireframe' flag. */
348        inline bool SetWireframeFlag(bool flag) { isWireframe = flag; }
349
350        /** Retrieves the 'face-map' flag.
351                This is a pure 3dsMax flag and I have no idea what it does.
352                @return The status of the 'face-map' flag. */
353        inline bool GetFaceMapFlag() const { return isFaceMap; }
354
355        /** Sets the 'face-map' flag.
356                This is a pure 3dsMax flag and I have no idea what it does.
357                @param flag The status of the 'face-map' flag. */
358        inline void SetFaceMapFlag(bool flag) { isFaceMap = flag; }
359
360        /** Retrieves an effect parameter.
361                Looks for the effect parameter with the correct semantic, in order to bind or override its value.
362                This function searches through the effect profile and the level of abstractions below.
363                @param semantic The effect parameter semantic to match.
364                @return The effect parameter that matches the semantic. This pointer may be
365                        NULL if no effect parameter matches the given semantic. */
366        virtual FCDEffectParameter* FindParameterBySemantic(const string& semantic);
367
368        /** Retrieves a subset of the effect parameter list.
369                Look for effect parameters with the correct semantic.
370                This function searches through the effect profile and the level of abstractions below.
371                @param semantic The effect parameter semantic to match.
372                @param parameters The list of parameters to fill in. This list is not cleared. */
373        virtual void FindParametersBySemantic(const string& semantic, FCDEffectParameterList& parameters);
374
375        /** Retrieves a subset of the effect parameter list.
376                Look for effect parameters with the correct reference.
377                This function searches through the effect profile and the level of abstractions below.
378                @param reference The effect parameter reference to match. In the case of effect
379                        parameter, the reference is replaced by the sub-id.
380                @param parameters The list of parameters to fill in. This list is not cleared. */
381        virtual void FindParametersByReference(const string& reference, FCDEffectParameterList& parameters);
382
383        /** [INTERNAL] Clones the COMMON profile effect.
384                You will need release the cloned effect directly, by deleting the pointer.
385                @param newParent The effect that contains the cloned effect profile.
386                @return The cloned effect profile. You will must delete this pointer. */
387        virtual FCDEffectProfile* Clone(FCDEffect* newParent);
388
389        /** [INTERNAL] Flattens the profile.
390                Does nothing on the common profile. */
391        virtual void Flatten() {}
392
393        /** [INTERNAL] Reads in the \<profile_COMMON\> element from a given COLLADA XML tree node.
394                For COLLADA 1.3 backward-compatibility, this function can also read in \<material\> elements.
395                @param baseNode The COLLADA XML tree node.
396                @return The status of the import. If the status is not successful,
397                        it may be dangerous to extract information from the effect profile.*/
398        virtual FUStatus LoadFromXML(xmlNode* baseNode);
399
400        /** [INTERNAL] Writes out the \<profile_COMMON\> element to the given COLLADA XML tree node.
401                @param parentNode The COLLADA XML parent node in which to insert the effect profile.
402                @return The created element XML tree node. */
403        virtual xmlNode* WriteToXML(xmlNode* parentNode) const;
404
405private:
406        xmlNode* WriteColorTextureParameterToXML(xmlNode* parentNode, const char* parameterNodeName, const FMVector3& value, const FCDTextureList& textureBucket) const;
407        xmlNode* WriteFloatTextureParameterToXML(xmlNode* parentNode, const char* parameterNodeName, const float& value, const FCDTextureList& textureBucket) const;
408        xmlNode* WriteTextureParameterToXML(xmlNode* parentNode, const FCDTextureList& textureBucket) const;
409
410        FUStatus ParseColorTextureParameter(xmlNode* parameterNode, FMVector3& value, FCDTextureList& textureBucket);
411        FUStatus ParseFloatTextureParameter(xmlNode* parameterNode, float& value, FCDTextureList& textureBucket);
412        FUStatus ParseSimpleTextureParameter(xmlNode* parameterNode, FCDTextureList& textureBucket);
413};
414
415#endif //_FCD_MATERIAL_STANDARD_H_
416
Note: See TracBrowser for help on using the repository browser.