NW4F G3d
Loading...
Searching...
No Matches
g3d_SkeletonObj.h
Go to the documentation of this file.
1#ifndef NW_G3D_SKELETON_H_
2#define NW_G3D_SKELETON_H_
3
4#include <nw/g3d/g3d_config.h>
5#include <nw/g3d/fnd/g3d_GfxObject.h>
6#include <nw/g3d/res/g3d_ResSkeleton.h>
7#include <nw/g3d/g3d_Sizer.h>
8
9namespace nw { namespace g3d {
10
17
18class LocalMtx : public LocalMtxData
19{
20public:
21 LocalMtx() : LocalMtxData() { flag = 0; }
22
24
25 static LocalMtx& DownCast(LocalMtxData& data) { return static_cast<LocalMtx&>(data); }
26
27 static const LocalMtx& DownCast(const LocalMtxData& data)
28 {
29 return static_cast<const LocalMtx&>(data);
30 }
31
32 static LocalMtx* DownCast(LocalMtxData* data) { return static_cast<LocalMtx*>(data); }
33
34 static const LocalMtx* DownCast(const LocalMtxData* data)
35 {
36 return static_cast<const LocalMtx*>(data);
37 }
38};
39
41{
42public:
43 WorldMtxManip(Mtx34* pMtx, Vec3* pScale, bit32* pFlag)
44 : m_pMtx(pMtx), m_pScale(pScale), m_pFlag(pFlag)
45 {
48 }
49
50 const Vec3* GetScale() const { return m_pScale; }
51
52 const Mtx34* GetMtx() const { return m_pMtx; }
53
59
60 bit32 GetFlag() const { return *m_pFlag; }
61
62private:
66
68};
69
71{
72public:
73 enum { INVALID_BONE = 0xFFFF };
74
75 virtual ~ICalcWorldCallback() {}
76
78 {
79 public:
80 CallbackArg(const int& boneIndex, int callbackBone)
81 : m_BoneIndex(boneIndex), m_CallbackBone(callbackBone)
82 {
83 }
84
85 int GetBoneIndex() const { return m_BoneIndex; }
86
87 int GetCallbackBoneIndex() const { return m_CallbackBone; }
88
89 void SetCallbackBoneIndex(int boneIndex) { m_CallbackBone = boneIndex; }
90
91 private:
92 const int& m_BoneIndex;
94
96 };
97
98 virtual void Exec(CallbackArg& arg, WorldMtxManip& manip) = 0;
99};
100
102{
103public:
127
128 class InitArg;
129
136
138
139 static size_t CalcBufferSize(const InitArg& arg);
140
141 bool Init(const InitArg& arg, void* pBuffer, size_t bufferSize);
142
144
145 bool SetupBlockBuffer(void* pBuffer, size_t bufferSize);
146
148
149 void ClearLocalMtx();
150
151 void CalcWorldMtx(const Mtx34& baseMtx);
152
153 void CalcBillboardMtx(Mtx34* pMtxArray, const Mtx34& cameraMtx, int boneIndex,
154 bool combineWorld = false) const;
155
156 void CalcMtxBlock(int bufferIndex = 0);
157
159
160 const ResSkeleton* GetResource() const { return m_pRes; }
161
162 void* GetBufferPtr() { return m_pBufferPtr; }
163
165
166 bool IsBlockBufferValid() const { return (m_Flag & BLOCK_BUFFER_VALID) != 0; }
167
168 int GetScaleMode() const { return m_Flag & SCALE_MASK; }
169
170 int GetRotateMode() const { return m_Flag & ROT_MASK; }
171
177
183
188
189 const Mtx34* GetWorldMtxArray() const
190 {
192 return m_pWorldMtxArray;
193 }
194
195 GfxBuffer& GetMtxBlock() { return m_MtxBlock; }
196
197 const GfxBuffer& GetMtxBlock() const { return m_MtxBlock; }
198
199 int GetBufferingCount() const { return m_NumBuffering; }
200
202
204
205 bool IsBlockSwapEnabled() const { return (m_Flag & BLOCK_BUFFER_SWAP) != 0; }
206
207 void SetUserPtr(void* pUserPtr) { m_pUserPtr = pUserPtr; }
208
209 void* GetUserPtr() { return m_pUserPtr; }
210
211 const void* GetUserPtr() const { return m_pUserPtr; }
212
213 template <typename T>
214 T* GetUserPtr() { return static_cast<T*>(m_pUserPtr); }
215
216 template <typename T>
217 const T* GetUserPtr() const { return static_cast<const T*>(m_pUserPtr); }
218
219 int GetBoneCount() const { return m_NumBone; }
220
221 ResBone* GetBone(int boneIndex)
222 {
223 return ResBone::ResCast(&m_pBoneArray[boneIndex]);
224 }
225
226 const ResBone* GetBone(int boneIndex) const
227 {
228 return ResBone::ResCast(&m_pBoneArray[boneIndex]);
229 }
230
231 ResBone* GetBone(const char* name) { return m_pRes->GetBone(name); }
232
233 const ResBone* GetBone(const char* name) const { return m_pRes->GetBone(name); }
234
235 const char* GetBoneName(int boneIndex) const { return m_pRes->GetBoneName(boneIndex); }
236
237 int GetBoneIndex(const char* name) const { return m_pRes->GetBoneIndex(name); }
238
239 void SetCalcWorldCallback(ICalcWorldCallback* pCallback) { m_pCallback = pCallback; }
240
242
244
245 void SetCallbackBoneIndex(int boneIndex)
246 {
247 m_CallbackBone = (boneIndex >= 0 && boneIndex < m_NumBone) ?
248 static_cast<u16>(boneIndex) : ICalcWorldCallback::INVALID_BONE;
249 }
250
252 {
253 return m_CallbackBone >= ICalcWorldCallback::INVALID_BONE ? -1 : m_CallbackBone;
254 }
255
257 {
258 return Align(sizeof(LocalMtx) * m_NumBone, LL_CACHE_FETCH_SIZE);
259 }
260
261 size_t LCMountLocalMtx(void* pLC, size_t size, bool load);
262
263 void LCUnmountLocalMtx(bool store);
264
265 bool IsLocalMtxOnCache() const { return !!(m_Flag & MASK_LOCAL_MTX); }
266
268 {
269 return Align(sizeof(Mtx34) * m_NumBone, LL_CACHE_FETCH_SIZE);
270 }
271
272 size_t LCMountWorldMtx(void* pLC, size_t size, bool load);
273
274 void LCUnmountWorldMtx(bool store);
275
276 bool IsWorldMtxOnCache() const { return !!(m_Flag & MASK_WORLD_MTX); }
277
279 {
280 return Align(sizeof(Mtx34) * m_pRes->GetMtxCount(), LL_CACHE_FETCH_SIZE);
281 }
282
283 size_t LCMountMtxBlock(void* pLC, size_t size, bool load, int bufferIndex = 0);
284
285 void LCUnmountMtxBlock(bool store, int bufferIndex = 0);
286
287protected:
288 class Impl;
289
290 template<typename CalcType, bool useCallback>
291 void CalcWorldImpl(const Mtx34& baseMtx);
292
293private:
294 class Sizer;
295
297
298 mutable bit16 m_Flag;
301
306
308
312
319
321};
322
323class SkeletonObj::Sizer : public nw::g3d::Sizer
324{
325public:
327
328 void Calc(const InitArg& arg);
329
330 enum
331 {
336 };
337
339};
340
342{
343public:
344 explicit InitArg(ResSkeleton* resource)
345 : m_pRes(resource)
346 , m_NumBuffering(1)
347 {
348 NW_G3D_ASSERT_NOT_NULL(resource);
349 }
350
351 void BufferingCount(int count) { m_NumBuffering = count; m_Sizer.Invalidate(); }
352
353 int GetBufferingCount() const { return m_NumBuffering; }
354
355 ResSkeleton* GetResource() const { return m_pRes; }
356
357 Sizer& GetSizer() const { return m_Sizer; }
358
359private:
362 mutable Sizer m_Sizer;
363};
364
365} } // namespace nw::g3d
366
367#endif // NW_G3D_SKELETON_H_
Definition g3d_SkeletonObj.h:78
const int & m_BoneIndex
Definition g3d_SkeletonObj.h:92
int m_CallbackBone
Definition g3d_SkeletonObj.h:93
void SetCallbackBoneIndex(int boneIndex)
Definition g3d_SkeletonObj.h:89
CallbackArg(const int &boneIndex, int callbackBone)
Definition g3d_SkeletonObj.h:80
int GetCallbackBoneIndex() const
Definition g3d_SkeletonObj.h:87
int GetBoneIndex() const
Definition g3d_SkeletonObj.h:85
Definition g3d_SkeletonObj.h:71
virtual ~ICalcWorldCallback()
Definition g3d_SkeletonObj.h:75
virtual void Exec(CallbackArg &arg, WorldMtxManip &manip)=0
@ INVALID_BONE
Definition g3d_SkeletonObj.h:73
Definition g3d_SkeletonObj.h:19
void EndEdit()
Definition g3d_SkeletonObj.h:23
static LocalMtx & DownCast(LocalMtxData &data)
Definition g3d_SkeletonObj.h:25
static LocalMtx * DownCast(LocalMtxData *data)
Definition g3d_SkeletonObj.h:32
static const LocalMtx * DownCast(const LocalMtxData *data)
Definition g3d_SkeletonObj.h:34
LocalMtx()
Definition g3d_SkeletonObj.h:21
static const LocalMtx & DownCast(const LocalMtxData &data)
Definition g3d_SkeletonObj.h:27
Definition g3d_Sizer.h:10
Sizer()
Definition g3d_Sizer.h:18
Definition g3d_SkeletonObj.cpp:10
Definition g3d_SkeletonObj.h:342
int GetBufferingCount() const
Definition g3d_SkeletonObj.h:353
InitArg(ResSkeleton *resource)
Definition g3d_SkeletonObj.h:344
ResSkeleton * GetResource() const
Definition g3d_SkeletonObj.h:355
void BufferingCount(int count)
Definition g3d_SkeletonObj.h:351
Sizer & GetSizer() const
Definition g3d_SkeletonObj.h:357
Sizer m_Sizer
Definition g3d_SkeletonObj.h:362
ResSkeleton * m_pRes
Definition g3d_SkeletonObj.h:360
int m_NumBuffering
Definition g3d_SkeletonObj.h:361
Definition g3d_SkeletonObj.h:324
void Calc(const InitArg &arg)
Definition g3d_SkeletonObj.cpp:35
@ LOCAL_MTX
Definition g3d_SkeletonObj.h:333
@ SCALE
Definition g3d_SkeletonObj.h:334
@ NUM_CHUNK
Definition g3d_SkeletonObj.h:335
@ WORLD_MTX
Definition g3d_SkeletonObj.h:332
Chunk chunk[NUM_CHUNK]
Definition g3d_SkeletonObj.h:338
Sizer()
Definition g3d_SkeletonObj.h:326
Definition g3d_SkeletonObj.h:102
size_t CalcBlockBufferSize() const
Definition g3d_SkeletonObj.cpp:100
ICalcWorldCallback * GetCalcWorldCallback()
Definition g3d_SkeletonObj.h:241
const ResBone * GetBone(const char *name) const
Definition g3d_SkeletonObj.h:233
GfxBuffer m_MtxBlock
Definition g3d_SkeletonObj.h:307
Mtx34 * m_pWorldMtxArray
Definition g3d_SkeletonObj.h:304
void * GetBlockBufferPtr()
Definition g3d_SkeletonObj.h:164
LocalMtxData * m_pLocalMtxArray
Definition g3d_SkeletonObj.h:303
void * m_pUserPtr
Definition g3d_SkeletonObj.h:316
void * m_pMemLocalMtxArray
Definition g3d_SkeletonObj.h:313
GfxBuffer & GetMtxBlock()
Definition g3d_SkeletonObj.h:195
T * GetUserPtr()
Definition g3d_SkeletonObj.h:214
size_t LCMountWorldMtx(void *pLC, size_t size, bool load)
const ResBone * GetBone(int boneIndex) const
Definition g3d_SkeletonObj.h:226
u16 m_CallbackBone
Definition g3d_SkeletonObj.h:310
ResSkeleton * GetResource()
Definition g3d_SkeletonObj.h:158
bool IsBlockBufferValid() const
Definition g3d_SkeletonObj.h:166
Mtx34 * GetWorldMtxArray()
Definition g3d_SkeletonObj.h:184
void SetCallbackBoneIndex(int boneIndex)
Definition g3d_SkeletonObj.h:245
ResBone * GetBone(const char *name)
Definition g3d_SkeletonObj.h:231
int GetScaleMode() const
Definition g3d_SkeletonObj.h:168
u8 m_NumBuffering
Definition g3d_SkeletonObj.h:299
void * m_pMemWorldMtxArray
Definition g3d_SkeletonObj.h:314
size_t CalcWorldMtxLCSize() const
Definition g3d_SkeletonObj.h:267
void * m_pBlockBuffer
Definition g3d_SkeletonObj.h:318
void CalcWorldImpl(const Mtx34 &baseMtx)
Definition g3d_SkeletonObj.cpp:296
const T * GetUserPtr() const
Definition g3d_SkeletonObj.h:217
void LCUnmountWorldMtx(bool store)
int GetRotateMode() const
Definition g3d_SkeletonObj.h:170
ResBone * GetBone(int boneIndex)
Definition g3d_SkeletonObj.h:221
size_t LCMountLocalMtx(void *pLC, size_t size, bool load)
ICalcWorldCallback * m_pCallback
Definition g3d_SkeletonObj.h:311
void EnableBlockSwap()
Definition g3d_SkeletonObj.h:201
bool IsBlockSwapEnabled() const
Definition g3d_SkeletonObj.h:205
static size_t CalcBufferSize(const InitArg &arg)
Definition g3d_SkeletonObj.cpp:51
int GetBoneIndex(const char *name) const
Definition g3d_SkeletonObj.h:237
const ResSkeleton * GetResource() const
Definition g3d_SkeletonObj.h:160
void SetCalcWorldCallback(ICalcWorldCallback *pCallback)
Definition g3d_SkeletonObj.h:239
size_t CalcMtxBlockLCSize() const
Definition g3d_SkeletonObj.h:278
const void * GetUserPtr() const
Definition g3d_SkeletonObj.h:211
void LCUnmountMtxBlock(bool store, int bufferIndex=0)
void SetUserPtr(void *pUserPtr)
Definition g3d_SkeletonObj.h:207
u16 m_NumBone
Definition g3d_SkeletonObj.h:309
bool SetupBlockBuffer(void *pBuffer, size_t bufferSize)
Definition g3d_SkeletonObj.cpp:105
const GfxBuffer & GetMtxBlock() const
Definition g3d_SkeletonObj.h:197
ResSkeleton * m_pRes
Definition g3d_SkeletonObj.h:296
int GetBufferingCount() const
Definition g3d_SkeletonObj.h:199
void LCUnmountLocalMtx(bool store)
void CalcBillboardMtx(Mtx34 *pMtxArray, const Mtx34 &cameraMtx, int boneIndex, bool combineWorld=false) const
Definition g3d_SkeletonObj.cpp:161
bit16 m_Flag
Definition g3d_SkeletonObj.h:298
Vec3 * m_pScaleArray
Definition g3d_SkeletonObj.h:305
void ClearLocalMtx()
Definition g3d_SkeletonObj.cpp:130
const ICalcWorldCallback * GetCalcWorldCallback() const
Definition g3d_SkeletonObj.h:243
bool IsLocalMtxOnCache() const
Definition g3d_SkeletonObj.h:265
Alignment
Definition g3d_SkeletonObj.h:131
@ BLOCK_BUFFER_ALIGNMENT
Definition g3d_SkeletonObj.h:134
@ BUFFER_ALIGNMENT
Definition g3d_SkeletonObj.h:132
int GetBoneCount() const
Definition g3d_SkeletonObj.h:219
const LocalMtx * GetLocalMtxArray() const
Definition g3d_SkeletonObj.h:178
SkeletonObj()
Definition g3d_SkeletonObj.h:137
size_t LCMountMtxBlock(void *pLC, size_t size, bool load, int bufferIndex=0)
void DisableBlockSwap()
Definition g3d_SkeletonObj.h:203
void * m_pBufferPtr
Definition g3d_SkeletonObj.h:317
bool Init(const InitArg &arg, void *pBuffer, size_t bufferSize)
Definition g3d_SkeletonObj.cpp:58
int GetCallbackBoneIndex() const
Definition g3d_SkeletonObj.h:251
size_t CalcLocalMtxLCSize() const
Definition g3d_SkeletonObj.h:256
void * GetBufferPtr()
Definition g3d_SkeletonObj.h:162
void CalcMtxBlock(int bufferIndex=0)
Definition g3d_SkeletonObj.cpp:220
const Mtx34 * GetWorldMtxArray() const
Definition g3d_SkeletonObj.h:189
bool IsWorldMtxOnCache() const
Definition g3d_SkeletonObj.h:276
Flag
Definition g3d_SkeletonObj.h:105
@ ROT_QUAT
Definition g3d_SkeletonObj.h:124
@ SCALE_SHIFT
Definition g3d_SkeletonObj.h:115
@ ROT_MASK
Definition g3d_SkeletonObj.h:125
@ CACHE_LOCAL_MTX
Definition g3d_SkeletonObj.h:108
@ INVALID_WORLD_MTX
Definition g3d_SkeletonObj.h:112
@ INVALID_LOCAL_MTX
Definition g3d_SkeletonObj.h:109
@ SCALE_NONE
Definition g3d_SkeletonObj.h:116
@ ROT_EULER_XYZ
Definition g3d_SkeletonObj.h:123
@ ROT_SHIFT
Definition g3d_SkeletonObj.h:122
@ SCALE_MASK
Definition g3d_SkeletonObj.h:120
@ SCALE_MAYA
Definition g3d_SkeletonObj.h:118
@ MASK_LOCAL_MTX
Definition g3d_SkeletonObj.h:110
@ SCALE_STD
Definition g3d_SkeletonObj.h:117
@ CACHE_WORLD_MTX
Definition g3d_SkeletonObj.h:111
@ BLOCK_BUFFER_VALID
Definition g3d_SkeletonObj.h:106
@ MASK_WORLD_MTX
Definition g3d_SkeletonObj.h:113
@ BLOCK_BUFFER_SWAP
Definition g3d_SkeletonObj.h:107
@ SCALE_SOFTIMAGE
Definition g3d_SkeletonObj.h:119
void * GetUserPtr()
Definition g3d_SkeletonObj.h:209
const char * GetBoneName(int boneIndex) const
Definition g3d_SkeletonObj.h:235
LocalMtx * GetLocalMtxArray()
Definition g3d_SkeletonObj.h:172
ResBoneData * m_pBoneArray
Definition g3d_SkeletonObj.h:302
u8 reserved
Definition g3d_SkeletonObj.h:300
void CalcWorldMtx(const Mtx34 &baseMtx)
Definition g3d_SkeletonObj.cpp:198
void * m_pLCMtxBlock
Definition g3d_SkeletonObj.h:315
Definition g3d_SkeletonObj.h:41
Mtx34 * m_pMtx
Definition g3d_SkeletonObj.h:63
bit32 GetFlag() const
Definition g3d_SkeletonObj.h:60
Vec3 * m_pScale
Definition g3d_SkeletonObj.h:64
const Mtx34 * GetMtx() const
Definition g3d_SkeletonObj.h:52
WorldMtxManip(Mtx34 *pMtx, Vec3 *pScale, bit32 *pFlag)
Definition g3d_SkeletonObj.h:43
bit32 * m_pFlag
Definition g3d_SkeletonObj.h:65
Mtx34 * EditMtx()
Definition g3d_SkeletonObj.h:54
const Vec3 * GetScale() const
Definition g3d_SkeletonObj.h:50
Definition g3d_GfxObject.h:48
Definition g3d_Matrix34.h:34
Definition g3d_Vector3.h:30
Definition g3d_ResSkeleton.h:41
@ HI_ROTTRANS_ZERO
Definition g3d_ResSkeleton.h:82
@ IDENTITY
Definition g3d_ResSkeleton.h:73
@ ROTTRANS_ZERO
Definition g3d_ResSkeleton.h:72
Definition g3d_ResSkeleton.h:162
@ SCALE_SOFTIMAGE
Definition g3d_ResSkeleton.h:174
@ ROT_EULER_XYZ
Definition g3d_ResSkeleton.h:179
@ SCALE_STD
Definition g3d_ResSkeleton.h:172
@ SCALE_MASK
Definition g3d_ResSkeleton.h:175
@ ROT_SHIFT
Definition g3d_ResSkeleton.h:177
@ SCALE_SHIFT
Definition g3d_ResSkeleton.h:170
@ ROT_MASK
Definition g3d_ResSkeleton.h:180
@ SCALE_NONE
Definition g3d_ResSkeleton.h:171
@ ROT_QUAT
Definition g3d_ResSkeleton.h:178
@ SCALE_MAYA
Definition g3d_ResSkeleton.h:173
#define NW_G3D_ASSERT_NOT_NULL(exp)
Definition g3d_assert.h:20
#define NW_G3D_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition g3d_defs.h:81
u16 bit16
Definition g3d_defs.h:130
u32 bit32
Definition g3d_defs.h:131
Definition g3d_GfxManage.cpp:10
Definition g3d_SkeletonObj.h:12
Vec3 scale
Definition g3d_SkeletonObj.h:14
Mtx34 mtxRT
Definition g3d_SkeletonObj.h:15
bit32 flag
Definition g3d_SkeletonObj.h:13
Definition g3d_Sizer.h:13
Definition g3d_ResSkeleton.h:17