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