/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_AnimAdder.cpp Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. 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. The content herein is highly confidential and should be handled accordingly. $Revision: 31311 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include #include #include namespace nw { namespace gfx { NW_UT_RUNTIME_TYPEINFO_DEFINITION(AnimAdder , AnimBlender); //---------------------------------------------------------- const anim::AnimResult* AnimAdder::GetResult( void* target, int memberIdx ) const { //---------------------------------------------------------- // ブレンドオペレーションがない場合および // ブレンドオペレーションにブレンド処理がない場合は上書き処理 const anim::AnimBlendOp* blendOp = m_AnimGroup->GetBlendOperation(memberIdx); if (blendOp == NULL || !blendOp->HasBlend()) { for (int animIdx = m_AnimObjects.Size() - 1; animIdx >= 0; --animIdx) { if (m_AnimObjects[animIdx] == NULL) { continue; } const anim::AnimResult* childResult = m_AnimObjects[animIdx]->GetResult(target, memberIdx); if (childResult != NULL) { return childResult; } } return NULL; } //---------------------------------------------------------- // 補間は操作空間があればそこで行われるべきなので // target の CONVERTED フラグを退避してからオンに anim::AnimResult* result = reinterpret_cast(target); const bool convertedBak = result->IsEnabledFlags(anim::AnimResult::FLAG_CONVERTED); result->EnableFlags(anim::AnimResult::FLAG_CONVERTED, true); //---------------------------------------------------------- // すべての子アニメーションについてループ anim::AnimResult workResult; bool written = false; //for (int animIdx = 0; animIdx < m_AnimObjects.Size(); ++animIdx) for (int animIdx = m_AnimObjects.Size() - 1; animIdx >= 0; --animIdx) { if (m_AnimObjects[animIdx] == NULL) { continue; } const float childWeight = m_Weights[animIdx]; if (!AnimWeightNearlyEqualZero(childWeight)) { // 退避した CONVERTED フラグを work に反映 // 子が CONVERTED を扱う Blender であれば CONVERTED なままの結果が返ってくることを期待 // 子が Evaluator の場合はフラグがオフで返ってくるが blendOp 内で変換されるので問題ない workResult.EnableFlags(anim::AnimResult::FLAG_CONVERTED, convertedBak); // 評価 const anim::AnimResult* childResult = m_AnimObjects[animIdx]->GetResult(&workResult, memberIdx); if (childResult != NULL) { written = true; if (!blendOp->Blend(result, NULL, childResult, &childWeight)) { break; } } } } //---------------------------------------------------------- // target の CONVERTED フラグを復元 if (!convertedBak) { result->DisableFlags(anim::AnimResult::FLAG_CONVERTED); } if (!written) // 有効な子アニメーションなし { return NULL; } //---------------------------------------------------------- // ブレンド後の処理があれば実行 if (!convertedBak && blendOp->HasPostBlend()) { blendOp->PostBlend(result, NULL); } return result; } } // namespace gfx } // namespace nw