/*---------------------------------------------------------------------------* Project: NintendoWare File : gfx_SceneEnvironmentSetting.h Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Revision: 24950 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include #include #include namespace nw { namespace gfx { NW_UT_RUNTIME_TYPEINFO_DEFINITION(SceneEnvironmentSetting, SceneObject); //---------------------------------------- SceneEnvironmentSetting* SceneEnvironmentSetting::Create( ResSceneObject resource, const SceneEnvironmentSetting::Description& description, os::IAllocator* allocator ) { NW_NULL_ASSERT(allocator); ResSceneEnvironmentSetting resSetting = ResDynamicCast(resource); NW_ASSERT(resSetting.IsValid()); NW_ASSERT( internal::ResCheckRevision( resSetting ) ); void* memory = allocator->Alloc(sizeof(SceneEnvironmentSetting)); NW_NULL_ASSERT(memory); SceneEnvironmentSetting* setting = new(memory) SceneEnvironmentSetting( allocator, resSetting, description); return setting; } //----------------------------------------- void SceneEnvironmentSetting::CreateEnvironmentArray(os::IAllocator* allocator, ResSceneEnvironmentSetting resSetting) { if (resSetting.GetLightSetsCount() != 0) { void* lightSetsMemory = allocator->Alloc(sizeof(LightSetBinder) * resSetting.GetLightSetsCount()); m_LightSets = ut::MoveArray(lightSetsMemory, resSetting.GetLightSetsCount(), allocator); m_LightSets.resize(resSetting.GetLightSetsCount()); ResLightSetArray::iterator lightSetEnd = resSetting.GetLightSets().end(); int lightSetIndex = 0; for (ResLightSetArray::iterator iter = resSetting.GetLightSets().begin(); iter != lightSetEnd; ++iter) { m_LightSets[lightSetIndex].lightSet = GfxPtr(LightSet::Create((*iter), allocator)); ++lightSetIndex; } } if (resSetting.GetCamerasCount() != 0) { void* camerasMemory = allocator->Alloc(sizeof(CameraBinder) * resSetting.GetCamerasCount()); NW_NULL_ASSERT(camerasMemory); m_Cameras = ut::MoveArray(camerasMemory, resSetting.GetCamerasCount(), allocator); } if (resSetting.GetFogsCount() != 0) { void* fogsMemory = allocator->Alloc(sizeof(FogBinder) * resSetting.GetFogsCount()); NW_NULL_ASSERT(fogsMemory); m_Fogs = ut::MoveArray(fogsMemory, resSetting.GetFogsCount(), allocator); } } //----------------------------------------- void SceneEnvironmentSetting::ResolveReference(const SceneContext& sceneContext) { ResSceneEnvironmentSetting resSetting = ResStaticCast(this->GetResSceneObject()); NW_ASSERT(resSetting.IsValid()); ResReferenceSceneObjectArray::iterator cameraEnd = resSetting.GetCameras().end(); for (ResReferenceSceneObjectArray::iterator iter = resSetting.GetCameras().begin(); iter != cameraEnd; ++iter) { // TODO: ResSceneObjectがNULLの場合の処理を追加する if ((*iter).IsValid()) { CameraArray::const_iterator found = std::find_if(sceneContext.GetCameraBegin(), sceneContext.GetCameraEnd(), SceneObjectCompare((*iter))); if (found != sceneContext.GetCameraEnd()) { CameraBinder cameraBinder; cameraBinder.index = (*iter).GetIndex(); cameraBinder.camera = (*found); bool isSuccess = this->m_Cameras.push_back(cameraBinder); NW_ASSERT(isSuccess); } } } ResReferenceSceneObjectArray::iterator fogEnd = resSetting.GetFogs().end(); for (ResReferenceSceneObjectArray::iterator iter = resSetting.GetFogs().begin(); iter != fogEnd; ++iter) { // TODO: ResSceneObjectがNULLの場合の処理を追加する if ((*iter).IsValid()) { FogArray::const_iterator found = std::find_if(sceneContext.GetFogBegin(), sceneContext.GetFogEnd(), SceneObjectCompare((*iter))); if (found != sceneContext.GetFogEnd()) { FogBinder fogBinder; fogBinder.index = (*iter).GetIndex(); fogBinder.fog = (*found); bool isSuccess = this->m_Fogs.push_back(fogBinder); NW_ASSERT(isSuccess); } } } int lightSetIndex = 0; ResLightSetArray::iterator lightSetEnd = resSetting.GetLightSets().end(); for (ResLightSetArray::iterator iter = resSetting.GetLightSets().begin(); iter != lightSetEnd; ++iter) { NW_ASSERT(lightSetIndex < this->m_LightSets.size()); LightSet* lightSet = this->m_LightSets[lightSetIndex].lightSet.Get(); NW_ASSERT(lightSet != NULL); lightSet->ClearAll(); ResReferenceSceneObjectArray::iterator lightEnd = (*iter).GetLights().end(); for (ResReferenceSceneObjectArray::iterator lightIter = (*iter).GetLights().begin(); lightIter != lightEnd; ++lightIter) { // TODO: ResSceneObjectがNULLの場合の処理を追加する if ((*lightIter).IsValid()) { AmbientLightArray::const_iterator foundAmbient = std::find_if(sceneContext.GetAmbientLightsBegin(), sceneContext.GetAmbientLightsEnd(), SceneObjectCompare((*lightIter))); if (foundAmbient != sceneContext.GetAmbientLightsEnd()) { lightSet->SetAmbientLight(*foundAmbient); } HemiSphereLightArray::const_iterator foundHemiSphere = std::find_if(sceneContext.GetHemiSphereLightsBegin(), sceneContext.GetHemiSphereLightsEnd(), SceneObjectCompare((*lightIter))); if (foundHemiSphere != sceneContext.GetHemiSphereLightsEnd()) { lightSet->SetHemiSphereLight(*foundHemiSphere); } #if defined(NW_GFX_VERTEX_LIGHT_ENABLED) VertexLightArray::const_iterator foundVertex = std::find_if(sceneContext.GetVertexLightsBegin(), sceneContext.GetVertexLightsEnd(), SceneObjectCompare((*lightIter))); if (foundVertex != sceneContext.GetVertexLightsEnd()) { lightSet->SetVertexLight(*foundVertex); } #endif FragmentLightArray::const_iterator foundFragment = std::find_if(sceneContext.GetFragmentLightsBegin(), sceneContext.GetFragmentLightsEnd(), SceneObjectCompare((*lightIter))); if (foundFragment != sceneContext.GetFragmentLightsEnd()) { lightSet->SetFragmentLight(*foundFragment); } } } this->m_LightSets[lightSetIndex].index = (*iter).GetIndex(); ++lightSetIndex; } } } // namespace gfx } // namespace nw