NW4F G3d
Loading...
Searching...
No Matches
g3d_ModelObj.h
Go to the documentation of this file.
1#ifndef NW_G3D_MODELOBJ_H_
2#define NW_G3D_MODELOBJ_H_
3
4#include <nw/g3d/g3d_config.h>
5#include <nw/g3d/res/g3d_ResModel.h>
6#include <nw/g3d/g3d_SkeletonObj.h>
7#include <nw/g3d/g3d_ShapeObj.h>
8#include <nw/g3d/g3d_MaterialObj.h>
9#include <nw/g3d/g3d_Sizer.h>
10#include <nw/g3d/ut/g3d_Flag.h>
11
12namespace nw { namespace g3d {
13
15{
16public:
17 class InitArg;
18
25
27
28 static size_t CalcBufferSize(const InitArg& arg);
29
30 bool Init(const InitArg& arg, void* pBuffer, size_t bufferSize);
31
33
34 bool SetupBlockBuffer(void* pBuffer, size_t bufferSize);
35
37
38 void CalcWorld(const Mtx34& baseMtx);
39
40 void CalcBounding();
41
42 void CalcMtxBlock(int bufferIndex = 0);
43
44 void CalcShape(int bufferIndex = 0);
45
46 void CalcMaterial();
47
48 void CalcView(int viewIndex, const Mtx34& cameraMtx, int bufferIndex = 0);
49
51
52 const ResModel* GetResource() const { return m_pRes; }
53
54 void* GetBufferPtr() { return m_pBufferPtr; }
55
57
58 bool IsBlockBufferValid() const { return (m_Flag & BLOCK_BUFFER_VALID) != 0; }
59
61
63
64 int GetViewCount() const { return m_NumView; }
65
66 bool IsViewDependent() const { return !!m_ViewDependent; }
67
69
71
72 const Sphere* GetBounding() const { return m_pBounding; }
73
74 void SetUserPtr(void* pUserPtr) { m_pUserPtr = pUserPtr; }
75
76 void* GetUserPtr() { return m_pUserPtr; }
77
78 const void* GetUserPtr() const { return m_pUserPtr; }
79
80 template <typename T>
81 T* GetUserPtr() { return static_cast<T*>(m_pUserPtr); }
82
83 template <typename T>
84 const T* GetUserPtr() const { return static_cast<const T*>(m_pUserPtr); }
85
86 bool IsShapeVisible(int shapeIndex) const
87 {
88 const ShapeObj* pShape = GetShape(shapeIndex);
91 }
92
93 bool IsBoneVisible(int boneIndex) const
94 {
95 NW_G3D_ASSERT_INDEX_BOUNDS(boneIndex, GetSkeleton()->GetBoneCount());
96 return IsBitOn<bool>(m_pBoneVisArray, boneIndex);
97 }
98
99 void SetBoneVisibility(int boneIndex, bool visible)
100 {
101 NW_G3D_ASSERT_INDEX_BOUNDS(boneIndex, GetSkeleton()->GetBoneCount());
102 SetBit(m_pBoneVisArray, boneIndex, visible ? 1 : 0);
103 }
104
106
107 const bit32* GetBoneVisArray() const { return m_pBoneVisArray; }
108
109 void ClearBoneVisibility();
110
111 bool IsMatVisible(int matIndex) const
112 {
113 NW_G3D_ASSERT_INDEX_BOUNDS(matIndex, GetMaterialCount());
114 return IsBitOn<bool>(m_pMatVisArray, matIndex);
115 }
116
117 void SetMatVisibility(int matIndex, bool visible)
118 {
119 NW_G3D_ASSERT_INDEX_BOUNDS(matIndex, GetMaterialCount());
120 SetBit(m_pMatVisArray, matIndex, visible ? 1 : 0);
121 }
122
124
125 const bit32* GetMatVisArray() const { return m_pMatVisArray; }
126
127 void ClearMatVisibility();
128
130
131 const SkeletonObj* GetSkeleton() const { return m_pSkeleton; }
132
133 int GetShapeCount() const { return m_NumShape; }
134
135 ShapeObj* GetShape(int shapeIndex)
136 {
137 NW_G3D_ASSERT_INDEX_BOUNDS(shapeIndex, m_NumShape);
138 return &m_pShapeArray[shapeIndex];
139 }
140
141 const ShapeObj* GetShape(int shapeIndex) const
142 {
143 NW_G3D_ASSERT_INDEX_BOUNDS(shapeIndex, m_NumShape);
144 return &m_pShapeArray[shapeIndex];
145 }
146
147 ShapeObj* GetShape(const char* name)
148 {
149 int shapeIndex = m_pRes->GetShapeIndex(name);
150 return shapeIndex >= 0 ? GetShape(shapeIndex) : NULL;
151 }
152
153 const ShapeObj* GetShape(const char* name) const
154 {
155 int shapeIndex = m_pRes->GetShapeIndex(name);
156 return shapeIndex >= 0 ? GetShape(shapeIndex) : NULL;
157 }
158
159 const char* GetShapeName(int shapeIndex) const { return m_pRes->GetShapeName(shapeIndex); }
160
161 int GetShapeIndex(const char* name) const { return m_pRes->GetShapeIndex(name); }
162
163 int GetMaterialCount() const { return m_NumMaterial; }
164
166 {
167 NW_G3D_ASSERT_INDEX_BOUNDS(matIndex, m_NumMaterial);
168 return &m_pMaterialArray[matIndex];
169 }
170
171 const MaterialObj* GetMaterial(int matIndex) const
172 {
173 NW_G3D_ASSERT_INDEX_BOUNDS(matIndex, m_NumMaterial);
174 return &m_pMaterialArray[matIndex];
175 }
176
177 MaterialObj* GetMaterial(const char* name)
178 {
179 int matIndex = m_pRes->GetMaterialIndex(name);
180 return matIndex >= 0 ? GetMaterial(matIndex) : NULL;
181 }
182
183 const MaterialObj* GetMaterial(const char* name) const
184 {
185 int matIndex = m_pRes->GetMaterialIndex(name);
186 return matIndex >= 0 ? GetMaterial(matIndex) : NULL;
187 }
188
189 const char* GetMaterialName(int matIndex) const { return m_pRes->GetMaterialName(matIndex); }
190
191 int GetMaterialIndex(const char* name) const { return m_pRes->GetMaterialIndex(name); }
192
193protected:
194 class Sizer;
195
196 enum Flag
197 {
199 };
200
201private:
202
204
211
214
219
223
225};
226
250
252{
253public:
254 explicit InitArg(ResModel* resource)
255 : m_pRes(resource)
259
260 , m_NumView(1)
261
262 , m_BoundingEnabled(false)
263 {
264 NW_G3D_ASSERT_NOT_NULL(resource);
265 }
266
267 void Skeleton(SkeletonObj* pSkeleton) { m_pSkeleton = pSkeleton; m_Sizer.Invalidate(); }
268
269 void SkeletonBufferingCount(int count) { m_NumSkelBuffering = count; m_Sizer.Invalidate(); }
270
271 void ShapeBufferingCount(int count) { m_NumShpBuffering = count; m_Sizer.Invalidate(); }
272
273 void ViewCount(int count) { m_NumView = count; m_Sizer.Invalidate(); }
274
275 void EnableBounding() { m_BoundingEnabled = true; m_Sizer.Invalidate(); }
276
277 void DisableBounding() { m_BoundingEnabled = false; m_Sizer.Invalidate(); }
278
279 ResModel* GetResource() const { return m_pRes; }
280
282
284
286
287 int GetViewCount() const { return m_NumView; }
288
289 bool IsBoundingEnabled() const { return m_BoundingEnabled; }
290
291 Sizer& GetSizer() const { return m_Sizer; }
292
293private:
298
300
302 mutable Sizer m_Sizer;
303};
304
305} } // namespace nw::g3d
306
307#endif // NW_G3D_MODELOBJ_H_
Definition g3d_MaterialObj.h:11
Definition g3d_ModelObj.h:252
void ViewCount(int count)
Definition g3d_ModelObj.h:273
void DisableBounding()
Definition g3d_ModelObj.h:277
void SkeletonBufferingCount(int count)
Definition g3d_ModelObj.h:269
void ShapeBufferingCount(int count)
Definition g3d_ModelObj.h:271
bool m_BoundingEnabled
Definition g3d_ModelObj.h:301
int GetSkeletonBufferingCount() const
Definition g3d_ModelObj.h:283
InitArg(ResModel *resource)
Definition g3d_ModelObj.h:254
int GetViewCount() const
Definition g3d_ModelObj.h:287
SkeletonObj * GetSkeleton() const
Definition g3d_ModelObj.h:281
int GetShapeBufferingCount() const
Definition g3d_ModelObj.h:285
int m_NumView
Definition g3d_ModelObj.h:299
int m_NumSkelBuffering
Definition g3d_ModelObj.h:296
SkeletonObj * m_pSkeleton
Definition g3d_ModelObj.h:295
ResModel * m_pRes
Definition g3d_ModelObj.h:294
Sizer & GetSizer() const
Definition g3d_ModelObj.h:291
int m_NumShpBuffering
Definition g3d_ModelObj.h:297
void EnableBounding()
Definition g3d_ModelObj.h:275
Sizer m_Sizer
Definition g3d_ModelObj.h:302
ResModel * GetResource() const
Definition g3d_ModelObj.h:279
void Skeleton(SkeletonObj *pSkeleton)
Definition g3d_ModelObj.h:267
bool IsBoundingEnabled() const
Definition g3d_ModelObj.h:289
Definition g3d_ModelObj.h:228
void Calc(const InitArg &arg)
Definition g3d_ModelObj.cpp:5
Sizer()
Definition g3d_ModelObj.h:230
@ MATERIAL_BUFFER
Definition g3d_ModelObj.h:238
@ SKELETON
Definition g3d_ModelObj.h:239
@ SKELETON_BUFFER
Definition g3d_ModelObj.h:236
@ NUM_CHUNK
Definition g3d_ModelObj.h:245
@ MATERIAL_ARRAY
Definition g3d_ModelObj.h:241
@ BOUNDING
Definition g3d_ModelObj.h:244
@ SHAPE_BUFFER
Definition g3d_ModelObj.h:237
@ BONE_VIS_ARRAY
Definition g3d_ModelObj.h:242
@ MAT_VIS_ARRAY
Definition g3d_ModelObj.h:243
@ SHAPE_ARRAY
Definition g3d_ModelObj.h:240
Chunk chunk[NUM_CHUNK]
Definition g3d_ModelObj.h:248
Definition g3d_ModelObj.h:15
bit32 * m_pBoneVisArray
Definition g3d_ModelObj.h:205
const void * GetUserPtr() const
Definition g3d_ModelObj.h:78
void CalcShape(int bufferIndex=0)
Definition g3d_ModelObj.cpp:381
void CalcMtxBlock(int bufferIndex=0)
Definition g3d_ModelObj.cpp:322
ResModel * GetResource()
Definition g3d_ModelObj.h:50
void ClearBoneVisibility()
Definition g3d_ModelObj.cpp:404
GfxBuffer * m_pViewBlockArray
Definition g3d_ModelObj.h:210
const T * GetUserPtr() const
Definition g3d_ModelObj.h:84
MaterialObj * GetMaterial(const char *name)
Definition g3d_ModelObj.h:177
u8 m_NumView
Definition g3d_ModelObj.h:207
const ResModel * GetResource() const
Definition g3d_ModelObj.h:52
const char * GetShapeName(int shapeIndex) const
Definition g3d_ModelObj.h:159
void * GetBufferPtr()
Definition g3d_ModelObj.h:54
void CleanupBlockBuffer()
bool IsBlockBufferValid() const
Definition g3d_ModelObj.h:58
int GetShapeIndex(const char *name) const
Definition g3d_ModelObj.h:161
void EnableBlockSwapAll()
SkeletonObj * GetSkeleton()
Definition g3d_ModelObj.h:129
ShapeObj * GetShape(int shapeIndex)
Definition g3d_ModelObj.h:135
void CalcView(int viewIndex, const Mtx34 &cameraMtx, int bufferIndex=0)
Definition g3d_ModelObj.cpp:327
void CalcMaterial()
Definition g3d_ModelObj.cpp:395
bit32 * GetBoneVisArray()
Definition g3d_ModelObj.h:105
int GetMaterialCount() const
Definition g3d_ModelObj.h:163
bit16 m_Flag
Definition g3d_ModelObj.h:209
void * m_pBufferPtr
Definition g3d_ModelObj.h:221
const Sphere * GetBounding() const
Definition g3d_ModelObj.h:72
Sphere * GetBounding()
Definition g3d_ModelObj.h:70
SkeletonObj * m_pSkeleton
Definition g3d_ModelObj.h:215
MaterialObj * m_pMaterialArray
Definition g3d_ModelObj.h:217
bool IsShapeVisible(int shapeIndex) const
Definition g3d_ModelObj.h:86
void * GetBlockBufferPtr()
Definition g3d_ModelObj.h:56
ShapeObj * GetShape(const char *name)
Definition g3d_ModelObj.h:147
u16 m_NumShape
Definition g3d_ModelObj.h:212
void * m_pUserPtr
Definition g3d_ModelObj.h:220
const ShapeObj * GetShape(int shapeIndex) const
Definition g3d_ModelObj.h:141
bool Init(const InitArg &arg, void *pBuffer, size_t bufferSize)
Definition g3d_ModelObj.cpp:94
int GetShapeCount() const
Definition g3d_ModelObj.h:133
void CalcWorld(const Mtx34 &baseMtx)
Definition g3d_ModelObj.cpp:296
const bit32 * GetBoneVisArray() const
Definition g3d_ModelObj.h:107
ModelObj()
Definition g3d_ModelObj.h:26
void UpdateViewDependency()
MaterialObj * GetMaterial(int matIndex)
Definition g3d_ModelObj.h:165
const SkeletonObj * GetSkeleton() const
Definition g3d_ModelObj.h:131
Sphere * m_pBounding
Definition g3d_ModelObj.h:218
u8 m_ViewDependent
Definition g3d_ModelObj.h:208
Alignment
Definition g3d_ModelObj.h:20
@ BLOCK_BUFFER_ALIGNMENT
Definition g3d_ModelObj.h:23
@ BUFFER_ALIGNMENT
Definition g3d_ModelObj.h:21
bool IsMatVisible(int matIndex) const
Definition g3d_ModelObj.h:111
const char * GetMaterialName(int matIndex) const
Definition g3d_ModelObj.h:189
bool IsViewDependent() const
Definition g3d_ModelObj.h:66
void * m_pBlockBuffer
Definition g3d_ModelObj.h:222
bool SetupBlockBuffer(void *pBuffer, size_t bufferSize)
Definition g3d_ModelObj.cpp:241
void SetBoneVisibility(int boneIndex, bool visible)
Definition g3d_ModelObj.h:99
void DisableBlockSwapAll()
bit32 * GetMatVisArray()
Definition g3d_ModelObj.h:123
ResModel * m_pRes
Definition g3d_ModelObj.h:203
T * GetUserPtr()
Definition g3d_ModelObj.h:81
const ShapeObj * GetShape(const char *name) const
Definition g3d_ModelObj.h:153
void SetMatVisibility(int matIndex, bool visible)
Definition g3d_ModelObj.h:117
void ClearMatVisibility()
Definition g3d_ModelObj.cpp:413
Flag
Definition g3d_ModelObj.h:197
@ BLOCK_BUFFER_VALID
Definition g3d_ModelObj.h:198
void CalcBounding()
Definition g3d_ModelObj.cpp:301
void SetUserPtr(void *pUserPtr)
Definition g3d_ModelObj.h:74
int GetMaterialIndex(const char *name) const
Definition g3d_ModelObj.h:191
bit32 * m_pMatVisArray
Definition g3d_ModelObj.h:206
int GetViewCount() const
Definition g3d_ModelObj.h:64
static size_t CalcBufferSize(const InitArg &arg)
Definition g3d_ModelObj.cpp:87
ShapeObj * m_pShapeArray
Definition g3d_ModelObj.h:216
u16 m_NumMaterial
Definition g3d_ModelObj.h:213
size_t CalcBlockBufferSize()
Definition g3d_ModelObj.cpp:211
const MaterialObj * GetMaterial(int matIndex) const
Definition g3d_ModelObj.h:171
bool IsBoneVisible(int boneIndex) const
Definition g3d_ModelObj.h:93
void * GetUserPtr()
Definition g3d_ModelObj.h:76
const MaterialObj * GetMaterial(const char *name) const
Definition g3d_ModelObj.h:183
const bit32 * GetMatVisArray() const
Definition g3d_ModelObj.h:125
Definition g3d_ShapeObj.h:95
int GetMaterialIndex() const
Definition g3d_ShapeObj.h:134
int GetBoneIndex() const
Definition g3d_ShapeObj.h:136
Definition g3d_Sizer.h:10
Sizer()
Definition g3d_Sizer.h:18
Definition g3d_SkeletonObj.h:102
@ BUFFER_ALIGNMENT
Definition g3d_SkeletonObj.h:132
Definition g3d_GfxObject.h:48
Definition g3d_Matrix34.h:34
Definition g3d_ResModel.h:38
#define NW_G3D_ASSERT_NOT_NULL(exp)
Definition g3d_assert.h:20
#define NW_G3D_ASSERT_INDEX_BOUNDS(index, size)
Definition g3d_assert.h:23
#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_Sizer.h:13
Definition g3d_ShapeObj.h:29