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

Revision 964, 20.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 FCDTexture.h
14        This file contains the FCDTexture class.
15*/
16
17#ifndef _FCD_TEXTURE_H_
18#define _FCD_TEXTURE_H_
19
20#include "FCDocument/FCDEntity.h"
21#include "FUtils/FUDaeEnum.h"
22
23class FCDocument;
24class FCDEffectParameter;
25class FCDEffectParameterInt;
26class FCDEffectParameterList;
27class FCDImage;
28
29/**
30        A COLLADA texture.
31       
32        Textures are used by the COMMON profile materials. For COLLADA 1.3 backward
33        compatibility, the textures may also be entities contained within
34        the material library. The ColladaFX profiles use the FCDEffectParameterSampler
35        and the FCDEffectParameterSurface classes, instead, to hold the texturing information.
36
37        Textures hold the information necessary to place an image onto polygon sets.
38        This information includes: which texture coordinate set to use, which image
39        contains the texels, the blend mode, the components of the texture matrix, etc.
40
41        Most of the texturing information does not belong to COLLADA and is specific to
42        either Maya or 3dsMax.
43
44        @ingroup FCDEffect
45*/
46class FCOLLADA_EXPORT FCDTexture : public FCDEntity
47{
48private:
49        DeclareObjectType;
50
51        FUDaeTextureChannel::Channel textureChannel; // COLLADA 1.3 backward compatibility
52        FCDImage* image;
53        string subId;
54
55        // Always preset, this parameter hold the map channel/uv set index
56        FCDEffectParameterInt* set;
57
58        // Texture color multiplier
59        float multiplier; // Max-specific
60
61        // Placement parameters. Yes, there's a ton of them [Maya-only]
62        bool hasProjection3D;
63        bool hasPlacement2D;
64        FUDaeBlendMode::Mode blendMode;
65
66        // 2D placement [Maya-only]
67        float wrapU, wrapV, mirrorU, mirrorV, stagger, fast; // animated, but should really be booleans
68        float coverageU, coverageV, translateFrameU, translateFrameV, rotateFrame;
69        float repeatU, repeatV, offsetU, offsetV, rotateUV, noiseU, noiseV;
70
71        // 3D projection [Maya-only]
72        FMMatrix44 projectionMatrix;
73        fstring projectionType;
74
75public:
76        /** Constructor: do not use directly.
77                Instead, use the FCDEffectStandard::AddTexture function.
78                @param document The COLLADA document that owns this texture. */
79        FCDTexture(FCDocument* document);
80
81        /** Destructor: do not use directly.
82                Instead, use the FCDEffectStandard::ReleaseTexture function. */
83        virtual ~FCDTexture();
84
85        /** Retrieves the type of the entity class.
86                This function is part of the FCDEntity interface and is used
87                for COLLADA 1.3 backward compatibility.
88                @return The entity class type: TEXTURE. */
89        virtual Type GetType() const { return TEXTURE; }
90
91        /** Retrieves which texture channel to use for this texture.
92                As it is directly tied in with which buckets holds this texture, you
93                cannot modify this value. Instead, create a new texture in the correct
94                bucket of the FCDEffectStandard object.
95                @return The texture channel. */
96        FUDaeTextureChannel::Channel GetTextureChannel() const { return textureChannel; }
97
98        /** Retrieves the image information for this texture.
99                @return The image. This pointer will be NULL if this texture is not yet
100                        tied to a valid image. */
101        FCDImage* GetImage() { return image; }
102        const FCDImage* GetImage() const { return image; } /**< See above. */
103
104        /** Sets the image to be used with this texture.
105                @param _image An image. */
106        void SetImage(FCDImage* _image) { image = _image; }
107
108        /** Retrieves the texture coordinate set to use with this texture.
109                This information is duplicated from the material instance abstraction level.
110                @return The effect parameter containing the set. */
111        FCDEffectParameterInt* GetSet() { return set; }
112        const FCDEffectParameterInt* GetSet() const { return set; } /**< See above. */
113
114        /** Retrieves the blend mode to use if this texture is not the first one
115                within its channel's bucket.
116                @return The blend mode. */
117        FUDaeBlendMode::Mode GetBlendMode() const { return blendMode; }
118
119        /** Sets the blend mode to use if this texture is not the first one
120                within its channel's bucket.
121                @param mode The blend mode. */
122        void SetBlendMode(FUDaeBlendMode::Mode mode) { blendMode = mode; }
123
124        /** @deprecated Retrieves the sub-id of the texture.
125                @return The sub-id. */
126        const string& GetSubId() const { return subId; }
127
128        /** @deprecated Sets the sub-id of the texture.
129                @param _subId The sub-id. */
130        void SetSubId(const string& _subId) { subId = _subId; }
131
132        /** Retrieves the generic multiplier to apply on the texture.
133                This parameter is specific to ColladaMax. The meaning of this parameter
134                depends on the channel that the texture belongs to.
135                This value is animatable.
136                @return The generic multiplier. */
137        float& GetMultiplier() { return multiplier; }
138        const float& GetMultiplier() const { return multiplier; } /**< See above. */
139
140        /** Sets the generic multiplier.
141                This parameter is specific to ColladaMax. The meaning of this parameter
142                depends on the channel that the texture belongs to.
143                @param _multiplier The generic multiplier. */
144        void SetMultiplier(float _multiplier) { multiplier = _multiplier; }
145
146        /** Retrieves whether the texturing information includes the
147                ColladaMaya-specific 2D placement parameters.
148                @return Whether the ColladaMaya-specific 2D placement parameters are valid. */
149        bool HasPlacement2D() const { return hasPlacement2D; }
150
151        /** Removes the ColladaMaya-specific 2D placement parameters and resets them. */
152        void ClearPlacement2D();
153
154        /** Retrieves whether to wrap the U texture coordinates.
155                This parameter is specific to ColladaMaya. This value is a float because
156                it is animatable: it should be interpreted as a boolean.
157                @return Whether to wrap the U texture coordinates. */
158        float& GetWrapU() { return wrapU; }
159        const float& GetWrapU() const { return wrapU; } /**< See above. */
160
161        /** Sets whether to wrap the U texture coordinates.
162                This parameter is specific to ColladaMaya.
163                @param _wrapU Whether to wrap the U texture coordinate. */
164        void SetWrapU(bool _wrapU) { wrapU = _wrapU ? 1.0f : 0.0f; hasPlacement2D = true; }
165
166        /** Retrieves whether to wrap the V texture coordinates.
167                This parameter is specific to ColladaMaya. This value is a float because
168                it is animatable: it should be interpreted as a boolean.
169                @return Whether to wrap the V texture coordinates. */
170        float& GetWrapV() { return wrapV; }
171        const float& GetWrapV() const { return wrapV; } /**< See above. */
172
173        /** Sets whether to wrap the V texture coordinates.
174                This parameter is specific to ColladaMaya.
175                @param _wrapV Whether to wrap the V texture coordinate. */
176        void SetWrapV(bool _wrapV) { wrapV = _wrapV ? 1.0f : 0.0f; hasPlacement2D = true; }
177
178        /** Retrieves whether to mirror the U texture coordinates.
179                This parameter is specific to ColladaMaya. This value is a float
180                because it is animatable: it should be interpreted as a boolean.
181                @return Whether to mirror the U texture coordinate. */
182        float& GetMirrorU() { return mirrorU; }
183        const float& GetMirrorU() const { return mirrorU; } /**< See above. */
184
185        /** Sets whether to mirror the U texture coordinates.
186                This parameter is specific to ColladaMaya.
187                @param _mirrorU Whether to mirror the U texture coordinates. */
188        void SetMirrorU(bool _mirrorU) { mirrorU = _mirrorU ? 1.0f : 0.0f; hasPlacement2D = true; }
189
190        /** Retrieves whether to mirror the V texture coordinates.
191                This parameter is specific to ColladaMaya. This value is a float
192                because it is animatable: it should be interpreted as a boolean.
193                @return Whether to mirror the V texture coordinate. */
194        float& GetMirrorV() { return mirrorV; }
195        const float& GetMirrorV() const { return mirrorV; } /**< See above. */
196
197        /** Sets whether to mirror the V texture coordinates.
198                This parameter is specific to ColladaMaya.
199                @param _mirrorV Whether to mirror the V texture coordinates. */
200        void SetMirrorV(bool _mirrorV) { mirrorV = _mirrorV ? 1.0f : 0.0f; hasPlacement2D = true; }
201
202        /** Retrieves whether to stagger the texture.
203                This parameter is specific to ColladaMaya. This value is a float
204                because it is animatable: it should be interpreted as a boolean.
205                @return Whether to stagger the texture. */
206        float& GetStagger() { return stagger; }
207        const float& GetStagger() const { return stagger; } /**< See above. */
208
209        /** Sets whether to stagger the texture.
210                This parameter is specific to ColladaMaya.
211                @param _stagger Whether to stagger the texture. */
212        void SetStagger(bool _stagger) { stagger = _stagger ? 1.0f : 0.0f; hasPlacement2D = true; }
213
214        /** Retrieves the 'fast' flag.
215                This parameter is specific to ColladaMaya. This value is a float
216                because it is animatable: it should be interpreted as a boolean.
217                This parameter has no meaning outside of Maya.
218                @return The 'fast' flag. */
219        float& GetFast() { return fast; }
220        const float& GetFast() const { return fast; } /**< See above. */
221
222        /** Sets the 'fast' flag.
223                This parameter is specific to ColladaMaya and has no meaning
224                outside of Maya.
225                @param _fast The 'fast' flag. */
226        void SetFast(bool _fast) { fast = _fast ? 1.0f : 0.0f; hasPlacement2D = true; }
227
228        /** Retrieves the scale factor of the texture frame, in the U coordinates.
229                This parameter is specific to ColladaMaya.
230                This value is animatable. For more information on this parameter,
231                check the Maya documentation.
232                @return The scale factor. */
233        float& GetCoverageU() { return coverageU; }
234        const float& GetCoverageU() const { return coverageU; } /**< See above. */
235
236        /** Sets the scale factor of the texture frame, in the U coordinates.
237                This parameter is specific to ColladaMaya.
238                @param _coverageU The scale factor. */
239        void SetCoverageU(float _coverageU) { coverageU = _coverageU; hasPlacement2D = true; }
240
241        /** Retrieves the scale factor of the texture frame, in the V coordinates.
242                This parameter is specific to ColladaMaya.
243                This value is animatable. For more information on this parameter,
244                check the Maya documentation.
245                @return The scale factor. */
246        float& GetCoverageV() { return coverageV; }
247        const float& GetCoverageV() const { return coverageV; } /**< See above. */
248
249        /** Sets the scale factor of the texture frame, in the V coordinates.
250                This parameter is specific to ColladaMaya.
251                @param _coverageV The scale factor. */
252        void SetCoverageV(float _coverageV) { coverageV = _coverageV; hasPlacement2D = true; }
253
254        /** Retrieves the translation of the texture frame, in the U coordinate.
255                This parameter is specific to ColladaMaya.
256                This value is animatable. For more information on this parameter,
257                check the Maya documentation.
258                @return The translation offset. */
259        float& GetTranslateFrameU() { return translateFrameU; }
260        const float& GetTranslateFrameU() const { return translateFrameU; } /**< See above. */
261
262        /** Sets the translation of the texture frame, in the U coordinate.
263                This parameter is specific to ColladaMaya.
264                For more information on this parameter, check the Maya documentation.
265                @param _translateFrameU The translation offset. */
266        void SetTranslateFrameU(float _translateFrameU) { translateFrameU = _translateFrameU; hasPlacement2D = true; }
267
268        /** Retrieves the translation of the texture frame, in the V coordinate.
269                This parameter is specific to ColladaMaya.
270                This value is animatable. For more information on this parameter,
271                check the Maya documentation.
272                @return The translation offset. */
273        float& GetTranslateFrameV() { return translateFrameV; }
274        const float& GetTranslateFrameV() const { return translateFrameV; } /**< See above. */
275
276        /** Sets the translation of the texture frame, in the V coordinate.
277                This parameter is specific to ColladaMaya.
278                For more information on this parameter, check the Maya documentation.
279                @param _translateFrameV The translation offset. */
280        void SetTranslateFrameV(float _translateFrameV) { translateFrameV = _translateFrameV; hasPlacement2D = true; }
281
282        /** Retrieves the angle of rotation of the texture frame.
283                This parameter is specific to ColladaMaya.
284                This value is animatable. For more information on this parameter,
285                check the Maya documentation.
286                @return The angle of rotation (in degrees). */
287        float& GetRotateFrame() { return rotateFrame; }
288        const float& GetRotateFrame() const { return rotateFrame; } /**< See above. */
289
290        /** Sets the angle of rotation of the texture frame.
291                This parameter is specific to ColladaMaya.
292                For more information on this parameter, check the Maya documentation.
293                @param _rotateFrame The angle of rotation (in degrees). */
294        void SetRotateFrame(float _rotateFrame) { rotateFrame = _rotateFrame; hasPlacement2D = true; }
295
296        /** Retrieves the scale factor applied on the U coordinates of the rendered polygons.
297                This parameter is specific to ColladaMaya. This value is animatable.
298                @return The scale factor. */
299        float& GetRepeatU() { return repeatU; }
300        const float& GetRepeatU() const { return repeatU; } /**< See above. */
301
302        /** Sets the scale factor applied on the U coordinates of the rendered polygons.
303                This parameter is specific to ColladaMaya.
304                @param _repeatU The scale factor. */
305        void SetRepeatU(float _repeatU) { repeatU = _repeatU; hasPlacement2D = true; }
306
307        /** Retrieves the scale factor applied on the V coordinates of the rendered polygons.
308                This parameter is specific to ColladaMaya. This value is animatable.
309                @return The scale factor. */
310        float& GetRepeatV() { return repeatV; }
311        const float& GetRepeatV() const { return repeatV; } /**< See above. */
312
313        /** Sets the scale factor applied on the V coordinates of the rendered polygons.
314                This parameter is specific to ColladaMaya.
315                @param _repeatV The scale factor. */
316        void SetRepeatV(float _repeatV) { repeatV = _repeatV; hasPlacement2D = true; }
317
318        /** Retrieves the translation offset applied on the U coordinates of the rendered polygons.
319                This parameter is specific to ColladaMaya. This value is animatable.
320                @return The translation offset. */
321        float& GetOffsetU() { return offsetU; }
322        const float& GetOffsetU() const { return offsetU; } /**< See above. */
323
324        /** Sets the translation offset applied on the U coordinates of the rendered polygons.
325                This parameter is specific to ColladaMaya.
326                @param _offsetU The translation offset. */
327        void SetOffsetU(float _offsetU) { offsetU = _offsetU; hasPlacement2D = true; }
328
329        /** Retrieves the translation offset applied on the V coordinates of the rendered polygons.
330                This parameter is specific to ColladaMaya. This value is animatable.
331                @return The translation offset. */
332        float& GetOffsetV() { return offsetV; }
333        const float& GetOffsetV() const { return offsetV; } /**< See above. */
334
335        /** Sets the translation offset applied on the V coordinates of the rendered polygons.
336                This parameter is specific to ColladaMaya.
337                @param _offsetV The translation offset. */
338        void SetOffsetV(float _offsetV) { offsetV = _offsetV; hasPlacement2D = true; }
339
340        /** Retrieves the rotation angle applied on the texture coordinates of the rendered polygons.
341                This parameter is specific to ColladaMaya. This value is animatable.
342                @return The rotation angle (in degrees). */
343        float& GetRotateUV() { return rotateUV; }
344        const float& GetRotateUV() const { return rotateUV; } /**< See above. */
345
346        /** Sets the rotation angle applied on the texture coordinates of the rendered polygons.
347                This parameter is specific to ColladaMaya. This value is animatable.
348                @param _rotateUV The rotation angle (in degrees). */
349        void SetRotateUV(float _rotateUV) { rotateUV = _rotateUV; hasPlacement2D = true; }
350
351        /** Retrieves the maxmimum amount of noise to add to each of the U coordinates of the rendered polygons.
352                This parameter is specific to ColladaMaya. This value is animatable.
353                @return The maxmimum amount of noise. */
354        float& GetNoiseU() { return noiseU; }
355        const float& GetNoiseU() const { return noiseU; } /**< See above. */
356
357        /** Sets the maximum amount of noise to add to each of the U coordinates of the rendered polygons.
358                This parameter is specific to ColladaMaya.
359                @param _noiseU The maximum amount of noise. */
360        void SetNoiseU(float _noiseU) { noiseU = _noiseU; hasPlacement2D = true; }
361
362        /** Retrieves the maxmimum amount of noise to add to each of the V coordinates of the rendered polygons.
363                This parameter is specific to ColladaMaya. This value is animatable.
364                @return The maxmimum amount of noise. */
365        float& GetNoiseV() { return noiseV; }
366        const float& GetNoiseV() const { return noiseV; } /**< See above. */
367
368        /** Sets the maximum amount of noise to add to each of the V coordinates of the rendered polygons.
369                This parameter is specific to ColladaMaya.
370                @param _noiseV The maximum amount of noise. */
371        void SetNoiseV(float _noiseV) { noiseV = _noiseV; hasPlacement2D = true; }
372
373        /** Retrieves whether the texturing information includes the
374                ColladaMaya-specific 3D projection parameters.
375                @return Whether the ColladaMaya-specific 3D projection parameters are valid. */
376        bool HasProjection3D() const { return hasProjection3D; }
377
378        /** Removes the ColladaMaya-specific 3D projection parameters and resets them. */
379        void ClearProjection3D();
380
381        /** Retrieves the texture projection matrix.
382                This matrix transforms the 3D texture coordinates into valid 2D texture coordinates.
383                This parameter is specific to ColladaMaya.
384                @return The texture projection matrix. */
385        FMMatrix44& GetProjectionMatrix() { return projectionMatrix; }
386        const FMMatrix44& GetProjectionMatrix() const { return projectionMatrix; } /**< See above. */
387
388        /** Sets the texture projection matrix.
389                This matrix transforms the 3D texture coordinates into valid 2D texture coordinates.
390                This parameter is specific to ColladaMaya.
391                @param matrix The texture projection matrix. */
392        void SetProjectionMatrix(const FMMatrix44& matrix) { projectionMatrix = matrix; hasProjection3D = true; }
393       
394        /** Retrieves the type of projection to use on the 3D texture coordinates.
395                This parameter is specific to ColladaMaya.
396                @return The type string. */
397        const fstring& GetProjectionType() const { return projectionType; }
398
399        /** Sets the type of projection to use on the 3D texture coordinates.
400                This paramter is specific to ColladaMaya.
401                @param type The type string. */
402        void SetProjectionType(const fstring& type) { projectionType = type; hasProjection3D = true; }
403
404        /** Retrieves an effect parameter.
405                Looks for the effect parameter with the correct semantic, in order to bind or override its value.
406                This function compares the local effect parameters with the given semantic.
407                @param semantic The effect parameter semantic to match.
408                @return The effect parameter that matches the semantic. This pointer may be
409                        NULL if no effect parameter matches the given semantic. */
410        FCDEffectParameter* FindParameterBySemantic(const string& semantic);
411
412        /** Retrieves a subset of the local effect parameter list.
413                Look for local effect parameters with the correct semantic.
414                This function searches through the effect profile and the level of abstractions below.
415                @param semantic The effect parameter semantic to match.
416                @param parameters The list of parameters to fill in. This list is not cleared. */
417        void FindParametersBySemantic(const string& semantic, FCDEffectParameterList& parameters);
418
419        /** Retrieves a subset of the local effect parameter list.
420                Look for the local effect parameter with the correct reference.
421                @param reference The effect parameter reference to match.
422                @param parameters The list of parameters to fill in. This list is not cleared. */
423        void FindParametersByReference(const string& reference, FCDEffectParameterList& parameters);
424
425        /** [INTERNAL] Clones the texture.
426                Does not clone the image: both texture objects will point to the same image object.
427                @return The cloned texture. This pointer will never be NULL. */
428        FCDTexture* Clone();
429
430        /** [INTERNAL] Reads in the texture from a given COLLADA XML tree node.
431                @param textureNode The COLLADA XML tree node.
432                @return The status of the import. If the status is not successful,
433                        it may be dangerous to extract information from the texture.*/
434        FUStatus LoadFromTextureXML(xmlNode* textureNode);
435
436        /** [INTERNAL] Reads in the texture from a given COLLADA XML tree node.
437                This function is useful only for COLLADA 1.3 backward compatibility.
438                @param textureNode The COLLADA XML tree node.
439                @return The status of the import. If the status is not successful,
440                        it may be dangerous to extract information from the texture.*/
441        virtual FUStatus LoadFromXML(xmlNode* textureNode);
442
443        /** [INTERNAL] Writes out the texture to the given COLLADA XML tree node.
444                @param parentNode The COLLADA XML parent node in which to insert the texture.
445                @return The created element XML tree node. */
446        virtual xmlNode* WriteToXML(xmlNode* parentNode);
447
448private:
449        // Read in the Maya-specific texture placement parameters and look for a texture projection program
450        FUStatus LoadPlacementXML(xmlNode* techniqueNode);
451};
452
453#endif // _FCD_TEXTURE_H_
Note: See TracBrowser for help on using the repository browser.