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