wavelength 1.0.0
Loading...
Searching...
No Matches
avatarpart.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <vector>
5
6#include "math/color.h"
7#include "math/key.h"
8#include "math/quaternion.h"
9#include "math/vector3.h"
10#include "rnd/rndloader.h"
11#include "rnd/rndmanager.h"
12#include "rnd/rndmat.h"
13#include "rnd/rndmesh.h"
14#include "rnd/rndobject.h"
15#include "rnd/rndtransanim.h"
16#include "script/dataarray.h"
17
18class Avatar;
19
30public:
38 public:
46 explicit Callback(AvatarPart *pOwner) : mOwner(pOwner) {
47 }
48
62 int ShouldLoad(RndObject *pExisting, const char *pszName, const char *pszClass) override;
63
64 private:
65 AvatarPart *mOwner;
66 };
67
82 AvatarPart(int nPart, int nParent, Avatar *pAvatar);
83
90 virtual ~AvatarPart();
91
101 virtual void SetFrame(float fFrame);
102
114 virtual void SetFrames(float fFrom, float fTo, float fBlend);
115
124 virtual void Update();
125
135 virtual void SetType(const char *pszType);
136
146 virtual bool Rebuild();
147
156 virtual void ReleaseType();
157
166 void Draw();
167
177 void SetBlend(float fBlend);
178
188 void SetColor(const Color *pColor);
189
191 const char *GetType() const {
192 return mType;
193 }
194
196 const char *GetPendingType() const {
197 return mPendingType;
198 }
199
205 void SetPendingType(const char *pszType) {
206 mPendingType = pszType;
207 }
208
214 void SetMat(RndMat *pMat) {
215 mMat = pMat;
216 }
217
220 return mTransRoot;
221 }
222
224 const std::vector<std::unique_ptr<RndTransAnim>> &GetAnims() const {
225 return mAnims;
226 }
227
228protected:
238 void SetMatTree(RndMesh *pMesh);
239
248 void FindJoint();
249
259 static void RotationAt(const RndTransAnim *pAnim, float fFrame, Quat &out) {
260 const Key<Quat> *pPrev;
261 const Key<Quat> *pNext;
262 float fRatio;
263 AtFrame(pAnim->GetFramesOwner()->GetRotKeys(), fFrame, pPrev, pNext, fRatio);
264 if (pPrev != nullptr) {
265 QuatSlerp(pPrev->value, pNext->value, out, fRatio);
266 }
267 }
268
280 static void
281 BlendRotation(const RndTransAnim *pAnim, float fFrom, float fTo, float fBlend, Quat &out) {
282 Quat from;
283 Quat to;
284 RotationAt(pAnim, fFrom, from);
285 RotationAt(pAnim, fTo, to);
286 QuatSlerp(from, to, out, fBlend);
287 }
288
300 static void BlendTranslation(
301 const RndTransAnim *pAnim, float fFrom, float fTo, float fBlend, Vector3 &out) {
302 Vector3 from;
303 Vector3 to;
304 InterpKeys(pAnim->GetFramesOwner()->GetTransKeys(), fFrom, from);
305 InterpKeys(pAnim->GetFramesOwner()->GetTransKeys(), fTo, to);
306 Interp(from, to, fBlend, out);
307 }
308
317 static RndMesh *FindMesh(const char *pszName) {
318 return dynamic_cast<RndMesh *>(TheManager.Find(pszName));
319 }
320
328 static void ResetLocalXfm(RndMesh *pMesh) {
329 Transform identity;
330 identity.mBasisX = {1.0f, 0.0f, 0.0f};
331 identity.mBasisY = {0.0f, 1.0f, 0.0f};
332 identity.mBasisZ = {0.0f, 0.0f, 1.0f};
333 identity.mTranslation = {0.0f, 0.0f, 0.0f, 1.0f};
334 pMesh->SetLocalXfm(identity);
335 pMesh->SetDirty(1);
336 }
337
339
341
342 const char *mType;
343
344 const char *mPendingType;
345
347
349
351
353
355
357 std::vector<std::unique_ptr<RndTransAnim>> mAnims;
358
360
362
363 std::unique_ptr<RndLoader> mLoader;
364
366 std::unique_ptr<RndLoader> mPendingLoader;
367
369 std::unique_ptr<RndLoader> mPendingExtraLoader;
370};
The callback of the loads of the files of a part.
Definition avatarpart.h:37
Callback(AvatarPart *pOwner)
Construct the callback of a part.
Definition avatarpart.h:46
int ShouldLoad(RndObject *pExisting, const char *pszName, const char *pszClass) override
Create an object only when no object of the name exists.
static void ResetLocalXfm(RndMesh *pMesh)
Set the local transform of a mesh to the identity and mark it out of date.
Definition avatarpart.h:328
static RndMesh * FindMesh(const char *pszName)
Find a mesh by name.
Definition avatarpart.h:317
const char * GetType() const
Definition avatarpart.h:191
void SetPendingType(const char *pszType)
Set the choice SetType() last requested.
Definition avatarpart.h:205
RndMesh * mTransRoot
Definition avatarpart.h:350
static void BlendRotation(const RndTransAnim *pAnim, float fFrom, float fTo, float fBlend, Quat &out)
Blend the rotations of an animation at two frames.
Definition avatarpart.h:281
virtual void Update()
Hang the model from the joint of its parent.
void SetColor(const Color *pColor)
Colour the model.
void SetBlend(float fBlend)
Set the alpha of the material of the model, when it has one.
void SetMatTree(RndMesh *pMesh)
Give a mesh and every mesh drawn under it the material of the model.
const char * mPendingType
Definition avatarpart.h:344
RndMesh * mJoint
Definition avatarpart.h:352
void SetMat(RndMat *pMat)
Set the material of the model.
Definition avatarpart.h:214
DataArray * mData
Definition avatarpart.h:340
Callback mCallback
Definition avatarpart.h:338
RndMesh * mMesh
Definition avatarpart.h:348
std::unique_ptr< RndLoader > mPendingExtraLoader
The load of the second file of mPendingType, or null.
Definition avatarpart.h:369
virtual void SetFrames(float fFrom, float fTo, float fBlend)
Pose the model between two frames of its animations.
const std::vector< std::unique_ptr< RndTransAnim > > & GetAnims() const
Definition avatarpart.h:224
std::vector< std::unique_ptr< RndTransAnim > > mAnims
The animations of the bones the anims array lists, in its order, deleted with the part.
Definition avatarpart.h:357
RndMesh * GetTransRoot()
Definition avatarpart.h:219
virtual ~AvatarPart()
Delete the animations and the loaders of the model.
virtual void ReleaseType()
Abandon the loads SetType() started and return to the choice the meshes show.
virtual void SetType(const char *pszType)
Start loading the files of a choice of the part.
Color mColor
Definition avatarpart.h:346
const char * mType
Definition avatarpart.h:342
AvatarPart * mParent
Definition avatarpart.h:359
virtual void SetFrame(float fFrame)
Pose the model at one frame of its animations.
static void BlendTranslation(const RndTransAnim *pAnim, float fFrom, float fTo, float fBlend, Vector3 &out)
Blend the translations of an animation at two frames.
Definition avatarpart.h:300
AvatarPart(int nPart, int nParent, Avatar *pAvatar)
Construct the model of a part from its entry of the parts array of the avatar entry of the "db" secti...
void FindJoint()
Find the joint mesh the model hangs from, avatar<n>_<trans_root>_joint.mesh.
Avatar * mAvatar
Definition avatarpart.h:361
std::unique_ptr< RndLoader > mPendingLoader
The load of the first file of mPendingType, or null.
Definition avatarpart.h:366
RndMat * mMat
Definition avatarpart.h:354
void Draw()
Draw the model, when it has a mesh.
static void RotationAt(const RndTransAnim *pAnim, float fFrame, Quat &out)
Interpolate the rotation keys of an animation at a frame.
Definition avatarpart.h:259
virtual bool Rebuild()
Build the meshes of the model once the files SetType() started loading have loaded.
std::unique_ptr< RndLoader > mLoader
Definition avatarpart.h:363
const char * GetPendingType() const
Definition avatarpart.h:196
One of the avatars the game can draw at a time, lent to the AvatarPartSet that shows.
Definition avatar.h:24
Reference-counted array of script data nodes.
Definition dataarray.h:20
Rotation quaternion, stored as the vector part followed by the scalar part.
Definition quaternion.h:19
Interface a loader consults before it creates each object of its file.
Definition rndloader.h:35
Surface description: blending, lighting colours, culling, and a list of texture stages.
Definition rndmat.h:20
Triangle mesh with a material.
Definition rndmesh.h:31
Base of every object the renderer can load, resolve by name, and serialise.
Definition rndobject.h:20
Animation of a transformable's local transform by rotation, translation, and scale keys.
Definition rndtransanim.h:20
const std::vector< Key< Quat > > & GetRotKeys() const
Definition rndtransanim.h:231
RndTransAnim * GetFramesOwner() const
Definition rndtransanim.h:226
const std::vector< Key< Vector3 > > & GetTransKeys() const
Definition rndtransanim.h:276
void SetDirty(int nDirty)
Definition rndtransformable.h:249
void SetLocalXfm(const Transform &xfm)
Definition rndtransformable.h:229
void InterpKeys(const std::vector< Key< T > > &keys, float fFrame, T &out)
Interpolate keys at a frame.
Definition key.h:193
int AtFrame(const std::vector< Key< T > > &keys, float fFrame, const Key< T > *&pPrev, const Key< T > *&pNext, float &fRatio)
Find the keys around a frame.
Definition key.h:46
void Interp(const Vector3 &a, const Vector3 &b, float fRatio, Vector3 &out)
Blend two vectors, taking either end exactly at a position of 0 or 1.
Definition key.h:103
void QuatSlerp(const Quat &from, const Quat &to, Quat &out, float flT)
Interpolate between two rotation quaternions along the shorter arc.
RndManager TheManager
The renderer's registry.
Linear colour with four float components.
Definition color.h:12
One keyframe of an animation channel, a value at a frame.
Definition key.h:21
T value
Definition key.h:22
Affine transform stored as three basis rows and a translation row.
Definition transform.h:18
Vector3 mTranslation
Definition transform.h:22
Vector3 mBasisZ
Definition transform.h:21
Vector3 mBasisY
Definition transform.h:20
Vector3 mBasisX
Definition transform.h:19
Three-component vector, padded to a PlayStation 2 quadword.
Definition vector3.h:14