1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_SceneBuilder.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: $
14  *---------------------------------------------------------------------------*/
15 
16 
17 #ifndef NW_GFX_SCENEBUILDER_H_
18 #define NW_GFX_SCENEBUILDER_H_
19 
20 #include <nw/gfx/gfx_SceneObject.h>
21 
22 namespace nw
23 {
24 namespace gfx
25 {
26 
27 class SceneNode;
28 
29 //---------------------------------------------------------------------------
30 //! @brief        シーン上のオブジェクトを生成するクラスです。
31 //---------------------------------------------------------------------------
32 class SceneBuilder
33 {
34 private:
35     NW_DISALLOW_COPY_AND_ASSIGN(SceneBuilder);
36 
37 public:
38     //! コンストラクタです。
SceneBuilder()39     SceneBuilder()
40     : m_IsFixedSizeMemory(true),
41       m_MaxChildren(SceneObject::DEFAULT_MAX_CHILDREN),
42       m_MaxCallbacks(SceneObject::DEFAULT_MAX_CALLBACKS),
43       m_BufferOption(0),
44       m_SharedMaterialModel(NULL),
45       m_MaxAnimObjectsPerGroup(1),
46       m_ParticleSetMarginCount(0),
47       m_IsAnimationEnabled(true)
48     {}
49 
50     //! デストラクタです。
~SceneBuilder()51     ~SceneBuilder() {}
52 
53     //! リソースを設定します。
Resource(ResSceneObject resource)54     SceneBuilder& Resource(ResSceneObject resource) { m_Resource = resource; return *this; }
55 
56     //! @brief 生成時以外にもメモリを確保するかどうかのフラグを設定します。
57     //!
58     //!        true を指定すると、生成時のみ固定サイズのメモリ確保を行います。
59     //!
60     //!        false を指定すると、生成時以外にも必要に応じて動的にメモリ確保が行われます。
IsFixedSizeMemory(bool isFixedSizeMemory)61     SceneBuilder& IsFixedSizeMemory(bool isFixedSizeMemory)
62     {
63         m_IsFixedSizeMemory = isFixedSizeMemory;
64         return *this;
65     }
66 
67     //! 子の最大数を設定します。
MaxChildren(int maxChildren)68     SceneBuilder& MaxChildren(int maxChildren) { m_MaxChildren = maxChildren; return *this; }
69 
70     //! 管理できるコールバックの最大数を設定します。
MaxCallbacks(int maxCallbacks)71     SceneBuilder& MaxCallbacks(int maxCallbacks) { m_MaxCallbacks = maxCallbacks; return *this; }
72 
73     //! @brief マテリアルのバッファを生成する数を設定します。
74     //!
75     //!        現在の実装では0か1を指定する必要があります。
76     //!
NW_DEPRECATED_FUNCTION(SceneBuilder & MaterialBufferCount (int bufferCount))77     NW_DEPRECATED_FUNCTION(SceneBuilder& MaterialBufferCount(int bufferCount))
78     {
79         NW_UNUSED_VARIABLE(bufferCount);
80         return *this;
81     }
82 
83     //! @brief バッファの生成オプションを設定します。
84     //!
85     //!
86     //! @param bufferOption Model::BufferOptionで定義されるフラグの組み合わせです。
87     //!        SharedMaterialModel が指定された場合、BufferOption は指定することができません。
88     //!        BufferOption が指定された場合は動作を停止します。
89     //!
90     //! @param[in] bufferOption Model::BufferOptionで定義されるフラグの組み合わせです。
91     //!
BufferOption(bit32 bufferOption)92     SceneBuilder& BufferOption(bit32 bufferOption) { m_BufferOption = bufferOption; return *this; }
93 
94     //! @brief マテリアルを共有する場合に共有元のモデルを設定します。
95     //!
96     //!        所有権の移動を行いません。
97     //!        マテリアルを最初に生成したモデルがマテリアルの所有権を持ちます。
98     //!        共有元のモデルが先に破棄された場合は未定義の動作となります。
99     //!
100     //! @param[in] model 共有するマテリアルを持つモデルです。
101     //!
SharedMaterialModel(Model * model)102     SceneBuilder& SharedMaterialModel(Model* model) { m_SharedMaterialModel = model; return *this; }
103 
104     //! @brief アニメオブジェクトの最大数を指定します。
105     //!
106     //! @details 複数のAnimGroupを持つ場合は、
107     //!          各AnimGroupごとのアニメオブジェクトの最大数のうち、最も大きいものを指定してください。
108     //!
MaxAnimObjectsPerGroup(s32 maxAnimObjects)109     SceneBuilder& MaxAnimObjectsPerGroup(s32 maxAnimObjects) { m_MaxAnimObjectsPerGroup = maxAnimObjects; return *this; }
110 
111     //! @brief パーティクルセットを生成する場合のバッファを生成する数を設定します。
112     //!
113     //!        値が指定されている場合、リソース内パーティクルセット数に指定された値を加えた数で生成されます。
114     //!        0が指定されている場合、リソース内パーティクルセット数にデフォルトマージンを加えた数で生成されます。
115     //!
ParticleSetMarginCount(int marginCount)116     SceneBuilder& ParticleSetMarginCount(int marginCount) { m_ParticleSetMarginCount = marginCount; return *this; }
117 
118     //! @brief アニメーション可能かを設定します。
119     //!
120     //!        false を指定すると AnimBinding の生成を行いません。
121     //!        そのためアニメーションのバインドができなくなりますが、
122     //!        アニメーション更新の処理が行われなくなるため、
123     //!        シーンアップデートのパフォーマンスが向上します。
IsAnimationEnabled(bool isAnimationEnabled)124     SceneBuilder& IsAnimationEnabled(bool isAnimationEnabled) { m_IsAnimationEnabled = isAnimationEnabled; return *this; }
125 
126     //! @brief        設定されたリソースから、ひとつのシーンオブジェクトを生成します。
127     //!               このとき、リソースに含まれる子階層以下のオブジェクトは生成されませんので、
128     //!               個別に生成する必要があります。
129     //!
130     //! @param[in]    allocator アロケータです。
131     //! @param[in]    deviceAllocator デバイスメモリのアロケータです。
132     //!
133     //! @return       生成したシーンオブジェクトを返します。
134     //!
135     SceneObject* CreateObject(os::IAllocator* allocator, os::IAllocator* deviceAllocator);
136 
137     //! @brief        設定されたリソースをルートノードとしたシーンツリーを生成します。
138     //!               リソースに含まれる子階層以下の参照をたどってすべてインスタンス化していくため、
139     //!               リソースファイルに含まれるモデルすべてを初期化する、などの処理で使用すると
140     //!               子階層のオブジェクトが2重にインスタンス化されます。
141     //!
142     //! @param[in]    allocator アロケータです。
143     //! @param[in]    deviceAllocator デバイスメモリのアロケータです。
144     //!
145     //! @return       生成したルートノードのシーンオブジェクトを返します。
146     //!
147     SceneObject* CreateTree(os::IAllocator* allocator, os::IAllocator* deviceAllocator);
148 
149 private:
150     //----------------------------------------
151     //! @name シーンオブジェクトの生成
152     //@{
153 
154     //! @brief        シーンオブジェクトを生成します。
155     //!
156     //! @param[in]    parent 親となるSceneNodeです。
157     //! @param[in]    resource リソースです。
158     //! @param[in]    allocator アロケータです。
159     //! @param[in]    deviceAllocator デバイスメモリのアロケータです。
160     //! @param[in]    isRecursive 再帰的に子階層を生成するかどうかのフラグです。
161     //!
162     //! @return       生成したオブジェクトを返します。
163     //!
164     SceneObject* BuildSceneObject(
165         SceneNode* parent,
166         ResSceneObject resource,
167         os::IAllocator* allocator,
168         os::IAllocator* deviceAllocator,
169         bool isRecursive);
170 
171     //! @brief        ノードの子を構築します。
172     //!
173     //! @param[in]    parent 親のシーンノードです。
174     //! @param[in]    resource リソースです。
175     //! @param[in]    allocator アロケータです。
176     //! @param[in]    deviceAllocator デバイスメモリのアロケータです。
177     //!
178     void BuildChildren(
179         SceneNode* parent,
180         ResSceneObject resource,
181         os::IAllocator* allocator,
182         os::IAllocator* deviceAllocator);
183     //@}
184 
185     ResSceneObject m_Resource;
186     bool m_IsFixedSizeMemory;
187     int m_MaxChildren;
188     int m_MaxCallbacks;
189     bit32 m_BufferOption;
190     Model* m_SharedMaterialModel;
191 
192     int m_MaxAnimObjectsPerGroup;
193     int m_ParticleSetMarginCount;
194 
195     bool m_IsAnimationEnabled;
196 };
197 
198 } // namespace gfx
199 } // namespace nw
200 
201 #endif // NW_GFX_SCENEBUILDER_H_
202