1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_ResMesh.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: 13145 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NW_GFX_RESMESH_H_
17 #define NW_GFX_RESMESH_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 
25 namespace nw {
26 namespace gfx {
27 namespace res {
28 
29 //! @details :private
30 struct ResMeshData : public ResSceneObjectData
31 {
32     enum { IR_SCALE_COMMAND_SIZE = 2 + 1 + 2 * 4 + 1 };
33 
34     nw::ut::ResS32 m_ShapeIndex;
35     nw::ut::ResS32 m_MaterialIndex;
36     nw::ut::Offset toOwnerModel;
37     nw::ut::ResBool m_IsVisible;
38     nw::ut::ResU8 m_RenderPriority;
39     nw::ut::ResS16 m_MeshNodeVisibilityIndex;
40     nw::ut::ResS32 m_CurrentPrimitiveIndex;
41     nw::ut::ResU32 m_Flags;
42     nw::ut::ResU32 m_IrScaleCommand[ IR_SCALE_COMMAND_SIZE ];
43     void*          m_ActivateCommandCache;
44     s32            m_ActivateCommandCacheSize;
45     void*          m_DeactivateCommandCache;
46     s32            m_DeactivateCommandCacheSize;
47     nw::ut::BinString toMeshNodeName;
48     u64            m_RenderKeyCache;
49 };
50 
51 //--------------------------------------------------------------------------
52 //! @brief  メッシュを表すバイナリリソースクラスです。
53 //---------------------------------------------------------------------------
54 class ResMesh : public ResSceneObject
55 {
56 public:
57     enum
58     {
59         FLAG_HAS_VERTEX_ALPHA  = 0x1,
60         FLAG_HAS_BONE_WEIGHT_W = 0x1 << 1,
61         FLAG_VALID_RENDER_KEY_CACHE = 0x1 << 2
62     };
63 
NW_RES_CTOR_INHERIT(ResMesh,ResSceneObject)64     NW_RES_CTOR_INHERIT( ResMesh, ResSceneObject )
65 
66     //---------------------------------------------------------------------------
67     //! @fn           void SetVisible(bool value)
68     //! @brief        表示されるかどうかのフラグを設定します。
69     //---------------------------------------------------------------------------
70     //---------------------------------------------------------------------------
71     //! @fn           void SetShapeIndex(s32 value)
72     //! @brief        使用するシェイプのインデックスを設定します。
73     //---------------------------------------------------------------------------
74     //---------------------------------------------------------------------------
75     //! @fn           void SetRenderPriority(u8 value)
76     //! @brief        描画優先度を設定します。
77     //---------------------------------------------------------------------------
78     //---------------------------------------------------------------------------
79     //! @fn           void SetMaterialIndex(s32 value)
80     //! @brief        使用するマテリアルのインデックスを設定します。
81     //---------------------------------------------------------------------------
82     //---------------------------------------------------------------------------
83     //! @fn           void SetFlags(u32 value)
84     //! @brief        フラグの値を設定します。
85     //---------------------------------------------------------------------------
86     //---------------------------------------------------------------------------
87     //! @fn           void SetCurrentPrimitiveIndex(s32 value)
88     //! @brief        現在有効なプリミティブのインデックス番号を設定します。
89     //---------------------------------------------------------------------------
90     //---------------------------------------------------------------------------
91     //! @fn           bool IsVisible() const
92     //! @brief        表示されるかどうかのフラグを取得します。
93     //---------------------------------------------------------------------------
94     //---------------------------------------------------------------------------
95     //! @fn           s32 GetShapeIndex() const
96     //! @brief        使用するシェイプのインデックスを取得します。
97     //---------------------------------------------------------------------------
98     //---------------------------------------------------------------------------
99     //! @fn           u8 GetRenderPriority() const
100     //! @brief        描画優先度を取得します。
101     //---------------------------------------------------------------------------
102     //---------------------------------------------------------------------------
103     //! @fn           ResTransformNode GetOwnerModel()
104     //! @brief        親モデルへを取得します。
105     //---------------------------------------------------------------------------
106     //---------------------------------------------------------------------------
107     //! @fn           s32 GetMaterialIndex() const
108     //! @brief        使用するマテリアルのインデックスを取得します。
109     //---------------------------------------------------------------------------
110     //---------------------------------------------------------------------------
111     //! @fn           u32 GetFlags() const
112     //! @brief        フラグの値を取得します。
113     //---------------------------------------------------------------------------
114     //---------------------------------------------------------------------------
115     //! @fn           s32 GetCurrentPrimitiveIndex() const
116     //! @brief        現在有効なプリミティブのインデックス番号を取得します。
117     //---------------------------------------------------------------------------
118     //---------------------------------------------------------------------------
119     //! @fn           const char * GetMeshNodeName() const
120     //! @brief        DCC 上でのノード名を取得します。
121     //---------------------------------------------------------------------------
122     //---------------------------------------------------------------------------
123     //! @fn           void GetMeshNodeVisibilityIndex(s32 value)
124     //! @brief        親モデルが持つビジビリティテーブルのインデックス番号を取得します。
125     //---------------------------------------------------------------------------
126     NW_RES_FIELD_PRIMITIVE_DECL( s32, ShapeIndex )            // GetShapeIndex(), SetShapeIndex()
127     NW_RES_FIELD_PRIMITIVE_DECL( s32, MaterialIndex )         // GetMaterialIndex(), SetMaterialIndex()
128     NW_RES_FIELD_CLASS_DECL( ResTransformNode, OwnerModel )   // GetOwnerModel()
129     NW_RES_FIELD_BOOL_PRIMITIVE_DECL( Visible )               // IsVisible(), SetVisible()
130     NW_RES_FIELD_PRIMITIVE_DECL( u8, RenderPriority )         // GetRenderPriority(), SetRenderPriority()
131     NW_RES_FIELD_PRIMITIVE_DECL( s32, CurrentPrimitiveIndex ) // GetCurrentPrimitiveIndex(), SetCurrentPrimitiveIndex()
132     NW_RES_FIELD_PRIMITIVE_DECL( u32, Flags )                 // GetFlags(), SetFlags()
133     // TODO: Name が取れないのを修正する。
134     // NW_RES_FIELD_STRING_DECL( MeshNodeName )              // GetMeshNodeName()
135     NW_RES_FIELD_PRIMITIVE_DECL( s32, MeshNodeVisibilityIndex )   // GetMeshNodeVisibilityIndex(), SetMeshNodeVisibilityIndex()
136 
137     //---------------------------------------------------------------------------
138     //! @brief        キャッシュされたレンダーキーの値を取得します。
139     //!
140     //! @return       レンダーキーの値です。
141     //---------------------------------------------------------------------------
142     u64 GetRenderKeyCache() const { return ref().m_RenderKeyCache; }
143 
144     //---------------------------------------------------------------------------
145     //! @brief        レンダーキーの値をキャッシュに保存します。
146     //!
147     //! @param[in]    renderKey レンダーキーの値です。
148     //---------------------------------------------------------------------------
SetRenderKeyCache(u64 renderKey)149     void SetRenderKeyCache(u64 renderKey) { ref().m_RenderKeyCache = renderKey; }
150 
151 
152     //---------------------------------------------------------------------------
153     //! @brief        リソースのセットアップをおこないます。
154     //!
155     //! @param[in]    owner 所有者となるモデルリソースです。
156     //! @param[in]    allocator アロケータです。
157     //! @param[in]    graphicsFile グラフィックスリソースです。
158     //---------------------------------------------------------------------------
159     Result Setup(ResModel owner, os::IAllocator* allocator, ResGraphicsFile graphicsFile);
160 
161     //---------------------------------------------------------------------------
162     //! @brief        リソースの後始末をおこないます。
163     //---------------------------------------------------------------------------
164     void Cleanup();
165 };
166 
167 typedef nw::ut::ResArrayClass<ResMesh>::type  ResMeshArray;
168 
169 } // namespace res
170 } // namespace gfx
171 } // namespace nw
172 
173 #endif // NW_GFX_RESMESH_H_
174