wavelength 1.0.0
Loading...
Searching...
No Matches
rndmatanim.h
Go to the documentation of this file.
1#pragma once
2
3#include <list>
4#include <vector>
5
6#include "math/color.h"
7#include "math/key.h"
8#include "math/vector3.h"
9#include "rnd/rndanimatable.h"
10#include "rnd/rndmat.h"
11#include "rnd/rndtex.h"
12
19class RndMatAnim : public RndAnimatable {
20public:
22 static constexpr int kCopyShareKeys = 4;
23
29 class Stage {
30 public:
40 }
41
48 ~Stage() = default;
49
57 void Print(PrnStream &stream) const;
58
66 void Save(BinStream &stream) const;
67
79 void Load(BinStream &stream);
80
83 return mMatAnim;
84 }
85
87 void SetMatAnim(RndMatAnim *pMatAnim) {
88 mMatAnim = pMatAnim;
89 }
90
92 const std::vector<Key<Vector3>> &GetRotKeys() const {
93 return mRotKeys;
94 }
95
97 std::vector<Key<Vector3>> &GetRotKeys() {
98 return mRotKeys;
99 }
100
102 void SetRotKeys(const std::vector<Key<Vector3>> &keys) {
103 mRotKeys = keys;
104 }
105
107 const std::vector<Key<Vector3>> &GetScaleKeys() const {
108 return mScaleKeys;
109 }
110
112 std::vector<Key<Vector3>> &GetScaleKeys() {
113 return mScaleKeys;
114 }
115
117 void SetScaleKeys(const std::vector<Key<Vector3>> &keys) {
118 mScaleKeys = keys;
119 }
120
122 const std::vector<Key<RndTex *>> &GetTexKeys() const {
123 return mTexKeys;
124 }
125
127 std::vector<Key<RndTex *>> &GetTexKeys() {
128 return mTexKeys;
129 }
130
132 const std::vector<Key<Vector3>> &GetTransKeys() const {
133 return mTransKeys;
134 }
135
137 std::vector<Key<Vector3>> &GetTransKeys() {
138 return mTransKeys;
139 }
140
142 void SetTransKeys(const std::vector<Key<Vector3>> &keys) {
143 mTransKeys = keys;
144 }
145
146 private:
147 std::vector<Key<Vector3>> mTransKeys;
148 std::vector<Key<Vector3>> mScaleKeys;
149 std::vector<Key<Vector3>> mRotKeys;
150 std::vector<Key<RndTex *>> mTexKeys;
151 RndMatAnim *mMatAnim;
152 };
153
161 explicit RndMatAnim(const char *pszName);
162
169 ~RndMatAnim() override;
170
178 float EndFrame() override;
179
187 void ListAnimObjects(std::list<RndObject *> &objects) override;
188
200 int SetFrameSelf(float fFrame) override;
201
209 void DumpText(PrnStream &stream) override;
210
218 void Save(BinStream &stream) override;
219
231 void Replace(RndObject *pFrom, RndObject *pTo) override;
232
240 const char *ClassName() const override {
241 return sClassName;
242 }
243
255 void Copy(const RndObject *pSource, int nFlags) override;
256
267 void Load(BinStream &stream) override;
268
276 void SetMat(RndMat *pMat);
277
288 void ResizeStages(int nStages);
289
298 static RndObject *New(const char *pszName) {
299 return new RndMatAnim(pszName);
300 }
301
308 static const char *sClassName;
309
316 static int sRev;
317
323 static int sLoadRev;
324
326 const std::vector<Key<float>> &GetAlphaKeys() const {
327 return mAlphaKeys;
328 }
329
331 std::vector<Key<float>> &GetAlphaKeys() {
332 return mAlphaKeys;
333 }
334
336 const std::vector<Key<Color>> &GetBaseKeys() const {
337 return mBaseKeys;
338 }
339
341 std::vector<Key<Color>> &GetBaseKeys() {
342 return mBaseKeys;
343 }
344
347 return mKeysOwner;
348 }
349
351 const std::vector<Stage> &GetStages() const {
352 return mStages;
353 }
354
356 std::vector<Stage> &GetStages() {
357 return mStages;
358 }
359
360protected:
370
380
381private:
382 RndMat *mMat;
383 std::vector<Stage> mStages;
384 RndMatAnim *mKeysOwner;
385 std::vector<Key<Color>> mLightKeys;
386 std::vector<Key<Color>> mBaseKeys;
387 std::vector<Key<Color>> mEdgeKeys;
388 std::vector<Key<float>> mAlphaKeys;
389};
390
401
414
424PrnStream &operator<<(PrnStream &stream, const std::vector<RndMatAnim::Stage> &stages);
425
435BinStream &operator<<(BinStream &stream, const std::vector<RndMatAnim::Stage> &stages);
436
446BinStream &operator>>(BinStream &stream, std::vector<RndMatAnim::Stage> &stages);
Stream of raw bytes, the base of the memory, file, and network streams.
Definition binstream.h:22
Text output stream.
Definition prnstream.h:16
RndAnimatable()
Construct an animatable at frame 0 without children or filters.
Definition rndanimatable.h:600
const std::vector< Key< Vector3 > > & GetScaleKeys() const
Definition rndmatanim.h:107
void SetScaleKeys(const std::vector< Key< Vector3 > > &keys)
Definition rndmatanim.h:117
void SetTransKeys(const std::vector< Key< Vector3 > > &keys)
Definition rndmatanim.h:142
Stage()
Construct a stage without keys.
Definition rndmatanim.h:39
RndMatAnim * GetMatAnim() const
Definition rndmatanim.h:82
void Print(PrnStream &stream) const
Write a description of the keys.
~Stage()=default
Release the keys.
void SetMatAnim(RndMatAnim *pMatAnim)
Definition rndmatanim.h:87
void SetRotKeys(const std::vector< Key< Vector3 > > &keys)
Definition rndmatanim.h:102
const std::vector< Key< Vector3 > > & GetRotKeys() const
Definition rndmatanim.h:92
std::vector< Key< Vector3 > > & GetScaleKeys()
Definition rndmatanim.h:112
std::vector< Key< Vector3 > > & GetTransKeys()
Definition rndmatanim.h:137
void Save(BinStream &stream) const
Write the keys.
const std::vector< Key< RndTex * > > & GetTexKeys() const
Definition rndmatanim.h:122
std::vector< Key< Vector3 > > & GetRotKeys()
Definition rndmatanim.h:97
std::vector< Key< RndTex * > > & GetTexKeys()
Definition rndmatanim.h:127
const std::vector< Key< Vector3 > > & GetTransKeys() const
Definition rndmatanim.h:132
void Load(BinStream &stream)
Read what Save() wrote, or an earlier version of it.
std::vector< Key< Color > > & GetBaseKeys()
Definition rndmatanim.h:341
static constexpr int kCopyShareKeys
The bit of the Copy() flags that shares the source's keys rather than copying them.
Definition rndmatanim.h:22
void Load(BinStream &stream) override
Read what Save() wrote, or an earlier version of it.
std::vector< Key< float > > & GetAlphaKeys()
Definition rndmatanim.h:331
const char * ClassName() const override
Report the class name.
Definition rndmatanim.h:240
const std::vector< Stage > & GetStages() const
Definition rndmatanim.h:351
static const char * sClassName
The class name a .rnd file writes, MatAnim.
Definition rndmatanim.h:308
static int sLoadRev
The version Load() read last, which Stage::Load() reads by.
Definition rndmatanim.h:323
std::vector< Stage > & GetStages()
Definition rndmatanim.h:356
RndMatAnim * GetKeysOwner() const
Definition rndmatanim.h:346
static int sRev
The format version Save() writes and Load() accepts.
Definition rndmatanim.h:316
void ListAnimObjects(std::list< RndObject * > &objects) override
Add the material to a list, then the objects of the children.
void SetMat(RndMat *pMat)
Set the material the animation drives.
void DumpText(PrnStream &stream) override
Write a description of the animation and its base.
float EndFrame() override
Report the last frame of any key.
void AcquireRefs()
Take references on the material, the keys owner, and the textures of the stages.
void ReleaseRefs()
Drop the references on the material, the keys owner, and the textures of the stages.
static RndObject * New(const char *pszName)
Create an animation.
Definition rndmatanim.h:298
~RndMatAnim() override
Drop the references on the material, the keys owner, and the textures.
void Save(BinStream &stream) override
Write the animation and its base.
void Replace(RndObject *pFrom, RndObject *pTo) override
Replace a referenced object with another.
const std::vector< Key< float > > & GetAlphaKeys() const
Definition rndmatanim.h:326
int SetFrameSelf(float fFrame) override
Apply a frame to the material.
void Copy(const RndObject *pSource, int nFlags) override
Copy another animation and its base.
void ResizeStages(int nStages)
Resize the stages of the keys owner.
RndMatAnim(const char *pszName)
Construct an animation of nothing without keys.
const std::vector< Key< Color > > & GetBaseKeys() const
Definition rndmatanim.h:336
Surface description: blending, lighting colours, culling, and a list of texture stages.
Definition rndmat.h:20
RndObject(const char *pszName)
Construct an object and register it under a name.
BinStream & operator>>(BinStream &stream, Key< RndTex * > &key)
Read a texture key the texture key writer wrote, resolving the name in TheManager.
BinStream & operator<<(BinStream &stream, const Key< RndTex * > &key)
Write a texture key as the texture's name, empty for none, followed by its frame.
One keyframe of an animation channel, a value at a frame.
Definition key.h:21