[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 FCDMaterial.h
|
---|
| 14 | This file contains the FCDMaterail class and the FCDMaterialTechniqueHint structure.
|
---|
| 15 | */
|
---|
| 16 |
|
---|
| 17 | #ifndef _FCD_MATERIAL_H_
|
---|
| 18 | #define _FCD_MATERIAL_H_
|
---|
| 19 |
|
---|
| 20 | #include "FCDocument/FCDEntity.h"
|
---|
| 21 |
|
---|
| 22 | class FCDocument;
|
---|
| 23 | class FCDEffect;
|
---|
| 24 | class FCDEffectParameter;
|
---|
| 25 | class FCDEffectParameterList;
|
---|
| 26 |
|
---|
| 27 | /**
|
---|
| 28 | A technique usage hint for a material.
|
---|
| 29 | This structure contains two strings to help applications
|
---|
| 30 | choose a technique within the material's instantiated effect
|
---|
| 31 | according to their application platform.
|
---|
| 32 | */
|
---|
| 33 | class FCOLLADA_EXPORT FCDMaterialTechniqueHint
|
---|
| 34 | {
|
---|
| 35 | public:
|
---|
| 36 | fstring platform; /**< A platform semantic. COLLADA defines no platform semantics. */
|
---|
| 37 | string technique; /**< The sid for the technique to choose for the platform. */
|
---|
| 38 | };
|
---|
| 39 |
|
---|
| 40 | /** A dynamically-sized list of material platform-technique hints. */
|
---|
| 41 | typedef vector<FCDMaterialTechniqueHint> FCDMaterialTechniqueHintList;
|
---|
| 42 |
|
---|
| 43 | /**
|
---|
| 44 | A COLLADA material.
|
---|
| 45 |
|
---|
| 46 | A COLLADA material is one of many abstraction level that defines how
|
---|
| 47 | to render mesh polygon sets. It instantiates an effect and may
|
---|
| 48 | overrides some of the effect parameters with its own values.
|
---|
| 49 |
|
---|
| 50 | Unless you care about the construction history or memory, you should probably
|
---|
| 51 | use the FCDMaterialInstance::FlattenMaterial function.
|
---|
| 52 |
|
---|
| 53 | @ingroup FCDocument
|
---|
| 54 | */
|
---|
| 55 | class FCOLLADA_EXPORT FCDMaterial : public FCDEntity
|
---|
| 56 | {
|
---|
| 57 | private:
|
---|
| 58 | DeclareObjectType;
|
---|
| 59 | bool ownsEffect;
|
---|
| 60 | FCDEffect* effect;
|
---|
| 61 | FCDEffectParameterList* parameters;
|
---|
| 62 | FCDMaterialTechniqueHintList techniqueHints;
|
---|
| 63 |
|
---|
| 64 | public:
|
---|
| 65 | /** Constructor: do not use directly.
|
---|
| 66 | Instead, use the FCDMaterialLibrary::AddMaterial function.
|
---|
| 67 | @param document The COLLADA document that owns the material. */
|
---|
| 68 | FCDMaterial(FCDocument* document);
|
---|
| 69 |
|
---|
| 70 | /** Destructor: do not use directly.
|
---|
| 71 | The material library will release all the materials when it is
|
---|
| 72 | released. If you want to remove a material from the material library:
|
---|
| 73 | use the FCDMaterialLibrary::RemoveMaterial function. */
|
---|
| 74 | virtual ~FCDMaterial();
|
---|
| 75 |
|
---|
| 76 | /** Retrieves the entity type for this class. This function is part
|
---|
| 77 | of the FCDEntity class interface.
|
---|
| 78 | @return The entity type: MATERIAL. */
|
---|
| 79 | virtual Type GetType() const { return FCDEntity::MATERIAL; }
|
---|
| 80 |
|
---|
| 81 | /** Retrieves the effect instantiated for this material.
|
---|
| 82 | The parameters of the effect may be overwritten by this material.
|
---|
| 83 | You should either flatten the material using the FlattenMaterial function
|
---|
| 84 | or verify the parameter values manually using the parameter list accessors.
|
---|
| 85 | @return The instantiated effect. This pointer will be NULL if the material has no rendering. */
|
---|
| 86 | FCDEffect* GetEffect() { return effect; }
|
---|
| 87 | const FCDEffect* GetEffect() const { return effect; } /**< See above. */
|
---|
| 88 |
|
---|
| 89 | /** Sets the effect instantiated for this material.
|
---|
| 90 | @param _effect The effect instantiated for this material. */
|
---|
| 91 | void SetEffect(FCDEffect* _effect) { effect = _effect; }
|
---|
| 92 |
|
---|
| 93 | /** Retrieves the list of the material platform-technique hints.
|
---|
| 94 | @return The list of material platform-technique hints. */
|
---|
| 95 | FCDMaterialTechniqueHintList& GetTechniqueHints() { return techniqueHints; }
|
---|
| 96 | const FCDMaterialTechniqueHintList& GetTechniqueHints() const { return techniqueHints; } /**< See above. */
|
---|
| 97 |
|
---|
| 98 | /** Retrieves the list of effect parameter overrides.
|
---|
| 99 | @return The list of effect parameter overrides. */
|
---|
| 100 | FCDEffectParameterList* GetParameters() { return parameters; }
|
---|
| 101 | const FCDEffectParameterList* GetParameters() const { return parameters; } /**< See above. */
|
---|
| 102 |
|
---|
| 103 | /** Retrieves an effect parameter override. Looks for the effect parameter override with the correct
|
---|
| 104 | semantic, in order to bind or set its value. This function searches through the material and the
|
---|
| 105 | level of abstractions below.
|
---|
| 106 | @param semantic The effect parameter semantic to match.
|
---|
| 107 | @return The effect parameter override that matches the semantic.
|
---|
| 108 | This pointer will be NULL if no effect parameter override matches
|
---|
| 109 | the given semantic. */
|
---|
| 110 | FCDEffectParameter* FindParameterBySemantic(const string& semantic);
|
---|
| 111 |
|
---|
| 112 | /** Retrieves a subset of the effect parameter override list.
|
---|
| 113 | Look for the effect parameter overrides with the correct semantic.
|
---|
| 114 | This function searches through the material and the level of abstractions below.
|
---|
| 115 | @param semantic The effect parameter semantic to match.
|
---|
| 116 | @param parameters The list of parameters to fill in. This list is not cleared. */
|
---|
| 117 | void FindParametersBySemantic(const string& semantic, FCDEffectParameterList& parameters);
|
---|
| 118 |
|
---|
| 119 | /** Retrieves a subset of the effect parameter override list.
|
---|
| 120 | Look for the effect parameter overrides with the correct reference.
|
---|
| 121 | This function searches through the material and the level of abstractions below.
|
---|
| 122 | @param reference The effect parameter reference to match. In the case of effect
|
---|
| 123 | parameter generators, the reference is replaced by the sub-id.
|
---|
| 124 | @param parameters The list of parameters to fill in. This list is not cleared. */
|
---|
| 125 | void FindParametersByReference(const string& reference, FCDEffectParameterList& parameters);
|
---|
| 126 |
|
---|
| 127 | /** [INTERNAL] Clones the material object. Everything is cloned, including the effect parameter.
|
---|
| 128 | You will need release the cloned material directly, by deleting the pointer.
|
---|
| 129 | @return The cloned material object. You will must delete this pointer. */
|
---|
| 130 | FCDMaterial* Clone();
|
---|
| 131 |
|
---|
| 132 | /** [INTERNAL] Flattens the material, pushing all the effect parameter overrides
|
---|
| 133 | into the effect parameter generators and moving all the parameters to the
|
---|
| 134 | effect technique level of abstraction. To flatten the material, use the
|
---|
| 135 | FCDMaterialInstance::FlattenMaterial function. */
|
---|
| 136 | void Flatten();
|
---|
| 137 |
|
---|
| 138 | /** [INTERNAL] Reads in the \<material\> element from a given COLLADA XML tree node.
|
---|
| 139 | @param materialNode The COLLADA XML tree node.
|
---|
| 140 | @return The status of the import. If the status is not successful,
|
---|
| 141 | it may be dangerous to extract information from the material.*/
|
---|
| 142 | virtual FUStatus LoadFromXML(xmlNode* materialNode);
|
---|
| 143 |
|
---|
| 144 | /** [INTERNAL] Writes out the \<material\> element to the given COLLADA XML tree node.
|
---|
| 145 | @param parentNode The COLLADA XML parent node in which to insert the material declaration.
|
---|
| 146 | @return The created element XML tree node. */
|
---|
| 147 | virtual xmlNode* WriteToXML(xmlNode* parentNode) const;
|
---|
| 148 |
|
---|
| 149 | private:
|
---|
| 150 | void AddParameter(FCDEffectParameter* parameter);
|
---|
| 151 | };
|
---|
| 152 |
|
---|
| 153 | #endif // _FCD_MATERIAL_H_
|
---|