1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: gfx_SceneInitializer.cpp
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: 22799 $
14 *---------------------------------------------------------------------------*/
15
16 #include "precompiled.h"
17
18 #include <nw/gfx/gfx_SceneTraverser.h>
19 #include <nw/gfx/gfx_SceneContext.h>
20 #include <nw/gfx/gfx_SceneNode.h>
21 #include <nw/gfx/gfx_TransformNode.h>
22 #include <nw/gfx/gfx_Model.h>
23 #include <nw/gfx/gfx_SkeletalModel.h>
24 #include <nw/gfx/gfx_Camera.h>
25 #include <nw/gfx/gfx_Fog.h>
26 #include <nw/gfx/gfx_FragmentLight.h>
27 #include <nw/gfx/gfx_VertexLight.h>
28 #include <nw/gfx/gfx_AmbientLight.h>
29 #include <nw/gfx/gfx_HemiSphereLight.h>
30 #include <nw/gfx/gfx_ParticleSet.h>
31 #include <nw/gfx/gfx_IMaterialIdGenerator.h>
32 #include <nw/gfx/gfx_RelativeHashMaterialIdGenerator.h>
33
34 namespace nw
35 {
36 namespace gfx
37 {
38
39 NW_UT_RUNTIME_TYPEINFO_DEFINITION(SceneInitializer, ISceneVisitor);
40
41 //----------------------------------------
42 SceneInitializer*
Create(os::IAllocator * allocator)43 SceneInitializer::Builder::Create(
44 os::IAllocator* allocator
45 )
46 {
47 NW_NULL_ASSERT(allocator);
48
49 void* memory = allocator->Alloc(sizeof(SceneInitializer));
50 NW_NULL_ASSERT(memory);
51
52 NW_ASSERTMSG(
53 m_Description.materialIdGenerator != NULL, "SceneInitializer need to set an IMaterialIdGenerator instance.");
54
55 SceneInitializer* initializer = new(memory) SceneInitializer(allocator, m_Description);
56
57 return initializer;
58 }
59
60 //----------------------------------------
VisitModel(Model * model)61 void SceneInitializer::VisitModel(Model* model)
62 {
63 if (m_MaterialIdGenerator.Get() != NULL)
64 {
65 nw::gfx::MaterialArray::iterator materialEnd = model->GetMaterials().second;
66 for (nw::gfx::MaterialArray::iterator material = model->GetMaterials().first;
67 material != materialEnd;
68 ++material)
69 {
70 m_MaterialIdGenerator.Get()->Accept(*material);
71 }
72 }
73 }
74
75 //----------------------------------------
VisitSkeletalModel(SkeletalModel * model)76 void SceneInitializer::VisitSkeletalModel(SkeletalModel* model)
77 {
78 if (m_MaterialIdGenerator.Get() != NULL)
79 {
80 nw::gfx::MaterialArray::iterator materialEnd = model->GetMaterials().second;
81 for (nw::gfx::MaterialArray::iterator material = model->GetMaterials().first;
82 material != materialEnd;
83 ++material)
84 {
85 m_MaterialIdGenerator.Get()->Accept(*material);
86 }
87 }
88 }
89
90 //----------------------------------------
Begin()91 void SceneInitializer::Begin()
92 {
93 }
94
95 //----------------------------------------
End()96 void SceneInitializer::End()
97 {
98 m_MaterialIdGenerator.Get()->Generate();
99 }
100
101 } // namespace gfx
102 } // namespace nw
103