[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 FCDMaterialInstance.h
|
---|
| 14 | This file contains the FCDMaterialInstance and the FCDMaterialInstanceBind classes.
|
---|
| 15 | */
|
---|
| 16 | |
---|
| 17 | #ifndef _FCD_MATERIAL_BIND_H_ |
---|
| 18 | #define _FCD_MATERIAL_BIND_H_ |
---|
| 19 | |
---|
| 20 | #include "FCDocument/FCDEntityInstance.h" |
---|
| 21 | |
---|
| 22 | class FCDocument; |
---|
| 23 | class FCDGeometryInstance; |
---|
| 24 | |
---|
| 25 | /** |
---|
| 26 | A ColladaFX per-instance binding. |
---|
| 27 | */ |
---|
| 28 | class FCOLLADA_EXPORT FCDMaterialInstanceBind |
---|
| 29 | { |
---|
| 30 | public: |
---|
| 31 | string semantic; |
---|
| 32 | string target; |
---|
| 33 | }; |
---|
| 34 | |
---|
| 35 | typedef vector<FCDMaterialInstanceBind> FCDMaterialInstanceBindList; /**< A dynamically-sized array of per-instance binding. */ |
---|
| 36 | |
---|
| 37 | /** |
---|
| 38 | A COLLADA material instance. |
---|
| 39 | A material instance is used to given polygon sets with a COLLADA material entity. |
---|
| 40 | It is also used to bind data sources with the inputs of an effect. |
---|
| 41 | |
---|
| 42 | @ingroup FCDocument |
---|
| 43 | */ |
---|
| 44 | class FCOLLADA_EXPORT FCDMaterialInstance : public FCDEntityInstance |
---|
| 45 | { |
---|
| 46 | private: |
---|
| 47 | DeclareObjectType; |
---|
| 48 | FCDGeometryInstance* parent; |
---|
| 49 | fstring semantic; |
---|
| 50 | FCDMaterial* material; |
---|
| 51 | FCDMaterialInstanceBindList bindings; |
---|
| 52 | |
---|
| 53 | public: |
---|
| 54 | FCDMaterialInstance(FCDocument* document, FCDGeometryInstance* parent); |
---|
| 55 | virtual ~FCDMaterialInstance(); |
---|
| 56 | |
---|
| 57 | // Accessors |
---|
| 58 | virtual Type GetType() const { return MATERIAL; } |
---|
| 59 | |
---|
| 60 | inline const fstring& GetSemantic() const { return semantic; } |
---|
| 61 | inline void SetSemantic(const fchar* _semantic) { semantic = _semantic; } |
---|
| 62 | inline void SetSemantic(const fstring& _semantic) { semantic = _semantic; } |
---|
| 63 | |
---|
| 64 | inline FCDMaterial* GetMaterial() { return material; } |
---|
| 65 | inline const FCDMaterial* GetMaterial() const { return material; } |
---|
| 66 | inline void SetMaterial(FCDMaterial* _material) { material = _material; } |
---|
| 67 | |
---|
| 68 | inline FCDMaterialInstanceBindList& GetBindings() { return bindings; } |
---|
| 69 | inline const FCDMaterialInstanceBindList& GetBindings() const { return bindings; } |
---|
| 70 | inline size_t GetBindingCount() const { return bindings.size(); } |
---|
| 71 | inline FCDMaterialInstanceBind* GetBinding(size_t index) { FUAssert(index < bindings.size(), return NULL); return &bindings.at(index); } |
---|
| 72 | inline const FCDMaterialInstanceBind* GetBinding(size_t index) const { FUAssert(index < bindings.size(), return NULL); return &bindings.at(index); } |
---|
| 73 | |
---|
| 74 | FCDMaterialInstanceBind* AddBinding(); |
---|
| 75 | FCDMaterialInstanceBind* AddBinding(const char* semantic, const char* target); |
---|
| 76 | inline FCDMaterialInstanceBind* AddBinding(const string& semantic, const char* target) { return AddBinding(semantic.c_str(), target); } |
---|
| 77 | inline FCDMaterialInstanceBind* AddBinding(const char* semantic, const string& target) { return AddBinding(semantic, target.c_str()); } |
---|
| 78 | inline FCDMaterialInstanceBind* AddBinding(const string& semantic, const string& target) { return AddBinding(semantic.c_str(), target.c_str()); } |
---|
| 79 | void ReleaseBinding(size_t index); |
---|
| 80 | |
---|
| 81 | /** Creates a flattened version of the instantiated material. This is the |
---|
| 82 | prefered way to generate viewer materials from a COLLADA document. |
---|
| 83 | @return The flattened version of the instantiated material. You |
---|
| 84 | will need to delete this pointer manually. This pointer will |
---|
| 85 | be NULL when there is no material attached to this instance. */ |
---|
| 86 | FCDMaterial* FlattenMaterial(); |
---|
| 87 | |
---|
| 88 | // Read in the materal instantiation from the COLLADA document |
---|
| 89 | virtual FUStatus LoadFromXML(xmlNode* instanceNode); |
---|
| 90 | FUStatus LoadFromId(const string& materialId); // COLLADA 1.3 backward compatibility |
---|
| 91 | |
---|
| 92 | // Write out the instantiation information to the xml node tree |
---|
| 93 | xmlNode* WriteToXML(xmlNode* parentNode) const; |
---|
| 94 | }; |
---|
| 95 | |
---|
| 96 | #endif // _FCD_MATERIAL_BIND_H_ |
---|