bool BMaxObject::UpdateModel(SceneState * sceneState /*= NULL*/) { if (!m_pAnimatedMesh) return false; int nIndex = (sceneState && IsLODEnabled()) ? m_pAnimatedMesh->GetLodIndex(sceneState->GetCameraToCurObjectDistance()/*, GetScaling()*/) : 0; CParaXModel* pModel = m_pAnimatedMesh->GetModel(nIndex); if (pModel == NULL) return false; // just a single standing animation is supported now and looped. if (!m_CurrentAnim.IsValid()) m_CurrentAnim = pModel->GetAnimIndexByID(0); if (m_CurrentAnim.IsValid() && IsAnimEnabled()) { int nAnimLength = std::max(1, m_CurrentAnim.nEndFrame - m_CurrentAnim.nStartFrame); int nToDoFrame = (m_CurrentAnim.nCurrentFrame + (int)(sceneState->dTimeDelta * 1000)) % nAnimLength; m_CurrentAnim.nCurrentFrame = nToDoFrame; } pModel->m_CurrentAnim = m_CurrentAnim; pModel->m_NextAnim.nIndex = 0; pModel->m_BlendingAnim.MakeInvalid(); pModel->blendingFactor = 0; pModel->animate(sceneState, NULL, GetAnimInstanceFields()); return true; }
HRESULT ParaEngine::CLightObject::RenderMesh(SceneState * sceneState) { if (!m_pAnimatedMesh) return E_FAIL; if (GetPrimaryTechniqueHandle() < 0) { // try loading the asset if it has not been done before. m_pAnimatedMesh->LoadAsset(); if (m_pAnimatedMesh->IsLoaded()) { SetPrimaryTechniqueHandle(m_pAnimatedMesh->GetPrimaryTechniqueHandle()); UpdateGeometry(); } return E_FAIL; } if (!CGlobals::GetEffectManager()->IsCurrentEffectValid()) { return E_FAIL; } CParaXModel* pModel = m_pAnimatedMesh->GetModel(0); if (pModel == NULL) return E_FAIL; sceneState->SetCurrentSceneObject(this); SetFrameNumber(sceneState->m_nRenderCount); // get world transform matrix Matrix4 mxWorld; GetRenderMatrix(mxWorld); RenderDevicePtr pd3dDevice = sceneState->m_pd3dDevice; EffectManager* pEffectManager = CGlobals::GetEffectManager(); pEffectManager->applyObjectLocalLighting(this); CEffectFile* pEffectFile = pEffectManager->GetCurrentEffectFile(); CGlobals::GetWorldMatrixStack().push(mxWorld); if (pEffectFile == 0) { // TODO: Fixed Function. } else { // apply block space lighting for object whose size is comparable to a single block size BlockWorldClient* pBlockWorldClient = BlockWorldClient::GetInstance(); if (pBlockWorldClient && pBlockWorldClient->IsInBlockWorld()) { uint8_t brightness[2]; Uint16x3 blockId_ws(0, 0, 0); Vector3 vPos = GetPosition(); BlockCommon::ConvertToBlockIndex(vPos.x, vPos.y + 0.1f, vPos.z, blockId_ws.x, blockId_ws.y, blockId_ws.z); float fLightness; pBlockWorldClient->GetBlockMeshBrightness(blockId_ws, brightness); // block light float fBlockLightness = Math::Max(pBlockWorldClient->GetLightBrightnessFloat(brightness[0]), 0.1f); sceneState->GetCurrentLightStrength().y = fBlockLightness; // sun light fLightness = Math::Max(pBlockWorldClient->GetLightBrightnessFloat(brightness[1]), 0.1f); sceneState->GetCurrentLightStrength().x = fLightness; fLightness *= pBlockWorldClient->GetSunIntensity(); fLightness = Math::Max(fLightness, fBlockLightness); sceneState->GetLocalMaterial().Ambient = (LinearColor(fLightness*0.7f, fLightness*0.7f, fLightness*0.7f, 1.f)); sceneState->GetLocalMaterial().Diffuse = (LinearColor(fLightness*0.4f, fLightness*0.4f, fLightness*0.4f, 1.f)); sceneState->EnableLocalMaterial(true); } // just a single standing animation is supported now and looped. if (!m_CurrentAnim.IsValid()) m_CurrentAnim = pModel->GetAnimIndexByID(0); if (m_CurrentAnim.IsValid()) { int nAnimLength = std::max(1, m_CurrentAnim.nEndFrame - m_CurrentAnim.nStartFrame); int nToDoFrame = (m_CurrentAnim.nCurrentFrame + (int)(sceneState->dTimeDelta * 1000)) % nAnimLength; m_CurrentAnim.nCurrentFrame = nToDoFrame; } pModel->m_CurrentAnim = m_CurrentAnim; pModel->m_NextAnim.nIndex = 0; pModel->m_BlendingAnim.MakeInvalid(); pModel->blendingFactor = 0; pModel->animate(sceneState, NULL); // force CParaXModel::BMAX_MODEL? pModel->draw(sceneState, NULL); } CGlobals::GetWorldMatrixStack().pop(); return S_OK; }