#include "stdafx.h" #include "StaticSceneNode.h" #include "ResourceManager.h" #include "CameraManager.h" #include "SceneManager.h" #include "NifAnimationInfo.h" cStaticSceneNode::cStaticSceneNode( eType type ) : cSceneNode( type ) , mVisibleLevel( 0 ) , mOccludeLevel( 1 ) , mPickedByCamera( false ) { mNifAniInfo = new cNifAnimationInfo; } cStaticSceneNode::~cStaticSceneNode() { ClearCollectInfo(); SAFE_DELETE( mNifAniInfo ); } void cStaticSceneNode::OnProcess( unsigned long deltaTime, unsigned long accumTime ) { #ifndef _MODELVIEW ProcessVisibleLevel( deltaTime ); #endif if( mCheckFrustum == false ) return; /// ¹Ýº¹ µ¿ÀÛÀ» °¡Áø °æ¿ì ¿£Áø ³ëµå¸¦ ó¸® if( mNifAniInfo ) { mNeedUpdateTransform = true; mNifAniInfo->Update( deltaTime, accumTime ); } else return; cSceneNode::OnProcess( deltaTime, accumTime ); } void cStaticSceneNode::ProcessVisibleLevel( unsigned long deltaTime ) { if( mVisibleLevel < 3 ) { /// Á¤ÇØÁø °Å¸®¸¸Å­ °Å¸£´Â üũ if( mVisibleLevel < SCENEMAN->CalcVisibleLevel( this ) ) { SetAlphaBlended( 0.0f ); if( mAlpha == mTargetAlpha ) /// no frustum check mCheckFrustum = false; else /// frustum check mCheckFrustum = true; } else { if( mOccludeLevel == 1 && mPickedByCamera ) { mPickedByCamera = false; SetAlphaBlended( 0.4f ); } else { SetAlphaBlended( 1.0f ); } /// frustum check mCheckFrustum = true; } } /// ¾ËÆÄ¸¦ ó¸® ProcessAlpha( deltaTime ); } bool cStaticSceneNode::Init( const cStaticSceneNodeParam& param ) { /// ÆÄÀÏÀ» ·Îµù if( RESOURCEMAN->LoadMapNIF( param.mPathName.Cstr() ) == false ) { assert( 0 && "failed to load nif file" ); return false; } /// ¸®¼Ò½º °ü¸®ÀڷκÎÅÍ ¿£Áø ³ëµå¸¦ º¹Á¦ NiNode* n = RESOURCEMAN->CloneObjectByName( param.mPathName.Cstr() ); if( n == 0 ) { assert( 0 && "failed to clone node from resource manager" ); return false; } /// »óÀ§ ÃʱâÈ­ mSceneNiNode = n; /// °¡½Ã ·¹º§À» ¼³Á¤ mVisibleLevel = param.mVisibleLevel; /// Â÷Æó ·¹º§À» ¼³Á¤ mOccludeLevel = param.mOccludeLevel; /// ¾ËÆÄ ¼Ó¼ºÀ» ¼³Á¤ NiAlphaProperty* alphaProp = (NiAlphaProperty*)n->GetProperty( NiProperty::ALPHA ); if( alphaProp == 0 ) { alphaProp = NiNew NiAlphaProperty; alphaProp->SetAlphaBlending( false ); alphaProp->SetAlphaTesting( false ); n->AttachProperty( alphaProp ); } if( cSceneNode::Init( param ) == false ) { return false; } /// ÀçÁúÀ» ¼³Á¤ if( param.mMaterialApplied ) SetMaterial( param.mMaterial ); /// ¾È°³ ¼Ó¼ºÀ» ºÎÂø // if( param.mFogApplied ) // n->AttachProperty( FOGAGENT->GetFogProperty() ); if( param.mNoAttachLight == false ) { n->AttachEffect( SCENEMAN->GetAmbientLight() ); // /// Á¶¸íÀ» ºÎÂø // n->AttachEffect( LIGHTAGENT->GetSceneAmbientLight( 0 ) ); // n->AttachEffect( LIGHTAGENT->GetSceneDirLight( 0 ) ); } /// ¿£Áø ³ëµå¸¦ ¼³Á¤ bool selectiveUpdate = true; bool rigid = false; n->SetSelectiveUpdateFlags( selectiveUpdate, mNifAniInfo!=0, rigid ); /// ¿£Áø ³ëµå¸¦ ó¸® n->UpdateProperties(); n->UpdateEffects(); n->Update( 0.0f ); n->UpdateNodeBound(); /// ¾Ö´Ï¸ÞÀÌ¼Ç ÄÁÆ®·Ñ·¯ Á¤º¸ ¼öÁý mNifAniInfo->CollectData( n ); if( mNifAniInfo->GetNumberOfControllers() ) { mNifAniInfo->SetAnimType( NiTimeController::APP_INIT ); mNifAniInfo->SetLooping( true ); } else { /// ¾Ö´Ï Á¤º¸°¡ ¾ø´Ù¸é ¸Þ¸ð¸® ÇØÁ¦ SAFE_DELETE(mNifAniInfo); } if( mNifAniInfo && param.mDisableAnimation == true ) mNifAniInfo->Stop(); return true; } bool cStaticSceneNode::Init( NiNode* node ) { /// Á¶¸íÀ» ºÎÂø // node->AttachEffect( SCENEMAN->GetAmbientLight() ); /// ¿£Áø ³ëµå¸¦ ¼³Á¤ node->SetSelectiveUpdate( true ); node->SetSelectiveUpdateTransforms( false ); node->SetSelectiveUpdatePropertyControllers( true ); node->SetSelectiveUpdateRigid( true ); /// ¿£Áø ³ëµå¸¦ ó¸® node->UpdateProperties(); node->UpdateEffects(); node->Update( 0.f ); node->UpdateNodeBound(); /// ¾Ö´Ï¸ÞÀÌ¼Ç ÄÁÆ®·Ñ·¯ Á¤º¸ ¼öÁý mNifAniInfo->CollectData( node ); mNifAniInfo->SetAnimType( NiTimeController::APP_INIT ); mNifAniInfo->SetLooping( true ); /// »óÀ§ ÃʱâÈ­ mSceneNiNode = node; mBoundSphere.Set( GetCenter(), GetRadius() ); return true; } void cStaticSceneNode::SetMaterial( const cMaterialData& material ) { cMatPropList::cIterator i = mMatPropList.Begin(); cMatPropList::cIterator end = mMatPropList.End(); for( ; i != end; ++i ) { NiMaterialProperty* matProp = (NiMaterialProperty*)*i; matProp->SetAmbientColor( material.mAmbient ); matProp->SetDiffuseColor( material.mDiffuse ); matProp->SetSpecularColor( material.mSpecular ); matProp->SetEmittance( material.mEmissive ); matProp->SetShineness( material.mShininess ); matProp->SetAlpha( material.mAlpha ); } mMaterial = material; } ////////////////////////////////////////////////////////////////////////// cManagedStaticSceneNode::cManagedStaticSceneNode( eType type ) : cStaticSceneNode( type ) { mIsMouseOver = false; } cManagedStaticSceneNode::~cManagedStaticSceneNode() { }