resonance 1.0.1
Loading...
Searching...
No Matches
matanim.h
Go to the documentation of this file.
1#pragma once
2
3#include <list>
4#include <vector>
5
6#include "os/hxstr.h"
7#include "rnd/animatable.h"
8#include "rnd/keychannel.h"
9
10namespace Rnd {
11class Dbg;
12class Mat;
13class Object;
14class Stream;
15class Tex;
16} // namespace Rnd
17
18namespace Rnd {
19
49class MatAnim : public Animatable {
50public:
60
62 enum { kSerialVersion = 2 };
63
71 enum { kCopyShareKeys = 0x04 };
72
87 class Stage {
88 public:
97 class TexKey {
98 public:
108 bool operator<(const TexKey &other) const {
109 return mFrame < other.mFrame;
110 }
111
113 float mFrame;
114 };
115
125 Stage() = default;
126
137 Stage(const Stage &other) = default;
138
148 ~Stage() = default;
149
156 Stage &operator=(const Stage &other) = default;
157
168 void Save(Stream &stream);
169
182 void Load(Stream &stream);
183
191 void Dump(Dbg &sink);
192
205 void AddTexKey(Tex *pTex, float flFrame);
206
217 void RemoveTexKey(int nIndex);
218
230 void SetTexKeyFrame(int nIndex, float flFrame);
231
232 private:
233 friend class MatAnim;
234
235 // Channel blended into the last row of the stage transform, which is its translation.
236 std::list<Vector3Key> mTranslateKeys; // +0x00
237 // Channel blended and then scaled into the stage transform through Rnd::Scale().
238 std::list<Vector3Key> mScaleKeys; // +0x04
239 // Channel of Euler angles blended and then built into the stage transform through
240 // Rnd::MakeRotMatrix().
241 std::list<Vector3Key> mRotateKeys; // +0x08
242 // Channel of texture references. Its element is 8 bytes, a texture at `+0x00` and the
243 // frame at `+0x04`, which the reference walk at `0x004d3750` pins by taking a reference on
244 // list node `+0x08` and the end-frame walk at `0x004d42f0` by reading the frame at node
245 // `+0x0c`.
246 std::list<TexKey> mTexKeys; // +0x0c
247 // Animation this stage record belongs to. `0x004d3818` writes `this` through it while
248 // taking the references of the whole animation.
249 MatAnim *mOwner; // +0x10
250 };
251
261 MatAnim(const HxStr &name);
262
269 virtual ~MatAnim();
270
282 virtual void DumpText(Dbg &sink);
283
294 virtual void Save(Stream &stream);
295
309 virtual void Replace(Object *pFrom, Object *pTo);
310
318 virtual const HxStr &ClassName() const;
319
333 virtual void Copy(const Object *pSource, unsigned nFlags);
334
346 virtual void Load(Stream &stream);
347
361 virtual float FilteredFrameEnd();
362
374 void SetMat(Mat *pMat);
375
387 void SetKeysOwner(MatAnim *pOwner);
388
400 void SetNumStages(int nCount);
401
402protected:
421 virtual void SetFrameSelf(float flFrame);
422
423private:
432 void ClearKeys();
433
441 void AddObjectRefs();
442
449 void RemoveObjectRefs();
450
451 // No class derives from Rnd::MatAnim and no access from outside it is recovered, so every
452 // member is private. The order below is the recovered offset order.
453
454 // The material this animation drives.
455 Mat *mMat; // +0x18
456 // One stage animation per texture stage of the material.
457 std::vector<Stage> mStages; // +0x1c
458 // Animation whose channels this one reads, itself for an animation that owns its keys.
459 MatAnim *mKeysOwner; // +0x28
460 // Channel that drives Rnd::Mat::SetDiffuse().
461 std::list<ColorKey> mDiffuseKeys; // +0x2c
462 // Channel that drives Rnd::Mat::SetAmbient().
463 std::list<ColorKey> mAmbientKeys; // +0x30
464 // Channel that drives Rnd::Mat::SetEmissive().
465 std::list<ColorKey> mEmissiveKeys; // +0x34
466 // Channel that drives Rnd::Mat::SetSpecular(), always with an alpha of zero.
467 std::list<ColorKey> mSpecularKeys; // +0x38
468 // Channel that drives Rnd::Mat::SetAlpha().
469 std::list<FloatKey> mAlphaKeys; // +0x3c
470};
471
484
496
508
509} // namespace Rnd
Heap-allocated NUL-terminated string.
Definition hxstr.h:41
Animatable()
Construct an animatable with no children, no filters, and a zero frame.
Sink that the engine formats its diagnostic and failure text into.
Definition dbg.h:33
One keyframe of the texture channel of a stage.
Definition matanim.h:97
bool operator<(const TexKey &other) const
Order two keys by frame, which is what std::list::sort() compares.
Definition matanim.h:108
float mFrame
Definition matanim.h:113
Tex * mValue
Definition matanim.h:112
Stage(const Stage &other)=default
Copy the four channels and the owner of another stage animation.
Stage()=default
Construct a stage animation with four empty channels.
void AddTexKey(Tex *pTex, float flFrame)
Add a texture key and sort the channel by frame.
void SetTexKeyFrame(int nIndex, float flFrame)
Move the texture key at a position to a new frame and sort the channel by frame.
Stage & operator=(const Stage &other)=default
Copy the four channels and the owner of another stage animation over this one.
void RemoveTexKey(int nIndex)
Remove the texture key at a position and sort the channel by frame.
~Stage()=default
Release the four channels.
void Dump(Dbg &sink)
Write the four channels and the owner to the engine text sink.
void Load(Stream &stream)
Load the stage animation.
void Save(Stream &stream)
Serialise the stage animation.
friend class MatAnim
Definition matanim.h:233
Animation of the colours and the texture stages of one material.
Definition matanim.h:49
void SetMat(Mat *pMat)
Change the material this animation drives.
@ kCopyShareKeys
Definition matanim.h:71
virtual ~MatAnim()
Drop every reference this animation holds and every reference held on it.
virtual void SetFrameSelf(float flFrame)
Apply the animation at a frame.
MatAnim(const HxStr &name)
Construct an animation with five empty channels, no stages, and no material.
virtual void Save(Stream &stream)
Serialise the animation.
virtual void Replace(Object *pFrom, Object *pTo)
Replace one object reference with another.
void SetNumStages(int nCount)
Resize the stage vector of the keys owner.
virtual void Load(Stream &stream)
Load the animation.
virtual void Copy(const Object *pSource, unsigned nFlags)
Copy another animation over this one.
virtual void DumpText(Dbg &sink)
Write the animation to the engine text sink.
static HxStr sClassName
Registered class name of Rnd::MatAnim, the string "MatAnim".
Definition matanim.h:59
virtual float FilteredFrameEnd()
Report the last frame this animation runs to.
@ kSerialVersion
Definition matanim.h:62
virtual const HxStr & ClassName() const
Report the registered class name, "MatAnim".
void SetKeysOwner(MatAnim *pOwner)
Change the animation whose channels this one reads.
Surface description a Rnd::Mesh draws with.
Definition mat.h:36
Base of every object the renderer can load, resolve by name, and serialise.
Definition object.h:43
Byte stream that every renderer object serialises itself through.
Definition stream.h:31
Texture, as a bitmap path plus the load state of its mip levels.
Definition tex.h:43
The rendering engine.
Definition animhelper.h:3
MatAnim * NewMatAnim(const HxStr &name)
Allocate and construct a material animation.
void RegisterMatAnimClass()
Register the "MatAnim" class with Rnd::Manager, created through Rnd::CreateRegisteredMatAnim().
Object * CreateRegisteredMatAnim(const HxStr &name)
Allocate and construct a material animation for the registered "MatAnim" class.