1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_ResSceneObject.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: 17337 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NW_GFX_RESSCENEOBJECT_H_
17 #define NW_GFX_RESSCENEOBJECT_H_
18 
19 #include <nw/ut/ut_BinaryFileFormat.h>
20 #include <nw/ut/ut_ResUtil.h>
21 #include <nw/ut/ut_ResDictionary.h>
22 #include <nw/math/math_ResTypes.h>
23 #include <nw/gfx/gfx_Common.h>
24 #include <nw/anim/res/anim_ResAnimGroup.h>
25 #include <nw/gfx/res/gfx_ResTypeInfo.h>
26 #include <nw/ut/ut_ResMetaData.h>
27 
28 namespace nw {
29 namespace gfx {
30 namespace res {
31 
32 //! @details :private
33 struct ResSceneObjectData
34 {
35     nw::ut::ResTypeInfo typeInfo;
36     nw::ut::BinaryRevisionHeader m_Header;
37     nw::ut::BinString toName;
38     nw::ut::ResS32 m_UserDataDicCount;
39     nw::ut::Offset toUserDataDic;
40 };
41 
42 
43 //! @details :private
44 struct ResSceneNodeData : public ResSceneObjectData
45 {
46     enum Flag
47     {
48         FLAG_IS_BRANCH_VISIBLE_SHIFT = 0,
49         FLAG_SHIFT_MAX,
50 
51         FLAG_IS_BRANCH_VISIBLE = 0x1 << FLAG_IS_BRANCH_VISIBLE_SHIFT
52     };
53 
54     nw::ut::ResU32 m_Flags;
55     nw::ut::ResBool m_IsBranchVisible;
56     u8             padding_0[3];
57     nw::ut::ResS32 m_ChildrenTableCount;
58     nw::ut::Offset toChildrenTable;
59     nw::ut::ResS32 m_AnimGroupsDicCount;
60     nw::ut::Offset toAnimGroupsDic;
61 };
62 
63 //! @details :private
64 struct ResTransformNodeData : public ResSceneNodeData
65 {
66     nw::ut::ResTransform3 m_Transform;
67     nw::ut::ResMtx34 m_LocalMatrix;
68     nw::ut::ResMtx34 m_WorldMatrix;
69 };
70 
71 //--------------------------------------------------------------------------
72 //! @brief シーンオブジェクトを表すバイナリリソースクラスです。
73 //---------------------------------------------------------------------------
74 class ResSceneObject : public nw::ut::ResCommon< ResSceneObjectData >
75 {
76 public:
77     enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResSceneObject) };
78     enum { SIGNATURE = NW_RES_SIGNATURE32('SOBJ') };
79 
80     NW_RES_CTOR( ResSceneObject )
81 
82     //---------------------------------------------------------------------------
83     //! @fn           void SetHeader(const nw::ut::BinaryRevisionHeader & value)
84     //! @brief        ヘッダ情報を設定します。
85     //---------------------------------------------------------------------------
86     //---------------------------------------------------------------------------
87     //! @fn           nw::ut::BinaryRevisionHeader & GetHeader()
88     //! @brief        ヘッダ情報を取得します。
89     //---------------------------------------------------------------------------
NW_RES_FIELD_STRUCT_DECL(nw::ut::BinaryRevisionHeader,Header)90     NW_RES_FIELD_STRUCT_DECL( nw::ut::BinaryRevisionHeader, Header ) // GetHeader()
91 
92     //---------------------------------------------------------------------------
93     //! @fn           const char * GetName() const
94     //! @brief        リソースの名前を取得します。
95     //---------------------------------------------------------------------------
96     NW_RES_FIELD_STRING_DECL( Name ) // GetName()
97 
98     //---------------------------------------------------------------------------
99     //! @fn           s32 GetUserDataIndex(const char * key) const
100     //! @brief        ユーザデータの辞書データ中でのインデックス番号を取得します。
101     //---------------------------------------------------------------------------
102     //---------------------------------------------------------------------------
103     //! @fn           s32 GetUserDataCount() const
104     //! @brief        ユーザデータの要素数を取得します。
105     //---------------------------------------------------------------------------
106     //---------------------------------------------------------------------------
107     //! @fn           nw::ut::ResMetaData GetUserData(int idx)
108     //! @brief        ユーザデータを取得します。
109     //---------------------------------------------------------------------------
110     NW_RES_FIELD_CLASS_DIC_DECL( nw::ut::ResMetaData, UserData, nw::ut::ResDicPatricia ) // GetMetaData(int idx), GetMetaData(const char*), GetMetaDataIndex(const char*), GetMetaDataCount()
111 
112     //---------------------------------------------------------------------------
113     //! @brief        インスタンスの型情報を取得します。
114     //!
115     //! @return       型情報です。
116     //---------------------------------------------------------------------------
117     nw::ut::ResTypeInfo     GetTypeInfo() const { return ref().typeInfo; }
118 };
119 
120 //--------------------------------------------------------------------------
121 //! @brief  シーンノードを表すバイナリリソースクラスです。
122 //---------------------------------------------------------------------------
123 class ResSceneNode : public ResSceneObject
124 {
125 public:
126     enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResSceneNode) };
127     enum { SIGNATURE = NW_RES_SIGNATURE32('CNOD') };
128 
NW_RES_CTOR_INHERIT(ResSceneNode,ResSceneObject)129     NW_RES_CTOR_INHERIT( ResSceneNode, ResSceneObject )
130 
131     //---------------------------------------------------------------------------
132     //! @fn           void SetFlags(u32 value)
133     //! @brief        フラグの値を設定します。
134     //!               設定されなかったフラグは無効になります。
135     //---------------------------------------------------------------------------
136     //---------------------------------------------------------------------------
137     //! @fn           void EnaleFlags(u32 value)
138     //! @brief        指定された Flag の値を有効にします。
139     //!               設定されなかったフラグは変更されません。
140     //---------------------------------------------------------------------------
141     //---------------------------------------------------------------------------
142     //! @fn           void DisableFlags(u32 value)
143     //! @brief        指定された Flag の値を無効にします。
144     //!               設定されなかったフラグは変更されません。
145     //---------------------------------------------------------------------------
146     //---------------------------------------------------------------------------
147     //! @fn           u32 GetFlags() const
148     //! @brief        フラグの設定を取得します。
149     //---------------------------------------------------------------------------
150     //---------------------------------------------------------------------------
151     //! @fn           s32 GetChildrenCount() const
152     //! @brief        子のシーンオブジェクトの要素数を取得します。
153     //---------------------------------------------------------------------------
154     //---------------------------------------------------------------------------
155     //! @fn           ResSceneObject GetChildren(int idx)
156     //! @brief        子のシーンオブジェクトを取得します。
157     //---------------------------------------------------------------------------
158     //---------------------------------------------------------------------------
159     //! @fn           s32 GetAnimGroupsIndex(const char * key) const
160     //! @brief        アニメーション対象のグループ情報の辞書データ中でのインデックス番号を取得します。
161     //---------------------------------------------------------------------------
162     //---------------------------------------------------------------------------
163     //! @fn           s32 GetAnimGroupsCount() const
164     //! @brief        アニメーション対象のグループ情報の要素数を取得します。
165     //---------------------------------------------------------------------------
166     //---------------------------------------------------------------------------
167     //! @fn           nw::anim::ResAnimGroup GetAnimGroups(int idx)
168     //! @brief        アニメーション対象のグループ情報を取得します。
169     //---------------------------------------------------------------------------
170     NW_RES_FIELD_FLAGS_DECL( u32, Flags )               // GetFlags(), SetFlags(), EnableFlags(), DisableFlags()
171     NW_RES_FIELD_CLASS_LIST_DECL( ResSceneObject, Children ) // GetChildren(int idx), GetChildrenCount()
172     NW_RES_FIELD_CLASS_DIC_DECL( nw::anim::ResAnimGroup, AnimGroups, nw::ut::ResDicPatricia ) // GetAnimGroups(int idx), GetAnimGroups(const char*), GetAnimGropuIndex(const char*), GetAnimGroupsCount()
173 
174     //---------------------------------------------------------------------------
175     //! @brief ノードのブランチを表示するかどうかのフラグを取得します。
176     //!
177     //! @return フラグの値を返します。
178     //---------------------------------------------------------------------------
179     bool IsBranchVisible() const { return ref().m_Flags & ResSceneNodeData::FLAG_IS_BRANCH_VISIBLE; }
180 
181     //---------------------------------------------------------------------------
182     //! @brief ノードのブランチを表示するかどうかのフラグを設定します。
183     //!
184     //! @param flag 設定するフラグ値です。
185     //---------------------------------------------------------------------------
SetBranchVisible(bool flag)186     void SetBranchVisible(bool flag)
187     {
188         if (flag)
189         {
190             ref().m_Flags |= ResSceneNodeData::FLAG_IS_BRANCH_VISIBLE;
191         }
192         else
193         {
194             ref().m_Flags &= ~ResSceneNodeData::FLAG_IS_BRANCH_VISIBLE;
195         }
196     }
197 };
198 
199 //--------------------------------------------------------------------------
200 //! @brief  トランスフォームノードを表すバイナリリソースクラスです。
201 //---------------------------------------------------------------------------
202 class ResTransformNode : public ResSceneNode
203 {
204 public:
205     enum Flag {
206         FLAG_SHIFT_MAX = ResSceneNodeData::FLAG_SHIFT_MAX
207     };
208 
209     enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResTransformNode) };
210     enum { SIGNATURE = NW_RES_SIGNATURE32('CTFN') };
211 
212     NW_RES_CTOR_INHERIT( ResTransformNode, ResSceneNode )
213 
214     //---------------------------------------------------------------------------
215     //! @fn           void SetWorldMatrix(const nw::math::MTX34 & value)
216     //! @brief        ワールド行列を設定します。
217     //---------------------------------------------------------------------------
218     //---------------------------------------------------------------------------
219     //! @fn           void SetTransform(const nw::math::Transform3 & value)
220     //! @brief        トランスフォーム情報を設定します。
221     //---------------------------------------------------------------------------
222     //---------------------------------------------------------------------------
223     //! @fn           nw::math::MTX34 & GetWorldMatrix()
224     //! @brief        ワールド行列を取得します。
225     //---------------------------------------------------------------------------
226     //---------------------------------------------------------------------------
227     //! @fn           nw::math::Transform3 & GetTransform()
228     //! @brief        トランスフォーム情報を取得します。
229     //---------------------------------------------------------------------------
230     NW_RES_FIELD_STRUCT_DECL( nw::math::Transform3, Transform ) // GetTransform()
231     NW_RES_FIELD_STRUCT_DECL( nw::math::MTX34, WorldMatrix )    // GetWorldMatrix()
232 };
233 
234 } // namespace res
235 } // namespace gfx
236 } // namespace nw
237 
238 #endif // NW_GFX_RESSCENEOBJECT_H_
239