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