Add infos into target window
[ryzomcore.git] / ryzom / client / src / animation_fx_sheet.cpp
blobb5c778b1185393ee147e537e729501b355ccc013
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_sheet.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"
30 extern NL3D::UScene *Scene;
32 //*******************************************************************************
33 // CAnimationFX
34 //*******************************************************************************
36 //-----------------------------------------------
37 // CAnimationFX
38 //-----------------------------------------------
39 CAnimationFX::CAnimationFX(const std::string &psName /* = "" */, const float *userParams /*=NULL*/)
41 PosTrack = NULL;
42 Sheet = NULL;
43 if ((!psName.empty()) || (userParams != NULL))
45 Sheet = new CAnimationFXSheet(psName, userParams);
47 }// CAnimationFX //
49 //-----------------------------------------------
50 // init
51 //-----------------------------------------------
52 void CAnimationFX::init(CAnimationFXSheet *sheet, NL3D::UAnimationSet *as)
54 Sheet = sheet;
55 // Dont need to call the build track
56 }// init //
59 //-----------------------------------------------
60 // buildTrack
61 //-----------------------------------------------
62 void CAnimationFX::buildTrack(NL3D::UAnimationSet *as)
64 nlassert(Sheet != NULL);
65 if (!as) return;
66 if (Sheet->TrajectoryAnim.empty()) return;
67 std::string animName = NLMISC::toLower(Sheet->TrajectoryAnim);
68 uint id = as->getAnimationIdByName(animName);
69 NL3D::UAnimation *anim = NULL;
70 if (id != NL3D::UAnimationSet::NotFound)
72 anim = as->getAnimation(id);
74 else
76 // try to load anim
77 uint id = as->addAnimation(animName.c_str(), animName.c_str());
78 if (id != NL3D::UAnimationSet::NotFound)
80 anim = as->getAnimation(id);
83 if (anim)
85 PosTrack = anim->getTrackByName("pos");
87 }// buildTrack //
89 //-----------------------------------------------
90 //createMatchingInstance
91 //-----------------------------------------------
92 NL3D::UParticleSystemInstance CAnimationFX::createMatchingInstance() const
94 nlassert(Sheet != NULL);
95 if (Sheet->PSName.empty()) return NULL;
96 if (nlstricmp(Sheet->PSName, "none") == 0) return NULL;
97 NL3D::UInstance inst = Scene->createInstance(Sheet->PSName);
98 if (!inst.empty())
100 NL3D::UParticleSystemInstance fx;
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 for(uint l = 0; l < 4; ++l)
112 fx->setUserParam(l, Sheet->UserParam[l]);
114 fx->setUserColor(Sheet->Color);
115 return fx;
118 return NULL;
119 }// createMatchingInstance //
121 //*******************************************************************************
122 // CAnimationFXSet
123 //*******************************************************************************
125 //-----------------------------------------------
126 // buildTrack
127 //-----------------------------------------------
128 void CAnimationFXSet::buildTrack(NL3D::UAnimationSet *as)
130 if (!as) return;
131 for(uint k = 0; k < FX.size(); ++k)
133 FX[k].buildTrack(as);
135 }// buildTrack //