Fix css style order when using external css files
[ryzomcore.git] / ryzom / client / src / animation_fx.cpp
blobb87464cb3ddb4bbd93ccf50906f7dc9fc3be45c1
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "stdpch.h"
20 #include "animation_fx.h"
21 #include "nel/georges/u_form_elm.h"
22 #include "nel/3d/u_animation_set.h"
23 #include "nel/3d/u_animation.h"
24 #include "nel/3d/u_track.h"
25 #include "nel/3d/u_instance.h"
26 #include "nel/3d/u_particle_system_instance.h"
27 #include "nel/3d/u_scene.h"
28 #include "client_sheets/animation_fx_set_sheet.h"
30 #ifdef DEBUG_NEW
31 #define new DEBUG_NEW
32 #endif
34 extern NL3D::UScene *Scene;
37 //-----------------------------------------------
38 // CAnimationFX
39 //-----------------------------------------------
40 CAnimationFX::CAnimationFX(const std::string &psName /* = "" */, const float *userParams /*=NULL*/)
42 PosTrack = NULL;
43 Sheet = NULL;
44 if ((!psName.empty()) || (userParams != NULL))
46 Sheet = new CAnimationFXSheet(psName, userParams);
48 }// CAnimationFX //
50 //-----------------------------------------------
51 // init
52 //-----------------------------------------------
53 void CAnimationFX::init(const CAnimationFXSheet *sheet, NL3D::UAnimationSet *as)
55 Sheet = sheet;
56 buildTrack(as);
57 }// init //
60 //-----------------------------------------------
61 // buildTrack
62 //-----------------------------------------------
63 void CAnimationFX::buildTrack(NL3D::UAnimationSet *as)
65 nlassert(Sheet != NULL);
66 if (!as) return;
67 if (Sheet->TrajectoryAnim.empty()) return;
68 std::string animName = NLMISC::toLowerAscii(Sheet->TrajectoryAnim);
69 uint id = as->getAnimationIdByName(animName);
70 NL3D::UAnimation *anim = NULL;
71 if (id != NL3D::UAnimationSet::NotFound)
73 anim = as->getAnimation(id);
75 else
77 // try to load anim
78 uint id = as->addAnimation(animName.c_str(), animName.c_str());
79 if (id != NL3D::UAnimationSet::NotFound)
81 anim = as->getAnimation(id);
84 if (anim)
86 PosTrack = anim->getTrackByName("pos");
88 }// buildTrack //
90 //-----------------------------------------------
91 //createMatchingInstance
92 //-----------------------------------------------
93 NL3D::UParticleSystemInstance CAnimationFX::createMatchingInstance(const float *customUserParams /* = NULL */) const
95 NL3D::UParticleSystemInstance fx;
96 nlassert(Sheet != NULL);
97 if (Sheet->PSName.empty()) return NULL;
98 NL3D::UInstance inst = Scene->createInstance(Sheet->PSName);
99 if (!inst.empty())
101 fx.cast (inst);
102 if (fx.empty())
104 nlwarning("Bad shape type for a fxsheet shape : must be a particle system");
105 Scene->deleteInstance(inst);
106 return NULL;
108 else
110 if (customUserParams != NULL)
112 for(uint l = 0; l < 4; ++l)
114 fx.setUserParam(l, customUserParams[l]);
117 else
119 for(uint l = 0; l < 4; ++l)
121 fx.setUserParam(l, Sheet->UserParam[l]);
124 fx.setUserColor(Sheet->Color);
127 return fx;
128 }// createMatchingInstance //
130 // *******************************************************************************
131 // CAnimationFXSet
132 // *******************************************************************************
134 //-----------------------------------------------
135 // init
136 //-----------------------------------------------
137 void CAnimationFXSet::init(const CAnimationFXSetSheet *sheet, NL3D::UAnimationSet *as)
139 if (!sheet) return;
140 Sheet = sheet;
141 FX.resize(sheet->FX.size());
142 for(uint k = 0; k < sheet->FX.size(); ++k)
144 FX[k].init(&sheet->FX[k], as);