#include <animated_material.h>
Inheritance diagram for NL3D::CAnimatedMaterial:
Nevrax France
Definition at line 159 of file animated_material.h.
Herited from IAnimatable | |
enum | TAnimValues { OwnerBit = IAnimatable::AnimValueLast, AmbientValue, DiffuseValue, SpecularValue, ShininessValue, EmissiveValue, OpacityValue, TextureValue, TextureMatValues, AnimValueLast = TextureMatValues + NumTexAnimatedValues * IDRV_MAT_MAXTEXTURES } |
Added values. More... | |
virtual ITrack * | getDefaultTrack (uint valueId) |
From IAnimatable. | |
virtual IAnimatedValue * | getValue (uint valueId) |
From IAnimatable. | |
virtual const char * | getValueName (uint valueId) const |
From IAnimatable. | |
virtual void | registerToChannelMixer (CChannelMixer *chanMixer, const std::string &prefix) |
From IAnimatable. | |
Public Types | |
enum | { NumTexAnimatedValues = CMaterialBase::CTexAnimTracks::NumTexAnimatedValues } |
number of animated values for each animated texture, taken from CMaterialBase More... | |
Public Member Functions | |
void | update () |
ctor / setup. | |
CAnimatedMaterial (CMaterialBase *baseMat) | |
std::string | getMaterialName () const |
void | setMaterial (CMaterial *pMat) |
Static Public Member Functions | |
Get some track name | |
const char * | getAmbientValueName () |
const char * | getDiffuseValueName () |
const char * | getEmissiveValueName () |
const char * | getOpacityValueName () |
const char * | getShininessValueName () |
const char * | getSpecularValueName () |
const char * | getTexMatUScaleName (uint stage) |
const char * | getTexMatUTransName (uint stage) |
const char * | getTexMatVScaleName (uint stage) |
const char * | getTexMatVTransName (uint stage) |
const char * | getTexMatWRotName (uint stage) |
const char * | getTextureValueName () |
Protected Member Functions | |
sint | addValue (CChannelMixer *chanMixer, uint valueId, uint ownerValueId, const std::string &prefix, bool detail) |
void | clearFlag (uint valueId) |
This method clear a bit in the bitset. | |
void | setFlag (uint valueId) |
This method set a bit in the bitset. | |
Private Attributes | |
CAnimatedValueRGBA | _Ambient |
CAnimatedValueRGBA | _Diffuse |
CAnimatedValueRGBA | _Emissive |
CRefPtr< CMaterial > | _Material |
CRefPtr< CMaterialBase > | _MaterialBase |
CAnimatedValueFloat | _Opacity |
CAnimatedValueFloat | _Shininess |
CAnimatedValueRGBA | _Specular |
CTexAnimatedMatValues | _TexAnimatedMatValues [IDRV_MAT_MAXTEXTURES] |
CAnimatedValueInt | _Texture |
|
number of animated values for each animated texture, taken from CMaterialBase
Definition at line 212 of file animated_material.h.
00212 { NumTexAnimatedValues = CMaterialBase::CTexAnimTracks::NumTexAnimatedValues }; |
|
Added values.
Reimplemented from NL3D::IAnimatable. Definition at line 217 of file animated_material.h.
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 /* texture matrix anim */ 00229 }; |
|
Constructor. This ctor:
Definition at line 159 of file animated_material.cpp. References _Ambient, _Diffuse, _Emissive, _MaterialBase, _Opacity, _Shininess, _Specular, _TexAnimatedMatValues, NL3D::CAnimatedMaterial::CTexAnimatedMatValues::affect(), NL3D::CAnimatedValueBlendable< float >::affect(), NL3D::CAnimatedValueBlendable< T >::affect(), NL3D::IDRV_MAT_MAXTEXTURES, nlassert, and uint.
00160 { 00161 nlassert(baseMat); 00162 _MaterialBase= baseMat; 00163 00164 // IAnimatable. 00165 IAnimatable::resize(AnimValueLast); 00166 00167 _Ambient.affect(_MaterialBase->DefaultAmbient.getValue()); 00168 _Diffuse.affect(_MaterialBase->DefaultDiffuse.getValue()); 00169 _Specular.affect(_MaterialBase->DefaultSpecular.getValue()); 00170 _Shininess.affect(_MaterialBase->DefaultShininess.getValue()); 00171 _Emissive.affect(_MaterialBase->DefaultEmissive.getValue()); 00172 _Opacity.affect(_MaterialBase->DefaultOpacity.getValue()); 00173 00174 for (uint k = 0; k < IDRV_MAT_MAXTEXTURES; ++k) 00175 { 00176 _TexAnimatedMatValues[k].affect(baseMat->DefaultTexAnimTracks[k]); 00177 } 00178 } |
|
This is a tool function which add a given value to a channel.
Definition at line 37 of file animatable.cpp. References NL3D::CChannelMixer::addChannel(), NL3D::IAnimatable::getDefaultTrack(), NL3D::IAnimatable::getValue(), NL3D::IAnimatable::getValueName(), nlassert, sint, and uint. Referenced by NL3D::CTransform::registerToChannelMixer(), NL3D::CParticleSystemModel::registerToChannelMixer(), NL3D::CCamera::registerToChannelMixer(), NL3D::CBone::registerToChannelMixer(), NL3D::CAnimatedMorph::registerToChannelMixer(), registerToChannelMixer(), and NL3D::CAnimatedLightmap::registerToChannelMixer().
00038 { 00039 nlassert(chanMixer); 00040 return chanMixer->addChannel(prefix+getValueName(valueId), this, getValue(valueId), getDefaultTrack(valueId), valueId, ownerValueId, detail); 00041 } |
|
This method clear a bit in the bitset.
Definition at line 233 of file animatable.h. References NL3D::IAnimatable::_BitSet, and uint. Referenced by NL3D::ITransformable::clearTransformFlags(), NL3D::CParticleSystemModel::doAnimate(), and update().
00234 { 00235 _BitSet&= ~(1<<valueId); 00236 } |
|
Definition at line 195 of file animated_material.h. Referenced by getValueName().
00195 {return "ambient";} |
|
From IAnimatable.
Implements NL3D::IAnimatable. Definition at line 340 of file animated_material.cpp. References _MaterialBase, AmbientValue, DiffuseValue, EmissiveValue, nlassert, nlstop, OpacityValue, ShininessValue, SpecularValue, TextureMatValues, TextureValue, and uint.
00341 { 00342 nlassert(_MaterialBase); 00343 00344 switch(valueId) 00345 { 00346 case AmbientValue: return &_MaterialBase->DefaultAmbient; 00347 case DiffuseValue: return &_MaterialBase->DefaultDiffuse; 00348 case SpecularValue: return &_MaterialBase->DefaultSpecular; 00349 case ShininessValue: return &_MaterialBase->DefaultShininess; 00350 case EmissiveValue: return &_MaterialBase->DefaultEmissive; 00351 case OpacityValue: return &_MaterialBase->DefaultOpacity; 00352 case TextureValue: return &_MaterialBase->DefaultTexture; 00353 default: // this may be a texture animated value... 00354 if (valueId >= TextureMatValues && valueId < AnimValueLast) 00355 { 00356 const uint baseId = valueId - TextureMatValues; 00357 const uint texNum = baseId / NumTexAnimatedValues; 00358 const uint argID = baseId % NumTexAnimatedValues; 00359 switch(argID) 00360 { 00361 case 0: return &_MaterialBase->DefaultTexAnimTracks[texNum].DefaultUTrans; 00362 case 1: return &_MaterialBase->DefaultTexAnimTracks[texNum].DefaultVTrans; 00363 case 2: return &_MaterialBase->DefaultTexAnimTracks[texNum].DefaultUTrans; 00364 case 3: return &_MaterialBase->DefaultTexAnimTracks[texNum].DefaultVTrans; 00365 case 4: return &_MaterialBase->DefaultTexAnimTracks[texNum].DefaultWRot; 00366 } 00367 } 00368 break; 00369 }; 00370 00371 // shoudl not be here!! 00372 nlstop; 00373 return NULL; 00374 } |
|
Definition at line 196 of file animated_material.h. Referenced by getValueName().
00196 {return "diffuse";} |
|
Definition at line 199 of file animated_material.h. Referenced by getValueName().
00199 {return "emissive";} |
|
Return the name of this material (stored in CMaterialBase). Definition at line 189 of file animated_material.cpp. References _MaterialBase, and nlassert. Referenced by NL3D::CSegRemanence::registerToChannelMixer().
00190 { 00191 nlassert(_MaterialBase); 00192 return _MaterialBase->Name; 00193 } |
|
Definition at line 200 of file animated_material.h. Referenced by getValueName().
00200 {return "opacity";} |
|
Definition at line 198 of file animated_material.h. Referenced by getValueName().
00198 {return "shininess";} |
|
Definition at line 197 of file animated_material.h. Referenced by getValueName().
00197 {return "specular";} |
|
Definition at line 432 of file animated_material.cpp. References NL3D::IDRV_MAT_MAXTEXTURES, nlassert, and uint. Referenced by getValueName().
00433 { 00434 static char names[IDRV_MAT_MAXTEXTURES][16]; 00435 static bool init = false; 00436 nlassert(stage < IDRV_MAT_MAXTEXTURES); 00437 if (!init) // where name initialized ? 00438 { 00439 for (uint k = 0; k < IDRV_MAT_MAXTEXTURES; ++k) 00440 { 00441 sprintf(&names[k][0], "UScale%d", k); 00442 } 00443 init = true; 00444 } 00445 return names[stage]; 00446 } |
|
Definition at line 396 of file animated_material.cpp. References NL3D::IDRV_MAT_MAXTEXTURES, nlassert, and uint. Referenced by getValueName().
00397 { 00398 static char names[IDRV_MAT_MAXTEXTURES][16]; 00399 static bool init = false; 00400 nlassert(stage < IDRV_MAT_MAXTEXTURES); 00401 if (!init) // where name initialized ? 00402 { 00403 for (uint k = 0; k < IDRV_MAT_MAXTEXTURES; ++k) 00404 { 00405 sprintf(&names[k][0], "UTrans%d", k); 00406 } 00407 init = true; 00408 } 00409 return names[stage]; 00410 } |
|
Definition at line 449 of file animated_material.cpp. References NL3D::IDRV_MAT_MAXTEXTURES, nlassert, and uint. Referenced by getValueName().
00450 { 00451 nlassert(stage < IDRV_MAT_MAXTEXTURES); 00452 static char names[IDRV_MAT_MAXTEXTURES][16]; 00453 static bool init = false; 00454 nlassert(stage < IDRV_MAT_MAXTEXTURES); 00455 if (!init) // where name initialized ? 00456 { 00457 for (uint k = 0; k < IDRV_MAT_MAXTEXTURES; ++k) 00458 { 00459 sprintf(&names[k][0], "VScale%d", k); 00460 } 00461 init = true; 00462 } 00463 return names[stage]; 00464 } |
|
Definition at line 413 of file animated_material.cpp. References NL3D::IDRV_MAT_MAXTEXTURES, nlassert, and uint. Referenced by getValueName().
00414 { 00415 nlassert(stage < IDRV_MAT_MAXTEXTURES); 00416 static char names[IDRV_MAT_MAXTEXTURES][16]; 00417 static bool init = false; 00418 nlassert(stage < IDRV_MAT_MAXTEXTURES); 00419 if (!init) // where name initialized ? 00420 { 00421 for (uint k = 0; k < IDRV_MAT_MAXTEXTURES; ++k) 00422 { 00423 sprintf(&names[k][0], "VTrans%d", k); 00424 } 00425 init = true; 00426 } 00427 return names[stage]; 00428 } |
|
Definition at line 468 of file animated_material.cpp. References NL3D::IDRV_MAT_MAXTEXTURES, nlassert, and uint. Referenced by getValueName().
00469 { 00470 nlassert(stage < IDRV_MAT_MAXTEXTURES); 00471 static char names[IDRV_MAT_MAXTEXTURES][16]; 00472 static bool init = false; 00473 nlassert(stage < IDRV_MAT_MAXTEXTURES); 00474 if (!init) // where name initialized ? 00475 { 00476 for (uint k = 0; k < IDRV_MAT_MAXTEXTURES; ++k) 00477 { 00478 sprintf(&names[k][0], "WRot%d", k); 00479 } 00480 init = true; 00481 } 00482 return names[stage]; 00483 } |
|
Definition at line 201 of file animated_material.h. Referenced by getValueName().
00201 {return "texture";} |
|
|
|
Return non 0 int if the value as been touched else 0.
Definition at line 184 of file animatable.h. References NL3D::IAnimatable::_BitSet, uint, and uint32. Referenced by NL3D::CParticleSystemModel::doAnimate(), NL3D::ITransformable::needCompute(), NL3D::IAnimatable::propagateTouch(), and update().
00185 {
00186 return _BitSet&(1<<valueId);
00187 }
|
|
From IAnimatable.
Implements NL3D::IAnimatable. Definition at line 376 of file animated_material.cpp. References NL3D::IAnimatable::addValue(), AmbientValue, DiffuseValue, EmissiveValue, NL3D::IDRV_MAT_MAXTEXTURES, OpacityValue, ShininessValue, SpecularValue, TextureMatValues, TextureValue, and uint. Referenced by NL3D::CSegRemanence::registerToChannelMixer().
00377 { 00378 // For CAnimatedMaterial, channels are detailled (material rendered after clip)! 00379 addValue(chanMixer, AmbientValue, OwnerBit, prefix, true); 00380 addValue(chanMixer, DiffuseValue, OwnerBit, prefix, true); 00381 addValue(chanMixer, SpecularValue, OwnerBit, prefix, true); 00382 addValue(chanMixer, ShininessValue, OwnerBit, prefix, true); 00383 addValue(chanMixer, EmissiveValue, OwnerBit, prefix, true); 00384 addValue(chanMixer, OpacityValue, OwnerBit, prefix, true); 00385 addValue(chanMixer, TextureValue, OwnerBit, prefix, true); 00386 for (uint k = 0; k < IDRV_MAT_MAXTEXTURES; ++k) 00387 { 00388 for (uint l = 0; l < NumTexAnimatedValues; ++l) 00389 { 00390 addValue(chanMixer, TextureMatValues + l + k * NumTexAnimatedValues, OwnerBit, prefix, true); 00391 } 00392 } 00393 } |
|
Change value count, bit are set to 0
Definition at line 195 of file animatable.h. References count, nlassert, and uint.
00196 { 00197 // with the "uint32 _BitSet" implementation, juste check the size is correct 00198 nlassert(count<=32); 00199 } |
|
Say which (if any) IAnimatable owns this one. This is important for Touch propagation. By this system, Fathers and ancestors know if they must check their sons (isTouched() return true).
Definition at line 153 of file animatable.h. References NL3D::IAnimatable::_Father, NL3D::IAnimatable::_FatherOwnerBit, NL3D::IAnimatable::propagateTouch(), and uint. Referenced by NL3D::CMeshBase::instanciateMeshBase(), and NL3D::CSegRemanence::setAnimatedMaterial().
00154 { 00155 _Father= father; _FatherOwnerBit= fatherOwnerBit; 00156 00157 // propagate the touch to the fathers. 00158 propagateTouch(); 00159 } |
|
This method set a bit in the bitset.
Definition at line 239 of file animatable.h. References NL3D::IAnimatable::_BitSet, and uint. Referenced by NL3D::IAnimatable::propagateTouch(), and NL3D::IAnimatable::touch().
00240 { 00241 _BitSet|= (1<<valueId); 00242 } |
|
setup the material context for this animated material. This method:
Definition at line 182 of file animated_material.cpp. References _Material. Referenced by NL3D::CSegRemanenceShape::createInstance(), and NL3D::CMeshBase::instanciateMeshBase().
00183 { 00184 _Material= pMat; 00185 } |
|
|
Check if The animated material is touched, and if necessary update the stored material (if any). Texture animation: for now, texture animation is possible only on stage 0. If TextureValue flag is touched (ie a texture anim track is linked to the animated value), update() look into the CMaterialBase what texture to set. If the track gives a bad Id for the texture, no-op. Definition at line 197 of file animated_material.cpp. References _Ambient, _Diffuse, _Emissive, _Material, _MaterialBase, _Opacity, _Shininess, _Specular, _TexAnimatedMatValues, _Texture, NL3D::CAnimatedMaterial::CTexAnimatedMatValues::_UScale, NL3D::CAnimatedMaterial::CTexAnimatedMatValues::_UTrans, NL3D::CAnimatedMaterial::CTexAnimatedMatValues::_VScale, NL3D::CAnimatedMaterial::CTexAnimatedMatValues::_VTrans, NL3D::CAnimatedMaterial::CTexAnimatedMatValues::_WRot, NLMISC::CRGBA::A, AmbientValue, NLMISC::clamp(), NL3D::IAnimatable::clearFlag(), DiffuseValue, EmissiveValue, NL3D::IDRV_MAT_MAXTEXTURES, NL3D::IAnimatable::isTouched(), NLMISC::CMatrix::mulVector(), nlassert, OpacityValue, NLMISC::CMatrix::setPos(), NLMISC::CMatrix::setRot(), ShininessValue, sint, SpecularValue, TextureMatValues, TextureValue, uint, uint32, NL3D::CAnimatedValueBlendable< sint32 >::Value, NL3D::CAnimatedValueBlendable< float >::Value, and NL3D::CAnimatedValueBlendable< T >::Value. Referenced by NL3D::CSegRemanence::traverseAnimDetail().
00198 { 00199 if(isTouched(OwnerBit) && _Material!=NULL /*&& _Material->isLighted()*/) 00200 { 00201 00202 // well, just update all... :) 00203 00204 // diffuse part. 00205 CRGBA diff= _Diffuse.Value; 00206 sint c= (sint)(_Opacity.Value*255); 00207 clamp(c, 0, 255); 00208 diff.A= c; 00209 00210 // setup material. 00211 if (_Material->isLighted()) 00212 { 00213 _Material->setLighting(true, _Emissive.Value, _Ambient.Value, diff, _Specular.Value, _Shininess.Value); 00214 } 00215 else 00216 { 00217 _Material->setColor(diff); 00218 } 00219 00220 // clear flags. 00221 clearFlag(AmbientValue); 00222 clearFlag(DiffuseValue); 00223 clearFlag(SpecularValue); 00224 clearFlag(ShininessValue); 00225 clearFlag(EmissiveValue); 00226 clearFlag(OpacityValue); 00227 00228 00229 // Texture Anim. 00230 if(isTouched(TextureValue)) 00231 { 00232 nlassert(_MaterialBase); 00233 00234 uint32 id= _Texture.Value; 00235 if(_MaterialBase->validAnimatedTexture(id)) 00236 { 00237 _Material->setTexture(0, _MaterialBase->getAnimatedTexture(id) ); 00238 } 00239 clearFlag(TextureValue); 00240 } 00241 00242 // Get texture matrix from animated value to setup the material 00243 uint flagIndex = TextureMatValues; 00244 for (uint k = 0; k < IDRV_MAT_MAXTEXTURES; ++k) 00245 { 00246 if (_Material->isUserTexMatEnabled(k)) 00247 { 00248 const CTexAnimatedMatValues &texMatAV = _TexAnimatedMatValues[k]; 00249 00250 CMatrix convMat; // exported v are already inverted (todo : optim this if needed, this matrix shouldn't be necessary) 00251 convMat.setRot(CVector::I, -CVector::J, CVector::K); 00252 convMat.setPos(CVector::J); 00253 float fCos = cosf(texMatAV._WRot.Value); 00254 float fSin = sinf(texMatAV._WRot.Value); 00255 CMatrix SR; 00256 SR.setRot(CVector(texMatAV._UScale.Value * fCos, texMatAV._VScale.Value * fSin, 0.f), 00257 CVector(- texMatAV._UScale.Value * fSin, texMatAV._VScale.Value * fCos, 0.f), 00258 CVector::K); 00259 CVector half(0.5f, 0.5f, 0.f); 00260 SR.setPos(SR.mulVector(- half - CVector(texMatAV._UTrans.Value, texMatAV._VTrans.Value, 0.f)) + half); 00261 _Material->setUserTexMat(k, convMat * SR * convMat); 00262 } 00263 } 00264 00265 // We are OK! 00266 IAnimatable::clearFlag(OwnerBit); 00267 } 00268 } |
|
Definition at line 255 of file animated_material.h. Referenced by CAnimatedMaterial(), getValue(), and update(). |
|
Definition at line 256 of file animated_material.h. Referenced by CAnimatedMaterial(), getValue(), and update(). |
|
Definition at line 259 of file animated_material.h. Referenced by CAnimatedMaterial(), getValue(), and update(). |
|
Definition at line 252 of file animated_material.h. Referenced by setMaterial(), and update(). |
|
Definition at line 250 of file animated_material.h. Referenced by CAnimatedMaterial(), getDefaultTrack(), getMaterialName(), and update(). |
|
Definition at line 260 of file animated_material.h. Referenced by CAnimatedMaterial(), getValue(), and update(). |
|
Definition at line 258 of file animated_material.h. Referenced by CAnimatedMaterial(), getValue(), and update(). |
|
Definition at line 257 of file animated_material.h. Referenced by CAnimatedMaterial(), getValue(), and update(). |
|
Definition at line 281 of file animated_material.h. Referenced by CAnimatedMaterial(), getValue(), and update(). |
|
Definition at line 261 of file animated_material.h. Referenced by getValue(), and update(). |