1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_ResModel.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: 19143 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NW_GFX_RESMODEL_H_
17 #define NW_GFX_RESMODEL_H_
18 
19 #include <nw/ut/ut_ResUtil.h>
20 #include <nw/ut/ut_ResDictionary.h>
21 #include <nw/gfx/res/gfx_ResSceneObject.h>
22 #include <nw/gfx/res/gfx_ResShape.h>
23 #include <nw/gfx/res/gfx_ResMaterial.h>
24 #include <nw/gfx/res/gfx_ResSkeleton.h>
25 #include <nw/gfx/res/gfx_ResMesh.h>
26 #include <nw/gfx/res/gfx_ResRevision.h>
27 #include <nw/gfx/res/gfx_ResTypeInfo.h>
28 
29 namespace nw {
30 namespace gfx {
31 namespace res {
32 
33 class ResGraphicsFile;
34 
35 //! @details :private
36 struct ResMeshNodeVisibilityData
37 {
38     nw::ut::BinString toName;
39     nw::ut::ResBool m_IsVisible;
40 };
41 
42 //! @details :private
43 struct ResModelData : public ResTransformNodeData
44 {
45     nw::ut::ResS32 m_MeshesTableCount;
46     nw::ut::Offset toMeshesTable;
47     nw::ut::ResS32 m_MaterialsDicCount;
48     nw::ut::Offset toMaterialsDic;
49     nw::ut::ResS32 m_ShapesTableCount;
50     nw::ut::Offset toShapesTable;
51     nw::ut::ResS32 m_MeshNodeVisibilitiesDicCount;
52     nw::ut::Offset toMeshNodeVisibilitiesDic;
53     nw::ut::ResBool m_IsVisible;
54     nw::ut::ResBool m_IsNonuniformScalable;
55     u8 _padding_0[6];
56     nw::ut::ResU32 m_LayerId;
57 };
58 
59 //! @details :private
60 struct ResSkeletalModelData : public ResModelData
61 {
62     nw::ut::Offset toSkeleton;
63 };
64 
65 //--------------------------------------------------------------------------
66 //! @brief  DCC 上でのノードのビジビリティを表すバイナリリソースクラスです。
67 //---------------------------------------------------------------------------
68 class ResMeshNodeVisibility : public nw::ut::ResCommon< ResMeshNodeVisibilityData >
69 {
70 public:
71     NW_RES_CTOR( ResMeshNodeVisibility )
72 
73     //---------------------------------------------------------------------------
74     //! @fn           const char * GetName() const
75     //! @brief        ノード名を取得します。
76     //---------------------------------------------------------------------------
77     //---------------------------------------------------------------------------
78     //! @fn           bool IsVisible() const
79     //! @brief        表示されるかどうかのフラグを取得します。
80     //---------------------------------------------------------------------------
81     NW_RES_FIELD_STRING_DECL( Name )            // GetName()
82     NW_RES_FIELD_BOOL_PRIMITIVE_DECL( Visible ) // IsVisible(), SetVisible()
83 };
84 
85 //--------------------------------------------------------------------------
86 //! @brief  モデルを表すバイナリリソースクラスです。
87 //---------------------------------------------------------------------------
88 class ResModel : public ResTransformNode
89 {
90 public:
91     enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResModel) };
92     enum { SIGNATURE = NW_RES_SIGNATURE32('CMDL') };
93     enum { BINARY_REVISION = REVISION_RES_MODEL };
94 
NW_RES_CTOR_INHERIT(ResModel,ResTransformNode)95     NW_RES_CTOR_INHERIT( ResModel, ResTransformNode )
96 
97     //---------------------------------------------------------------------------
98     //! @fn           void SetVisible(bool value)
99     //! @brief        表示するかどうかのフラグを設定します。
100     //---------------------------------------------------------------------------
101     //---------------------------------------------------------------------------
102     //! @fn           void SetNonuniformScalable(bool value)
103     //! @brief        不均一なスケールをかけることができるかのフラグを設定します。
104     //---------------------------------------------------------------------------
105     //---------------------------------------------------------------------------
106     //! @fn           void SetLayerId(u32 value)
107     //! @brief        描画順を制御するためのIDを設定します。
108     //---------------------------------------------------------------------------
109     //---------------------------------------------------------------------------
110     //! @fn           bool IsVisible() const
111     //! @brief        表示するかどうかのフラグを取得します。
112     //---------------------------------------------------------------------------
113     //---------------------------------------------------------------------------
114     //! @fn           bool IsNonuniformScalable() const
115     //! @brief        不均一なスケールをかけることができるかのフラグを取得します。
116     //---------------------------------------------------------------------------
117     //---------------------------------------------------------------------------
118     //! @fn           s32 GetShapesCount() const
119     //! @brief        シェイプの要素数を取得します。
120     //---------------------------------------------------------------------------
121     //---------------------------------------------------------------------------
122     //! @fn           ResShape GetShapes(int idx)
123     //! @brief        シェイプを取得します。
124     //---------------------------------------------------------------------------
125     //---------------------------------------------------------------------------
126     //! @fn           s32 GetMeshesCount() const
127     //! @brief        メッシュの要素数を取得します。
128     //---------------------------------------------------------------------------
129     //---------------------------------------------------------------------------
130     //! @fn           ResMesh GetMeshes(int idx)
131     //! @brief        メッシュを取得します。
132     //---------------------------------------------------------------------------
133     //---------------------------------------------------------------------------
134     //! @fn           s32 GetMaterialsIndex(const char * key) const
135     //! @brief        マテリアルの辞書データ中でのインデックス番号を取得します。
136     //---------------------------------------------------------------------------
137     //---------------------------------------------------------------------------
138     //! @fn           s32 GetMaterialsCount() const
139     //! @brief        マテリアルの要素数を取得します。
140     //---------------------------------------------------------------------------
141     //---------------------------------------------------------------------------
142     //! @fn           ResMaterial GetMaterials(int idx)
143     //! @brief        マテリアルを取得します。
144     //---------------------------------------------------------------------------
145     //---------------------------------------------------------------------------
146     //! @fn           u32 GetLayerId() const
147     //! @brief        描画順を制御するためのIDを取得します。
148     //---------------------------------------------------------------------------
149     //---------------------------------------------------------------------------
150     //! @fn           s32 GetMeshNodeVisibilitiesCount() const
151     //! @brief        ビジビリティを持つ DCC 上でのノードの数を取得します。
152     //---------------------------------------------------------------------------
153     //---------------------------------------------------------------------------
154     //! @fn           ResMeshNodeVisibility GetMeshNodeVisibilities(int idx)
155     //! @brief        DCC 上でのノードのビジビリティを取得します。
156     //---------------------------------------------------------------------------
157     NW_RES_FIELD_CLASS_LIST_DECL( ResMesh, Meshes )  // GetMeshes(int idx), GetMeshesCount()
158     NW_RES_FIELD_CLASS_DIC_DECL( ResMaterial, Materials, nw::ut::ResDicPatricia ) // GetMaterials(int idx), GetMaterials(const char*), GetMaterialsIndex(const char*), GetMaterialsCount()
159     NW_RES_FIELD_CLASS_LIST_DECL( ResShape, Shapes ) // GetShapes(int idx), GetShapesCount()
160     NW_RES_FIELD_CLASS_DIC_DECL( ResMeshNodeVisibility, MeshNodeVisibilities, nw::ut::ResDicPatricia ) // GetMeshNodeVisibilities(int idx), GetMeshNodeVisibilities(const char*), GetMeshNodeVisibilitiesIndex(const char*), GetMeshNodeVisibilitiesCount()
161     NW_RES_FIELD_BOOL_PRIMITIVE_DECL( Visible )      // IsVisible(), SetVisible()
162     NW_RES_FIELD_BOOL_PRIMITIVE_DECL( NonuniformScalable ) // IsNonuniformScalable(), SetNonuniformScalable()
163     NW_RES_FIELD_PRIMITIVE_DECL( u32, LayerId )      // GetLayerId(), SetLayerId()
164 
165     //---------------------------------------------------------------------------
166     //! @brief        リビジョンを取得します。
167     //!
168     //! @return       リソースのリビジョン情報です。
169     //---------------------------------------------------------------------------
170     u32 GetRevision() const { return this->GetHeader().revision; }
171 
172     //---------------------------------------------------------------------------
173     //! @brief        リソースの初期化処理をおこないます。
174     //!
175     //! @param[in]    allocator アロケータです。
176     //! @param[in]    graphicsFile グラフィックスリソースです。
177     //---------------------------------------------------------------------------
178      Result Setup(os::IAllocator* allocator, ResGraphicsFile graphicsFile);
179 
180     //---------------------------------------------------------------------------
181     //! @brief        リソースの解放処理をおこないます。
182     //---------------------------------------------------------------------------
183     void Cleanup();
184 };
185 typedef nw::ut::ResArrayPatricia<ResModel>::type  ResModelArray;
186 
187 //--------------------------------------------------------------------------
188 //! @brief  スケルタルモデルを表すバイナリリソースクラスです。
189 //---------------------------------------------------------------------------
190 class ResSkeletalModel : public ResModel
191 {
192 public:
193     enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResSkeletalModel) };
194     enum { SIGNATURE = NW_RES_SIGNATURE32('CSMD') };
195 
196     NW_RES_CTOR_INHERIT( ResSkeletalModel, ResModel )
197 
198     //---------------------------------------------------------------------------
199     //! @fn           ResSkeleton GetSkeleton()
200     //! @brief        スケルトンを取得します。
201     //---------------------------------------------------------------------------
202     NW_RES_FIELD_CLASS_DECL( ResSkeleton, Skeleton )             // GetSkeleton()
203 };
204 
205 } // namespace res
206 } // namespace gfx
207 } // namespace nw
208 
209 #endif // NW_GFX_RESMODEL_H_
210