1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: gfx_AnimAdder.cpp
4
5 Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain proprietary
8 information of Nintendo and/or its licensed developers and are protected by
9 national and international copyright laws. They may not be disclosed to third
10 parties or copied or duplicated in any form, in whole or in part, without the
11 prior written consent of Nintendo.
12
13 The content herein is highly confidential and should be handled accordingly.
14
15 $Revision: 31311 $
16 *---------------------------------------------------------------------------*/
17
18 #include "precompiled.h"
19
20 #include <nw/anim/anim_AnimBlend.h>
21 #include <nw/gfx/gfx_AnimAdder.h>
22 #include <nw/gfx/gfx_AnimGroup.h>
23
24 namespace nw
25 {
26 namespace gfx
27 {
28
29 NW_UT_RUNTIME_TYPEINFO_DEFINITION(AnimAdder , AnimBlender);
30
31 //----------------------------------------------------------
32 const anim::AnimResult*
GetResult(void * target,int memberIdx) const33 AnimAdder::GetResult(
34 void* target,
35 int memberIdx
36 ) const
37 {
38 //----------------------------------------------------------
39 // ブレンドオペレーションがない場合および
40 // ブレンドオペレーションにブレンド処理がない場合は上書き処理
41 const anim::AnimBlendOp* blendOp = m_AnimGroup->GetBlendOperation(memberIdx);
42 if (blendOp == NULL || !blendOp->HasBlend())
43 {
44 for (int animIdx = m_AnimObjects.Size() - 1; animIdx >= 0; --animIdx)
45 {
46 if (m_AnimObjects[animIdx] == NULL)
47 {
48 continue;
49 }
50 const anim::AnimResult* childResult =
51 m_AnimObjects[animIdx]->GetResult(target, memberIdx);
52 if (childResult != NULL)
53 {
54 return childResult;
55 }
56 }
57 return NULL;
58 }
59
60 //----------------------------------------------------------
61 // 補間は操作空間があればそこで行われるべきなので
62 // target の CONVERTED フラグを退避してからオンに
63 anim::AnimResult* result = reinterpret_cast<anim::AnimResult*>(target);
64 const bool convertedBak = result->IsEnabledFlags(anim::AnimResult::FLAG_CONVERTED);
65 result->EnableFlags(anim::AnimResult::FLAG_CONVERTED, true);
66
67 //----------------------------------------------------------
68 // すべての子アニメーションについてループ
69 anim::AnimResult workResult;
70 bool written = false;
71 //for (int animIdx = 0; animIdx < m_AnimObjects.Size(); ++animIdx)
72 for (int animIdx = m_AnimObjects.Size() - 1; animIdx >= 0; --animIdx)
73 {
74 if (m_AnimObjects[animIdx] == NULL)
75 {
76 continue;
77 }
78 const float childWeight = m_Weights[animIdx];
79 if (!AnimWeightNearlyEqualZero(childWeight))
80 {
81 // 退避した CONVERTED フラグを work に反映
82 // 子が CONVERTED を扱う Blender であれば CONVERTED なままの結果が返ってくることを期待
83 // 子が Evaluator の場合はフラグがオフで返ってくるが blendOp 内で変換されるので問題ない
84 workResult.EnableFlags(anim::AnimResult::FLAG_CONVERTED, convertedBak);
85
86 // 評価
87 const anim::AnimResult* childResult =
88 m_AnimObjects[animIdx]->GetResult(&workResult, memberIdx);
89 if (childResult != NULL)
90 {
91 written = true;
92 if (!blendOp->Blend(result, NULL, childResult, &childWeight))
93 {
94 break;
95 }
96 }
97 }
98 }
99
100 //----------------------------------------------------------
101 // target の CONVERTED フラグを復元
102 if (!convertedBak)
103 {
104 result->DisableFlags(anim::AnimResult::FLAG_CONVERTED);
105 }
106
107 if (!written) // 有効な子アニメーションなし
108 {
109 return NULL;
110 }
111
112 //----------------------------------------------------------
113 // ブレンド後の処理があれば実行
114 if (!convertedBak && blendOp->HasPostBlend())
115 {
116 blendOp->PostBlend(result, NULL);
117 }
118 return result;
119 }
120
121 } // namespace gfx
122 } // namespace nw
123