Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / client / src / animation_fx.cpp
blob0ab586a92e3a5ab5376ed23367d7c8d6790fe4bf
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "stdpch.h"
23 #include "animation_fx.h"
24 #include "nel/georges/u_form_elm.h"
25 #include "nel/3d/u_animation_set.h"
26 #include "nel/3d/u_animation.h"
27 #include "nel/3d/u_track.h"
28 #include "nel/3d/u_instance.h"
29 #include "nel/3d/u_particle_system_instance.h"
30 #include "nel/3d/u_scene.h"
31 #include "client_sheets/animation_fx_set_sheet.h"
33 #ifdef DEBUG_NEW
34 #define new DEBUG_NEW
35 #endif
37 extern NL3D::UScene *Scene;
40 //-----------------------------------------------
41 // CAnimationFX
42 //-----------------------------------------------
43 CAnimationFX::CAnimationFX(const std::string &psName /* = "" */, const float *userParams /*=NULL*/)
45 PosTrack = NULL;
46 Sheet = NULL;
47 if ((!psName.empty()) || (userParams != NULL))
49 Sheet = new CAnimationFXSheet(psName, userParams);
51 }// CAnimationFX //
53 //-----------------------------------------------
54 // init
55 //-----------------------------------------------
56 void CAnimationFX::init(const CAnimationFXSheet *sheet, NL3D::UAnimationSet *as)
58 Sheet = sheet;
59 buildTrack(as);
60 }// init //
63 //-----------------------------------------------
64 // buildTrack
65 //-----------------------------------------------
66 void CAnimationFX::buildTrack(NL3D::UAnimationSet *as)
68 nlassert(Sheet != NULL);
69 if (!as) return;
70 if (Sheet->TrajectoryAnim.empty()) return;
71 std::string animName = NLMISC::toLowerAscii(Sheet->TrajectoryAnim);
72 uint id = as->getAnimationIdByName(animName);
73 NL3D::UAnimation *anim = NULL;
74 if (id != NL3D::UAnimationSet::NotFound)
76 anim = as->getAnimation(id);
78 else
80 // try to load anim
81 uint id = as->addAnimation(animName.c_str(), animName.c_str());
82 if (id != NL3D::UAnimationSet::NotFound)
84 anim = as->getAnimation(id);
87 if (anim)
89 PosTrack = anim->getTrackByName("pos");
91 }// buildTrack //
93 //-----------------------------------------------
94 //createMatchingInstance
95 //-----------------------------------------------
96 NL3D::UParticleSystemInstance CAnimationFX::createMatchingInstance(const float *customUserParams /* = NULL */) const
98 NL3D::UParticleSystemInstance fx;
99 nlassert(Sheet != NULL);
100 if (Sheet->PSName.empty()) return NULL;
101 NL3D::UInstance inst = Scene->createInstance(Sheet->PSName);
102 if (!inst.empty())
104 fx.cast (inst);
105 if (fx.empty())
107 nlwarning("Bad shape type for a fxsheet shape : must be a particle system");
108 Scene->deleteInstance(inst);
109 return NULL;
111 else
113 if (customUserParams != NULL)
115 for(uint l = 0; l < 4; ++l)
117 fx.setUserParam(l, customUserParams[l]);
120 else
122 for(uint l = 0; l < 4; ++l)
124 fx.setUserParam(l, Sheet->UserParam[l]);
127 fx.setUserColor(Sheet->Color);
130 return fx;
131 }// createMatchingInstance //
133 // *******************************************************************************
134 // CAnimationFXSet
135 // *******************************************************************************
137 //-----------------------------------------------
138 // init
139 //-----------------------------------------------
140 void CAnimationFXSet::init(const CAnimationFXSetSheet *sheet, NL3D::UAnimationSet *as)
142 if (!sheet) return;
143 Sheet = sheet;
144 FX.resize(sheet->FX.size());
145 for(uint k = 0; k < sheet->FX.size(); ++k)
147 FX[k].init(&sheet->FX[k], as);