2
Copyright (c) 2008-2009 NetAllied Systems GmbH
4
This file is part of COLLADAMax.
6
Portions of the code are:
7
Copyright (c) 2005-2007 Feeling Software Inc.
8
Copyright (c) 2005-2007 Sony Computer Entertainment America
10
Based on the 3dsMax COLLADASW Tools:
11
Copyright (c) 2005-2006 Autodesk Media Entertainment
13
Licensed under the MIT Open Source License,
14
for details please see LICENSE file or the website
15
http://www.opensource.org/licenses/mit-license.php
18
#ifndef __COLLADAMAX_MATERIALCREATOR_H__
19
#define __COLLADAMAX_MATERIALCREATOR_H__
21
#include "COLLADAMaxPrerequisites.h"
22
#include "COLLADAMaxImporterBase.h"
28
/** Creates and assigns all material previously been stored by the material and affect importers.*/
29
class MaterialCreator : public ImporterBase
32
/** A struct that uniquely identifies material created in Max.*/
33
struct MaterialIdentifier
43
EMISSION = 1<<4, //self-illumination
48
/** The unique id of the frame work effect this material has been created from.*/
49
COLLADAFW::UniqueId effectUniqueId;
51
/** Flags indication which slot uses a max channel.*/
52
unsigned char slotFlags;
54
unsigned char ambientMapChannel;
55
unsigned char diffuseMapChannel;
56
unsigned char specularMapChannel;
57
unsigned char shininessMapChannel;
58
unsigned char emissionMapChannel;
59
unsigned char opacityMapChannel;
61
unsigned char bumpMapChannel;
63
bool operator<( const MaterialIdentifier& rhs ) const;
66
/** Maps framework effects to max materials.*/
67
typedef std::map<MaterialIdentifier, Mtl*> MaterialIdentifierMaxMaterialMap;
70
/** Maps all the framework effects already created a max material for, to the max
72
MaterialIdentifierMaxMaterialMap mMaterialIdentifierMaxMaterialMap;
77
MaterialCreator( DocumentImporter* documentImporter );
80
virtual ~MaterialCreator();
82
/** Performs the creation of all material.
83
@return True on success, false otherwise.*/
86
/** Creates all the material referenced in @a materialBinding, if not already created and
87
assigns them to the node in @a materialBinding.*/
88
bool createAndAssingMaxMaterial( const DocumentImporter::NodeMaterialBindingsPair& materialBinding );
90
/** Creates a standard material from @a effectCommon.*/
91
StdMat2* createStandardMaterial( const COLLADAFW::EffectCommon& effectCommon, const String& name, const MaterialCreator::MaterialIdentifier& materialIdentifier, const EffectMaps* extraEffectMaps);
93
/** Creates a material from @a effect.*/
94
Mtl* createMaxMaterial( const COLLADAFW::Effect& effect, const MaterialCreator::MaterialIdentifier& materialIdentifier);
96
/** Returns the material created for @a effect. If for the same effect a max material has already been
97
created for, the formally created one is returned, otherwise a new one is created.*/
98
Mtl* getMaxMaterial( const COLLADAFW::Effect& effect, const COLLADAFW::MaterialBinding& materialBinding, const COLLADAFW::UniqueId& geometryUniqueId );
100
/** Returns the effect used by @a materialBinding. It resolves first the material and than the effect.
101
If the effect could not be resolved, null is returned.*/
102
const COLLADAFW::Effect* getEffect( const COLLADAFW::MaterialBinding& materialBinding );
104
/** Returns the MaterialIdentifierMaxMaterialMap.*/
105
const MaterialIdentifierMaxMaterialMap& getMaterialIdentifierMaxMaterialMap() const { return mMaterialIdentifierMaxMaterialMap; }
109
/** Disable default copy ctor. */
110
MaterialCreator( const MaterialCreator& pre );
112
/** Disable default assignment operator. */
113
const MaterialCreator& operator= ( const MaterialCreator& pre );
115
/** Creates a max texture from the frame work texture @a texture.*/
116
BitmapTex* createTexture( const COLLADAFW::EffectCommon& effectCommon, const COLLADAFW::Texture& texture );
118
BitmapTex* createTexture( const COLLADAFW::EffectCommon& effectCommon, const COLLADAFW::SamplerID& samplerId );
120
/** Assigns @a texture to @a slot of @a material.*/
121
void assignTextureToMaterial( Mtl* material, int slot, BitmapTex* texture);
123
void createAndAssignTexture( Mtl* material, const COLLADAFW::EffectCommon& effectCommon, const COLLADAFW::ColorOrTexture& (COLLADAFW::EffectCommon::*f)()const, int slot, unsigned char mapChannel);
125
void handleExtraEffectMaps( const EffectMaps* extraEffectMaps, Mtl* material, const COLLADAFW::EffectCommon& effectCommon, const MaterialCreator::MaterialIdentifier& materialIdentifier );
128
/** Sets the vertex color flag for all nodes that use vertex color.*/
129
void setVertexColorFlag();
134
} // namespace COLLADAMAX
136
#endif // __COLLADAMAX_MATERIALCREATOR_H__