00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_ANIMATED_MATERIAL_H
00027 #define NL_ANIMATED_MATERIAL_H
00028
00029
00030 #include "nel/misc/types_nl.h"
00031 #include "nel/misc/smart_ptr.h"
00032 #include "3d/animatable.h"
00033 #include "3d/material.h"
00034 #include "3d/track.h"
00035 #include <map>
00036
00037
00038 namespace NL3D
00039 {
00040
00041
00042
00043
00051 class CMaterialBase : public NLMISC::CRefCount
00052 {
00053 public:
00054
00055 CMaterialBase();
00056
00064 void copyFromMaterial(CMaterial *pMat);
00065
00066
00067
00068 std::string Name;
00069
00070
00071
00072 CTrackDefaultRGBA DefaultAmbient;
00073 CTrackDefaultRGBA DefaultDiffuse;
00074 CTrackDefaultRGBA DefaultSpecular;
00075 CTrackDefaultFloat DefaultShininess;
00076 CTrackDefaultRGBA DefaultEmissive;
00077 CTrackDefaultFloat DefaultOpacity;
00078 CTrackDefaultInt DefaultTexture;
00079
00080
00081 struct CTexAnimTracks
00082 {
00083
00084 CTrackDefaultFloat DefaultUTrans;
00085 CTrackDefaultFloat DefaultVTrans;
00086 CTrackDefaultFloat DefaultUScale;
00087 CTrackDefaultFloat DefaultVScale;
00088 CTrackDefaultFloat DefaultWRot;
00089
00090
00091
00092 enum { NumTexAnimatedValues = 5 };
00093
00094
00095 void setDefaultValue()
00096 {
00097 DefaultUTrans.setValue(0);
00098 DefaultVTrans.setValue(0);
00099 DefaultUScale.setValue(1);
00100 DefaultVScale.setValue(1);
00101 }
00102
00103 void serial(NLMISC::IStream &f)
00104 {
00105 (void)f.serialVersion(0);
00106 f.serial(DefaultUTrans, DefaultVTrans, DefaultUScale, DefaultVScale);
00107 }
00108 };
00109 CTexAnimTracks DefaultTexAnimTracks[IDRV_MAT_MAXTEXTURES];
00110
00112 void serial(NLMISC::IStream &f);
00113
00114
00116
00122
00124
00126
00128
00129
00130
00131
00132
00133 private:
00134
00135 struct CAnimatedTexture
00136 {
00137 CSmartPtr<ITexture> Texture;
00138
00139
00140 void serial(NLMISC::IStream &f);
00141 };
00142
00143 typedef std::map<uint32, CAnimatedTexture> TAnimatedTextureMap;
00144 TAnimatedTextureMap _AnimatedTextures;
00145
00146 };
00147
00148
00149
00150
00159 class CAnimatedMaterial : public IAnimatable
00160 {
00161 public:
00162
00164
00170 CAnimatedMaterial(CMaterialBase *baseMat);
00171
00172
00177 void setMaterial(CMaterial *pMat);
00178
00181 std::string getMaterialName() const;
00182
00183
00184
00190 void update();
00191
00192
00194
00195 static const char *getAmbientValueName() {return "ambient";}
00196 static const char *getDiffuseValueName() {return "diffuse";}
00197 static const char *getSpecularValueName() {return "specular";}
00198 static const char *getShininessValueName() {return "shininess";}
00199 static const char *getEmissiveValueName() {return "emissive";}
00200 static const char *getOpacityValueName() {return "opacity";}
00201 static const char *getTextureValueName() {return "texture";}
00202
00203 static const char *getTexMatUTransName(uint stage);
00204 static const char *getTexMatVTransName(uint stage);
00205 static const char *getTexMatUScaleName(uint stage);
00206 static const char *getTexMatVScaleName(uint stage);
00207 static const char *getTexMatWRotName(uint stage);
00208
00209
00210
00212 enum { NumTexAnimatedValues = CMaterialBase::CTexAnimTracks::NumTexAnimatedValues };
00213
00215
00217
00218 {
00219 OwnerBit= IAnimatable::AnimValueLast,
00220 AmbientValue,
00221 DiffuseValue,
00222 SpecularValue,
00223 ShininessValue,
00224 EmissiveValue,
00225 OpacityValue,
00226 TextureValue,
00227 TextureMatValues,
00228 AnimValueLast = TextureMatValues + NumTexAnimatedValues * IDRV_MAT_MAXTEXTURES
00229 };
00230
00232 virtual IAnimatedValue* getValue (uint valueId);
00233
00235 virtual const char *getValueName (uint valueId) const;
00236
00238 virtual ITrack* getDefaultTrack (uint valueId);
00239
00241 virtual void registerToChannelMixer(CChannelMixer *chanMixer, const std::string &prefix);
00242
00243
00244
00245
00246
00247 private:
00248
00249
00250 CRefPtr<CMaterialBase> _MaterialBase;
00251
00252 CRefPtr<CMaterial> _Material;
00253
00254
00255 CAnimatedValueRGBA _Ambient;
00256 CAnimatedValueRGBA _Diffuse;
00257 CAnimatedValueRGBA _Specular;
00258 CAnimatedValueFloat _Shininess;
00259 CAnimatedValueRGBA _Emissive;
00260 CAnimatedValueFloat _Opacity;
00261 CAnimatedValueInt _Texture;
00262
00263 struct CTexAnimatedMatValues
00264 {
00265 CAnimatedValueFloat _UTrans;
00266 CAnimatedValueFloat _VTrans;
00267 CAnimatedValueFloat _UScale;
00268 CAnimatedValueFloat _VScale;
00269 CAnimatedValueFloat _WRot;
00270
00271 void affect(CMaterialBase::CTexAnimTracks &at)
00272 {
00273 _UTrans.affect(at.DefaultUTrans.getValue());
00274 _VTrans.affect(at.DefaultVTrans.getValue());
00275 _UScale.affect(at.DefaultUScale.getValue());
00276 _VScale.affect(at.DefaultVScale.getValue());
00277 _WRot.affect(at.DefaultWRot.getValue());
00278
00279 }
00280 };
00281 CTexAnimatedMatValues _TexAnimatedMatValues[IDRV_MAT_MAXTEXTURES];
00282 };
00283
00284
00285 }
00286
00287
00288 #endif // NL_ANIMATED_MATERIAL_H
00289
00290