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

Revision 964, 5.6 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 FCDMaterialLibrary.h
14        This file contains the FCDMaterialLibrary.h.
15*/
16
17#ifndef _FCD_MATERIAL_LIBRARY_H_
18#define _FCD_MATERIAL_LIBRARY_H_
19
20class FCDocument;
21class FCDTexture;
22class FCDEffect;
23class FCDMaterial;
24
25typedef vector<FCDTexture*> FCDTextureList; /**< A dynamically-sized list of textures. */
26typedef vector<FCDEffect*> FCDEffectList; /**< A dynamically-sized list of effects. */
27typedef vector<FCDMaterial*> FCDMaterialList; /**< A dynamically-sized list of materials. */
28
29#include "FCDocument/FCDLibrary.h"
30
31/**
32        The shared COLLADA material and effect libraries.
33        This class covers the material and effect libraries, as well as the
34        texture library for COLLADA 1.3 backward compatibility.
35
36        @todo When information push is fully implemented: split the effect library out of this one.
37
38        @ingroup FCDocument
39*/
40class FCOLLADA_EXPORT FCDMaterialLibrary : public FCDLibrary<FCDEntity>
41{
42private:
43        FCDTextureList textures;
44        FCDEffectList effects;
45        FCDMaterialList materials;
46
47public:
48        /** Constructor: do not use directly.
49                The document object will create the one and only object of this class.
50                @param document The COLLADA document that owns this library. */
51        FCDMaterialLibrary(FCDocument* document);
52
53        /** Destructor: do not use directly.
54                The document object will release its libraries. */
55        virtual ~FCDMaterialLibrary();
56
57        /** Retrieves the list of effects contained by this library.
58                @return The list of effects. */
59        FCDEffectList& GetEffects() { return effects; }
60        const FCDEffectList& GetEffects() const { return effects; } /**< See above. */
61
62        /** Retrieves the number of effects contained by this library.
63                @return The number of effects within the library. */
64        size_t GetEffectCount() const { return effects.size(); }
65
66        /** Retrieves an effect contained by this library.
67                @param index The index of the effect.
68                @return The given effect. This pointer will be NULL if no effect matches the index. */
69        FCDEffect* GetEffect(size_t index) { FUAssert(index < GetEffectCount(), return NULL); return effects.at(index); }
70        const FCDEffect* GetEffect(size_t index) const { FUAssert(index < GetEffectCount(), return NULL); return effects.at(index); } /**< See above. */
71
72        /** [INTERNAL] Retrieves an effect contained by this library.
73                @param daeId The COLLADA id of the effect.
74                @return The matching effect. This pointer will be NULL if no effect matches the COLLADA id. */
75        FCDEffect* FindEffect(const string& daeId);
76
77        /** Creates a new effect.
78                @return The newly created effect. */
79        FCDEffect* AddEffect();
80
81        /** Releases an effect.
82                @todo Implement FCDMaterialLibrary::ReleaseEffect.
83                @param effect The effect to release. */
84        void ReleaseEffect(FCDEffect* effect);
85
86        /** Retrieves the list of materials contained by this library.
87                @return The list of materials. */
88        FCDMaterialList& GetMaterials() { return materials; }
89        const FCDMaterialList& GetMaterials() const { return materials; } /**< See above. */
90
91        /** Retrieves the number of materials contained by this library.
92                @return The number of materials within the library. */
93        size_t GetMaterialCount() const { return materials.size(); }
94
95        /** Retrieves a material contained by this library.
96                @param index The index of the material.
97                @return The given material. This pointer will be NULL if no material matches the index. */
98        FCDMaterial* GetMaterial(size_t index) { FUAssert(index < GetMaterialCount(), return NULL); return materials.at(index); }
99        const FCDMaterial* GetMaterial(size_t index) const { FUAssert(index < GetMaterialCount(), return NULL); return materials.at(index); } /**< See above. */
100
101        /** [INTERNAL] Retrieves a material contained by this library.
102                @param daeId The COLLADA id of the material.
103                @return The matching material. This pointer will be NULL
104                        if no material matches the COLLADA id. */
105        FCDMaterial* FindMaterial(const string& daeId);
106
107        /** [INTERNAL] Retrieves a texture contained by this library.
108                @param daeId The COLLADA id of the texture.
109                @return The matching texture. This pointer will be NULL
110                        if no texture matches the COLLADA id. */
111        FCDTexture* FindTexture(const string& daeId);
112       
113        /** Creates a new material.
114                @return The newly created material. */
115        FCDMaterial* AddMaterial();
116
117        /** Releases a material.
118                @todo Implement FCDMaterialLibrary::ReleaseMaterial.
119                @param material The material to release. */
120        void ReleaseMaterial(FCDMaterial* material);
121
122        /** [INTERNAL] Reads in the contents of the library from the COLLADA XML document.
123                This method will be called once for the effect library and once for the material library.
124                It may also be called once, for COLLADA 1.3 backward compatibility, for the texture library.
125                @param node The COLLADA XML tree node to parse into entities.
126                @return The status of the import. If the status is not successful, it may be dangerous to
127                        extract information from the library. */
128        virtual FUStatus LoadFromXML(xmlNode* node);
129
130        /** [INTERNAL] Writes out the library entities to the COLLADA XML document.
131                This method writes out the material library within the given node and
132                writes out the effect library as a sibling node to the given node.
133                @param libraryNode The COLLADA XML tree node in which to write the materials. */
134        virtual void WriteToXML(xmlNode* libraryNode) const;
135};
136
137#endif // _FCD_MATERIAL_LIBRARY_H_
138
Note: See TracBrowser for help on using the repository browser.