1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_ResSkeleton.h
4 
5   Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Revision: 14993 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NW_GFX_RESSKELETON_H_
17 #define NW_GFX_RESSKELETON_H_
18 
19 #include <nw/ut/ut_ResUtil.h>
20 #include <nw/ut/ut_ResDictionary.h>
21 #include <nw/math/math_ResTypes.h>
22 #include <nw/gfx/res/gfx_ResSceneObject.h>
23 #include <nw/gfx/res/gfx_ResTypeInfo.h>
24 
25 namespace nw {
26 namespace gfx {
27 namespace res {
28 
29 //! @details :private
30 struct ResBoneData
31 {
32     enum Flag
33     {
34         FLAG_IS_IDENTITY                       = 0x1 << 0,
35         FLAG_IS_TRANSLATE_ZERO                 = 0x1 << 1,
36         FLAG_IS_ROTATE_ZERO                    = 0x1 << 2,
37         FLAG_IS_SCALE_ONE                      = 0x1 << 3,
38         FLAG_IS_UNIFORM_SCALE                  = 0x1 << 4,
39         FLAG_IS_SEGMENTSCALE_COMPENSATE     = 0x1 << 5,
40         FLAG_IS_NEED_RENDERING              = 0x1 << 6,
41         FLAG_IS_LOCAL_MATRIX_CALCULATE      = 0x1 << 7,
42         FLAG_IS_WORLD_MATRIX_CALCULATE      = 0x1 << 8,
43         FLAG_HAS_SKINNING_MATRIX            = 0x1 << 9
44     };
45 
46     nw::ut::BinString toName;
47     nw::ut::ResU32 m_Flags;
48     nw::ut::ResS32 m_Index;
49     nw::ut::ResS32 m_ParentBoneIndex;
50     nw::ut::Offset toParentBone;
51     nw::ut::Offset toChildBone;
52     nw::ut::Offset toPrevSibling;
53     nw::ut::Offset toNextSibling;
54     nw::ut::ResTransform3 m_Transform;
55     nw::ut::ResMtx34 m_LocalMatrix;
56     nw::ut::ResMtx34 m_WorldMatrix;  // 行列計算用のバッファへ正式対応後、削除予定。
57     nw::ut::ResMtx34 m_InverseBaseMatrix;
58     nw::ut::ResS32 m_BillboardMode;
59     nw::ut::ResS32 m_UserDataDicCount;
60     nw::ut::Offset toUserDataDic;
61 };
62 
63 //! @details :private
64 struct ResSkeletonData : public ResSceneObjectData
65 {
66     enum Flag
67     {
68         FLAG_MODEL_COORDINATE                       = 0x1 << 0,
69         FLAG_TRANSLATE_ANIMATION_ENABLED            = 0x1 << 1
70     };
71 
72     nw::ut::ResS32 m_BonesDicCount;
73     nw::ut::Offset toBonesDic;
74     nw::ut::Offset toRootBone;
75     nw::ut::ResS32 m_ScalingRule;
76     nw::ut::ResU32 m_Flags;
77 };
78 
79 //--------------------------------------------------------------------------
80 //! @brief スケルタルモデルのボーンを表すバイナリリソースクラスです。
81 //---------------------------------------------------------------------------
82 class ResBone : public nw::ut::ResCommon< ResBoneData >
83 {
84 public:
85 
86     //! ビルボードの種類の定義です。
87     enum BillboardMode
88     {
89         BILLBOARD_MODE_OFF,                 //!< ビルボード処理を行いません。
90         BILLBOARD_MODE_WORLD,               //!< Z 軸が視点軸と平行となるように回転させます。
91         BILLBOARD_MODE_WORLD_VIEWPOINT,     //!< Z 軸が視点方向に向くように回転させます。
92         BILLBOARD_MODE_SCREEN,              //!< Z 軸が視点軸と平行で、Y 軸が画面上方向になるように回転させます。
93         BILLBOARD_MODE_SCREEN_VIEWPOINT,    //!< Z 軸が視点方向に向くき、Y 軸が画面上方向になるように回転させます。
94         BILLBOARD_MODE_Y_AXIAL,             //!< Z 軸が視点軸と平行となるように Y 軸だけ 回転させます。
95         BILLBOARD_MODE_Y_AXIAL_VIEWPOINT   //!< Z 軸が視点方向に向くように Y 軸だけ 回転させます。
96     };
97 
98     NW_RES_CTOR( ResBone )
99 
100     //---------------------------------------------------------------------------
101     //! @fn           void SetWorldMatrix(const nw::math::MTX34 & value)
102     //! @brief        ワールドマトリクスを設定します。
103     //---------------------------------------------------------------------------
104     //---------------------------------------------------------------------------
105     //! @fn           void SetTransform(const nw::math::Transform3 & value)
106     //! @brief        トランスフォーム情報を設定します。
107     //---------------------------------------------------------------------------
108     //---------------------------------------------------------------------------
109     //! @fn           void SetParentBoneIndex(s32 value)
110     //! @brief        親ボーンのインデックス番号を設定します。
111     //---------------------------------------------------------------------------
112     //---------------------------------------------------------------------------
113     //! @fn           void SetLocalMatrix(const nw::math::MTX34 & value)
114     //! @brief        ローカルマトリクスを設定します。
115     //---------------------------------------------------------------------------
116     //---------------------------------------------------------------------------
117     //! @fn           void SetInverseBaseMatrix(const nw::math::MTX34 & value)
118     //! @brief        ベースマトリクスの逆行列を設定します。
119     //---------------------------------------------------------------------------
120     //---------------------------------------------------------------------------
121     //! @fn           void SetIndex(s32 value)
122     //! @brief        インデックス番号を設定します。
123     //---------------------------------------------------------------------------
124     //---------------------------------------------------------------------------
125     //! @fn           void SetFlags(u32 value)
126     //! @brief        フラグの値を設定します。
127     //!               設定されなかったフラグは無効になります。
128     //---------------------------------------------------------------------------
129     //---------------------------------------------------------------------------
130     //! @fn           void EnaleFlags(u32 value)
131     //! @brief        指定された Flag の値を有効にします。
132     //!               設定されなかったフラグは変更されません。
133     //---------------------------------------------------------------------------
134     //---------------------------------------------------------------------------
135     //! @fn           void DisableFlags(u32 value)
136     //! @brief        指定された Flag の値を無効にします。
137     //!               設定されなかったフラグは変更されません。
138     //---------------------------------------------------------------------------
139     //---------------------------------------------------------------------------
140     //! @fn           void SetBillboardMode(BillboardMode value)
141     //! @brief        ビルボード表示のモードを設定します。
142     //---------------------------------------------------------------------------
143     //---------------------------------------------------------------------------
144     //! @fn           nw::math::MTX34 & GetWorldMatrix()
145     //! @brief        ワールドマトリクスを取得します。
146     //---------------------------------------------------------------------------
147     //---------------------------------------------------------------------------
148     //! @fn           nw::math::Transform3 & GetTransform()
149     //! @brief        トランスフォーム情報を取得します。
150     //---------------------------------------------------------------------------
151     //---------------------------------------------------------------------------
152     //! @fn           ResBone GetPrevSibling()
153     //! @brief        前の兄弟ボーンを取得します。
154     //---------------------------------------------------------------------------
155     //---------------------------------------------------------------------------
156     //! @fn           s32 GetParentBoneIndex() const
157     //! @brief        親ボーンのインデックス番号を取得します。
158     //---------------------------------------------------------------------------
159     //---------------------------------------------------------------------------
160     //! @fn           ResBone GetParentBone()
161     //! @brief        親ボーンを取得します。
162     //---------------------------------------------------------------------------
163     //---------------------------------------------------------------------------
164     //! @fn           ResBone GetNextSibling()
165     //! @brief        次の兄弟ボーンを取得します。
166     //---------------------------------------------------------------------------
167     //---------------------------------------------------------------------------
168     //! @fn           const char * GetName() const
169     //! @brief        名前を取得します。
170     //---------------------------------------------------------------------------
171     //---------------------------------------------------------------------------
172     //! @fn           nw::math::MTX34 & GetLocalMatrix()
173     //! @brief        ローカルマトリクスを取得します。
174     //---------------------------------------------------------------------------
175     //---------------------------------------------------------------------------
176     //! @fn           nw::math::MTX34 & GetInverseBaseMatrix()
177     //! @brief        ベースマトリクスの逆行列を取得します。
178     //---------------------------------------------------------------------------
179     //---------------------------------------------------------------------------
180     //! @fn           s32 GetIndex() const
181     //! @brief        インデックス番号を取得します。
182     //---------------------------------------------------------------------------
183     //---------------------------------------------------------------------------
184     //! @fn           u32 GetFlags() const
185     //! @brief        フラグの値を取得します。
186     //---------------------------------------------------------------------------
187     //---------------------------------------------------------------------------
188     //! @fn           ResBone GetChildBone()
189     //! @brief        子ボーンを取得します。
190     //---------------------------------------------------------------------------
191     //---------------------------------------------------------------------------
192     //! @fn           BillboardMode GetBillboardMode() const
193     //! @brief        ビルボード表示のモードを取得します。
194     //---------------------------------------------------------------------------
195     NW_RES_FIELD_STRING_DECL( Name )                    // GetName()
196     NW_RES_FIELD_FLAGS_DECL( u32, Flags )               // GetFlags(), SetFlags(), EnableFlags(), DisableFlags()
197     NW_RES_FIELD_PRIMITIVE_DECL( s32, Index )           // GetIndex(), SetIndex()
198     NW_RES_FIELD_PRIMITIVE_DECL( s32, ParentBoneIndex ) // GetParentBoneIndex(), SetParentBoneIndex()
199     NW_RES_FIELD_CLASS_DECL( ResBone, ParentBone )      // GetParentBone()
200     NW_RES_FIELD_CLASS_DECL( ResBone, ChildBone )       // GetChildBone()
201     NW_RES_FIELD_CLASS_DECL( ResBone, PrevSibling )     // GetPrevSibling()
202     NW_RES_FIELD_CLASS_DECL( ResBone, NextSibling )     // GetNextSibling()
203     NW_RES_FIELD_STRUCT_DECL( nw::math::Transform3, Transform )    // GetTransform()
204     NW_RES_FIELD_STRUCT_DECL( nw::math::MTX34, LocalMatrix )       // GetLocalMatrix()
205     NW_RES_FIELD_STRUCT_DECL( nw::math::MTX34, WorldMatrix )       // 行列計算用のバッファへ正式対応後、削除予定。
206     NW_RES_FIELD_STRUCT_DECL( nw::math::MTX34, InverseBaseMatrix ) // GetInverseBaseMatrix()
207     NW_RES_FIELD_PRIMITIVE_DECL( BillboardMode, BillboardMode )   // GetBillboardMode(), SetBillboardMode()
208 
209     //---------------------------------------------------------------------------
210     //! @fn           s32 GetUserDataIndex(const char * key) const
211     //! @brief        ユーザデータの辞書データ中でのインデックス番号を取得します。
212     //---------------------------------------------------------------------------
213     //---------------------------------------------------------------------------
214     //! @fn           s32 GetUserDataCount() const
215     //! @brief        ユーザデータの要素数を取得します。
216     //---------------------------------------------------------------------------
217     //---------------------------------------------------------------------------
218     //! @fn           nw::ut::ResMetaData GetUserData(int idx)
219     //! @brief        ユーザデータを取得します。
220     //---------------------------------------------------------------------------
221     NW_RES_FIELD_CLASS_DIC_DECL( nw::ut::ResMetaData, UserData, nw::ut::ResDicPatricia ) // GetMetaData(int idx), GetMetaData(const char*), GetMetaDataIndex(const char*), GetMetaDataCount()
222 };
223 typedef nw::ut::ResArrayPatricia<ResBone>::type  ResBoneArray;
224 
225 
226 //--------------------------------------------------------------------------
227 //! @brief ボーンを束ねるスケルトンを表すバイナリリソースクラスです。
228 //---------------------------------------------------------------------------
229 class ResSkeleton : public ResSceneObject
230 {
231 public:
232     enum Flag
233     {
234         FLAG_MODEL_COORDINATE                       = 0x1 << 0,
235         FLAG_TRANSLATE_ANIMATION_ENABLED            = 0x1 << 1
236     };
237 
238     enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResSkeleton) };
239     enum { SIGNATURE = NW_RES_SIGNATURE32('CSKL') };
240 
241     NW_RES_CTOR_INHERIT( ResSkeleton, ResSceneObject )
242 
243     //---------------------------------------------------------------------------
244     //! @fn           void SetScalingRule(s32 value)
245     //! @brief        スケールの方式を設定します。
246     //---------------------------------------------------------------------------
247     //---------------------------------------------------------------------------
248     //! @fn           void SetFlags(u32 value)
249     //! @brief        Flag の値を設定します。
250     //!               ワールド座標、モデル座標などを設定できます。
251     //!               設定されなかったフラグは無効になります。
252     //---------------------------------------------------------------------------
253     //---------------------------------------------------------------------------
254     //! @fn           void EnaleFlags(u32 value)
255     //! @brief        指定された Flag の値を有効にします。
256     //!               設定されなかったフラグは変更されません。
257     //---------------------------------------------------------------------------
258     //---------------------------------------------------------------------------
259     //! @fn           void DisableFlags(u32 value)
260     //! @brief        指定された Flag の値を無効にします。
261     //!               設定されなかったフラグは変更されません。
262     //---------------------------------------------------------------------------
263     //---------------------------------------------------------------------------
264     //! @fn           s32 GetScalingRule() const
265     //! @brief        スケールの方式を取得します。
266     //---------------------------------------------------------------------------
267     //---------------------------------------------------------------------------
268     //! @fn           ResBone GetRootBone()
269     //! @brief        ルートのボーンを取得します。
270     //---------------------------------------------------------------------------
271     //---------------------------------------------------------------------------
272     //! @fn           u32 GetFlags() const
273     //! @brief        フラグの値を取得します。
274     //---------------------------------------------------------------------------
275     //---------------------------------------------------------------------------
276     //! @fn           s32 GetBonesIndex(const char * key) const
277     //! @brief        ボーンの辞書データ中でのインデックス番号を取得します。
278     //---------------------------------------------------------------------------
279     //---------------------------------------------------------------------------
280     //! @fn           s32 GetBonesCount() const
281     //! @brief        ボーンの要素数を取得します。
282     //---------------------------------------------------------------------------
283     //---------------------------------------------------------------------------
284     //! @fn           ResBone GetBones(int idx)
285     //! @brief        ボーンを取得します。
286     //---------------------------------------------------------------------------
287     NW_RES_FIELD_CLASS_DIC_DECL( ResBone, Bones, nw::ut::ResDicPatricia ) // GetBones(int idx), GetBones(const char*), GetBonesIndex(const char*), GetBonesCount()
288     NW_RES_FIELD_CLASS_DECL( ResBone, RootBone )    // GetRootBone()
289     NW_RES_FIELD_PRIMITIVE_DECL( s32, ScalingRule ) // GetScalingRule(), SetScalingRule()
290     NW_RES_FIELD_FLAGS_DECL( u32, Flags )           // GetFlags(), SetFlags(), EnableFlags(), DisableFlags()
291 };
292 
293 } // namespace res
294 } // namespace gfx
295 } // namespace nw
296 
297 #endif // NW_GFX_RESSKELETON_H_
298