ad5cd7b16a
match the genesis editor version 1.3.1.921.
267 lines
7.3 KiB
C++
267 lines
7.3 KiB
C++
/****************************************************************************
|
||
Copyright (c) 2011-2013,WebJet Business Division,CYOU
|
||
|
||
http://www.genesis-3d.com.cn
|
||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||
of this software and associated documentation files (the "Software"), to deal
|
||
in the Software without restriction, including without limitation the rights
|
||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||
copies of the Software, and to permit persons to whom the Software is
|
||
furnished to do so, subject to the following conditions:
|
||
|
||
The above copyright notice and this permission notice shall be included in
|
||
all copies or substantial portions of the Software.
|
||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||
THE SOFTWARE.
|
||
****************************************************************************/
|
||
#include "stdneb.h"
|
||
#include "simpleskycomponent.h"
|
||
#include "appframework/actor.h"
|
||
#include "resource/meshres.h"
|
||
#include "graphicsystem/Material/materialinstance.h"
|
||
|
||
namespace App
|
||
{
|
||
__ImplementClass(App::SimpleSkyComponent, 'SKRC', App::MeshRenderComponent );
|
||
|
||
SimpleSkyComponent::SimpleSkyComponent():
|
||
m_skyTex0(NULL),
|
||
m_skyTex1(NULL),
|
||
m_skyTex2(NULL),
|
||
m_skyTex3(NULL),
|
||
m_skyTex4(NULL),
|
||
m_skyTex5(NULL),
|
||
m_skyFogLowest(0.0f),
|
||
m_skyFogHighest(0.5f)
|
||
{
|
||
|
||
}
|
||
|
||
SimpleSkyComponent::~SimpleSkyComponent()
|
||
{
|
||
|
||
}
|
||
|
||
void SimpleSkyComponent::SetupCallbacks()
|
||
{
|
||
mActor->RegisterComponentCallback(this, BeginFrame);
|
||
Super::SetupCallbacks();
|
||
}
|
||
|
||
void SimpleSkyComponent::OnActivate()
|
||
{
|
||
Super::OnActivate();
|
||
Graphic::GraphicSystem::Instance()->m_BeforeDrawEvent += Delegates::newDelegate(this, &SimpleSkyComponent::updateScale);
|
||
}
|
||
|
||
void SimpleSkyComponent::_BuildRenderObject()
|
||
{
|
||
Super::_BuildRenderObject();
|
||
}
|
||
|
||
void SimpleSkyComponent::_BuildRenderRes()
|
||
{
|
||
Super::_BuildRenderRes();
|
||
mRenderObject->SetTransform(mActor->GetWorldTransform());
|
||
Math::bbox bb;
|
||
bb.pmin = Math::point(-Math::N_INFINITY, -Math::N_INFINITY, -Math::N_INFINITY);
|
||
bb.pmax = Math::point(Math::N_INFINITY, Math::N_INFINITY, Math::N_INFINITY);
|
||
mRenderObject->SetBoundingBox(bb);
|
||
mRenderObject->SetProjected(false);
|
||
}
|
||
|
||
void SimpleSkyComponent::OnDeactivate()
|
||
{
|
||
Super::OnDeactivate();
|
||
Graphic::GraphicSystem::Instance()->m_BeforeDrawEvent -= Delegates::newDelegate(this, &SimpleSkyComponent::updateScale);
|
||
}
|
||
|
||
void SimpleSkyComponent::OnDestroy()
|
||
{
|
||
Super::OnDestroy();
|
||
}
|
||
|
||
void SimpleSkyComponent::_OnMoveAfter()
|
||
{
|
||
Super::_OnMoveAfter();
|
||
}
|
||
|
||
void SimpleSkyComponent::_OnBeginFrame()
|
||
{
|
||
Super::_OnBeginFrame();
|
||
|
||
GPtr<Graphic::Camera> pMainCam = Graphic::GraphicSystem::Instance()->GetSceneDefaultCamera();
|
||
// mActor->SetPosition(pMainCam->GetTransform().get_position());
|
||
}
|
||
|
||
void SimpleSkyComponent::_UpdateRenderQueue()
|
||
{
|
||
//[zhongdaohuan][render_obj]<5D><>ʱɾ<CAB1><C9BE>ʵ<EFBFBD><CAB5>
|
||
}
|
||
|
||
void SimpleSkyComponent::CopyFrom(const GPtr<Component> &pComponent)
|
||
{
|
||
if( !pComponent.isvalid() )
|
||
return;
|
||
if( !pComponent->GetRtti()->IsDerivedFrom( *(this->GetRtti()) ) )
|
||
return;
|
||
|
||
Super::CopyFrom(pComponent);
|
||
}
|
||
|
||
void SimpleSkyComponent::updateScale( Graphic::Camera* camera )
|
||
{
|
||
float nh =camera->GetCameraSetting().GetNearHeight();
|
||
float nw = camera->GetCameraSetting().GetNearWidth();
|
||
float nz = camera->GetCameraSetting().GetZNear();
|
||
|
||
float scale = Math::n_max(nh,nw);
|
||
scale = Math::n_max(nz,scale)/50;
|
||
|
||
Math::matrix44 _mscale;
|
||
_mscale.scale(Math::float4(scale,scale,scale,1.0f));
|
||
Math::matrix44 trans = camera->GetCameraSetting().GetViewTransform();
|
||
trans.set_position(Math::float4(0.0f,0.0f,0.0f,1.0f));
|
||
Math::matrix44 rot = Math::matrix44::rotationx(-90);
|
||
trans = Math::matrix44::multiply(trans,rot);
|
||
trans = Math::matrix44::multiply(trans,_mscale);
|
||
mActor->SetTransform(trans);
|
||
}
|
||
|
||
//-----------------------------------------------------------------
|
||
void SimpleSkyComponent:: SetSkyTexByNum( int num, Util::String& tex )
|
||
{
|
||
switch(num)
|
||
{
|
||
case 0:
|
||
m_skyTex0 = tex;
|
||
SetTexture(0, "_diffuseMap", m_skyTex0);
|
||
break;
|
||
case 1:
|
||
m_skyTex1 = tex;
|
||
SetTexture(1, "_diffuseMap", m_skyTex1);
|
||
break;
|
||
case 2:
|
||
m_skyTex2 = tex;
|
||
SetTexture(2, "_diffuseMap", m_skyTex2);
|
||
break;
|
||
case 3:
|
||
m_skyTex3 = tex;
|
||
SetTexture(3, "_diffuseMap", m_skyTex3);
|
||
break;
|
||
case 4:
|
||
m_skyTex4 = tex;
|
||
SetTexture(4, "_diffuseMap", m_skyTex4);
|
||
break;
|
||
case 5:
|
||
m_skyTex5 = tex;
|
||
SetTexture(5, "_diffuseMap", m_skyTex5);
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
const Util::String SimpleSkyComponent::GetSkyTexByNum( int num )
|
||
{
|
||
Util::String temp;
|
||
switch(num)
|
||
{
|
||
case 0:
|
||
temp = m_skyTex0;
|
||
break;
|
||
case 1:
|
||
temp = m_skyTex1;
|
||
break;
|
||
case 2:
|
||
temp = m_skyTex2;
|
||
break;
|
||
case 3:
|
||
temp = m_skyTex3;
|
||
break;
|
||
case 4:
|
||
temp = m_skyTex4;
|
||
break;
|
||
case 5:
|
||
temp = m_skyTex5;
|
||
break;
|
||
default:
|
||
temp = NULL;
|
||
break;
|
||
}
|
||
return temp;
|
||
}
|
||
//------------------------------------------------------------------------------
|
||
float SimpleSkyComponent::GetSkyFogLowest()
|
||
{
|
||
return m_skyFogLowest;
|
||
}
|
||
float SimpleSkyComponent::GetSkyFogHighest()
|
||
{
|
||
return m_skyFogHighest;
|
||
}
|
||
void SimpleSkyComponent::SetSkyFogLowest(IndexT iSubMesh, const ShaderParamString& paramName,float low)
|
||
{
|
||
m_skyFogLowest = low;
|
||
GPtr<Graphic::MaterialInstance>& mat = GetMaterial(iSubMesh);
|
||
if ( mat )
|
||
{
|
||
mat->SetConstantParam(paramName,low);
|
||
}
|
||
}
|
||
void SimpleSkyComponent::SetSkyFogHighest(IndexT iSubMesh, const ShaderParamString& paramName,float high)
|
||
{
|
||
m_skyFogHighest = high;
|
||
GPtr<Graphic::MaterialInstance>& mat = GetMaterial(iSubMesh);
|
||
if ( mat )
|
||
{
|
||
mat->SetConstantParam(paramName,high);
|
||
}
|
||
}
|
||
//------------------------------------------------------------------------------
|
||
void SimpleSkyComponent::SetMaterialID( IndexT iSubMesh, const Resources::ResourceId& matID,const bool bCopy/* = false*/,Resources::Priority p )
|
||
{
|
||
//skybox's setmaterial should be null
|
||
return;
|
||
}
|
||
//------------------------------------------------------------------------------
|
||
void SimpleSkyComponent::GetReferenceResourceId(Util::Array<Resources::ReferenceResource>& list) const
|
||
{
|
||
list.Append(Resources::ReferenceResource(mMeshInfo.meshID, Resources::RR_Unknown));
|
||
|
||
list.Append(Resources::ReferenceResource(m_skyTex0, Resources::RR_Texture));
|
||
list.Append(Resources::ReferenceResource(m_skyTex1, Resources::RR_Texture));
|
||
list.Append(Resources::ReferenceResource(m_skyTex2, Resources::RR_Texture));
|
||
list.Append(Resources::ReferenceResource(m_skyTex3, Resources::RR_Texture));
|
||
list.Append(Resources::ReferenceResource(m_skyTex4, Resources::RR_Texture));
|
||
list.Append(Resources::ReferenceResource(m_skyTex5, Resources::RR_Texture));
|
||
|
||
}
|
||
//------------------------------------------------------------------------
|
||
void SimpleSkyComponent::SetCastShadow( bool bCastShadow )
|
||
{
|
||
|
||
}
|
||
//------------------------------------------------------------------------
|
||
bool SimpleSkyComponent::GetCastShadow()
|
||
{
|
||
return false;
|
||
}
|
||
//------------------------------------------------------------------------
|
||
void SimpleSkyComponent::SetReceiveShadow( bool bCastShadow )
|
||
{
|
||
|
||
}
|
||
//------------------------------------------------------------------------
|
||
bool SimpleSkyComponent::GetReceiveShadow()
|
||
{
|
||
return false;
|
||
}
|
||
}
|