1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: gfx_AnimGroup.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: 32337 $
16 *---------------------------------------------------------------------------*/
17
18 #include "precompiled.h"
19
20 #include <nw/anim/anim_AnimBlend.h>
21 #include <nw/gfx/gfx_AnimGroup.h>
22 #include <nw/gfx/gfx_TransformAnimBlendOp.h>
23
24 namespace nw
25 {
26 namespace gfx
27 {
28
29 namespace {
30
31 /*!--------------------------------------------------------------------------*
32 @brief タイプに対応するアニメーションのブレンドオペレーションを取得します。
33 *---------------------------------------------------------------------------*/
34 anim::AnimBlendOp*
GetAnimBlendOpByType(int blendOpType)35 GetAnimBlendOpByType(int blendOpType)
36 {
37 static anim::AnimBlendOpBool blendOpBool;
38 static anim::AnimBlendOpInt blendOpInt;
39 static anim::AnimBlendOpFloat blendOpFloat;
40 static anim::AnimBlendOpVector2 blendOpVector2;
41 static anim::AnimBlendOpVector3 blendOpVector3;
42 static anim::AnimBlendOpRgbaColor blendOpRgbaColor;
43 static anim::AnimBlendOpTexture blendOpTexture;
44
45 static TransformAnimBlendOpStandard blendOpTransform;
46 static TransformAnimBlendOpAccScale blendOpTransformAccScale;
47 static TransformAnimBlendOpQuat blendOpTransformQuat;
48 static TransformAnimBlendOpAccScaleQuat blendOpTransformAccScaleQuat;
49
50 static AnimBlendOpTransform blendOpTransformNode;
51
52 switch (blendOpType)
53 {
54 case anim::ResAnimGroup::BLENDOP_BOOL:
55 return &blendOpBool;
56 case anim::ResAnimGroup::BLENDOP_INT:
57 return &blendOpInt;
58 case anim::ResAnimGroup::BLENDOP_FLOAT:
59 return &blendOpFloat;
60 case anim::ResAnimGroup::BLENDOP_VECTOR2:
61 return &blendOpVector2;
62 case anim::ResAnimGroup::BLENDOP_VECTOR3:
63 return &blendOpVector3;
64 case anim::ResAnimGroup::BLENDOP_RGBA_COLOR:
65 return &blendOpRgbaColor;
66 case anim::ResAnimGroup::BLENDOP_TEXTURE:
67 return &blendOpTexture;
68
69 case anim::ResAnimGroup::BLENDOP_CALCULATED_TRANSFORM:
70 return &blendOpTransform;
71 case anim::ResAnimGroup::BLENDOP_CALCULATED_TRANSFORM_ACCURATE_SCALE:
72 return &blendOpTransformAccScale;
73 case anim::ResAnimGroup::BLENDOP_CALCULATED_TRANSFORM_QUAT:
74 return &blendOpTransformQuat;
75 case anim::ResAnimGroup::BLENDOP_CALCULATED_TRANSFORM_ACCURATE_SCALE_QUAT:
76 return &blendOpTransformAccScaleQuat;
77
78 case anim::ResAnimGroup::BLENDOP_TRANSFORM:
79 return &blendOpTransformNode;
80
81 default:
82 return NULL;
83 }
84 }
85
86 } // namespace
87
88 //----------------------------------------------------------
AnimGroup(anim::ResAnimGroup resAnimGroup,SceneNode * sceneNode,os::IAllocator * allocator)89 AnimGroup::AnimGroup(
90 anim::ResAnimGroup resAnimGroup,
91 SceneNode* sceneNode,
92 os::IAllocator* allocator)
93 : GfxObject(allocator),
94 m_ResAnimGroup(resAnimGroup),
95 m_SceneNode(sceneNode),
96 m_PreEvaluateCallback(NULL),
97 m_FullBakedAnimEnabled(false)
98 {
99 }
100
101 //----------------------------------------------------------
102 void
GetMemorySizeForInitialize(os::MemorySizeCalculator * pSize,const anim::ResAnimGroup resAnimGroup,bool useOriginalValue)103 AnimGroup::GetMemorySizeForInitialize(
104 os::MemorySizeCalculator* pSize,
105 const anim::ResAnimGroup resAnimGroup,
106 bool useOriginalValue)
107 {
108 const int blendOpCount = resAnimGroup.GetBlendOperationsCount();
109 const int memberCount = resAnimGroup.GetMemberInfoSetCount();
110
111 os::MemorySizeCalculator& size = *pSize;
112
113 size += sizeof(anim::AnimBlendOp*) * blendOpCount;
114 size += sizeof(int) * memberCount;
115 size += sizeof(void*) * memberCount;
116 size += sizeof(void*) * memberCount;
117
118 if (useOriginalValue)
119 {
120 size += sizeof(void*) * memberCount;
121 }
122 }
123
124 //----------------------------------------------------------
Initialize(bool useOriginalValue)125 Result AnimGroup::Initialize(bool useOriginalValue)
126 {
127 Result result = INITIALIZE_RESULT_OK;
128
129 {
130 const int blendOpCount = m_ResAnimGroup.GetBlendOperationsCount();
131 NW_ASSERT(blendOpCount > 0);
132
133 void* memory = GetAllocator().Alloc(sizeof(anim::AnimBlendOp*) * blendOpCount);
134
135 if (memory == NULL)
136 {
137 result |= Result::MASK_FAIL_BIT;
138 }
139 NW_ENSURE_AND_RETURN(result);
140
141 m_BlendOperations = ut::MoveArray<anim::AnimBlendOp*>(memory, blendOpCount, &GetAllocator());
142 for (int blendOpIdx = 0; blendOpIdx < blendOpCount; ++blendOpIdx)
143 {
144 const int blendOpType = m_ResAnimGroup.GetBlendOperations(blendOpIdx);
145 m_BlendOperations.PushBackFast(GetAnimBlendOpByType(blendOpType));
146 }
147 }
148
149 const int memberCount = GetMemberCount();
150 NW_ASSERT(memberCount > 0);
151
152 {
153 void* memory = GetAllocator().Alloc(sizeof(int) * memberCount);
154 if (memory == NULL)
155 {
156 result |= Result::MASK_FAIL_BIT;
157 }
158 NW_ENSURE_AND_RETURN(result);
159
160 m_TargetObjectIndicies = ut::MoveArray<int>(memory, memberCount, &GetAllocator());
161 m_TargetObjectIndicies.Resize(memberCount);
162 }
163
164 {
165 void* memory = GetAllocator().Alloc(sizeof(void*) * memberCount);
166 if (memory == NULL)
167 {
168 result |= Result::MASK_FAIL_BIT;
169 }
170 NW_ENSURE_AND_RETURN(result);
171
172 m_TargetObjects = ut::MoveArray<void*>(memory, memberCount, &GetAllocator());
173 m_TargetObjects.Resize(memberCount);
174 }
175
176 {
177 void* memory = GetAllocator().Alloc(sizeof(void*) * memberCount);
178 if (memory == NULL)
179 {
180 result |= Result::MASK_FAIL_BIT;
181 }
182 NW_ENSURE_AND_RETURN(result);
183
184 m_TargetPtrs = ut::MoveArray<void*>(memory, memberCount, &GetAllocator());
185 m_TargetPtrs.Resize(memberCount);
186 }
187
188 if (useOriginalValue)
189 {
190 void* memory = GetAllocator().Alloc(sizeof(void*) * memberCount);
191 if (memory == NULL)
192 {
193 result |= Result::MASK_FAIL_BIT;
194 }
195 NW_ENSURE_AND_RETURN(result);
196
197 m_OriginalValues = ut::MoveArray<const void*>(memory, memberCount, &GetAllocator());
198 m_OriginalValues.Resize(memberCount);
199 }
200
201 return result;
202 }
203
204 //----------------------------------------------------------
205 void
Reset()206 AnimGroup::Reset()
207 {
208 if (!this->HasOriginalValue())
209 {
210 return;
211 }
212
213 for ( int memberIdx = 0 ; memberIdx < this->GetMemberCount() ; ++memberIdx )
214 {
215 const anim::ResAnimGroupMember resAnimGroupMember = this->GetResAnimGroupMember(memberIdx);
216 resAnimGroupMember.SetValueForType(
217 this->GetTargetObject(memberIdx),
218 this->GetOriginalValue(memberIdx));
219 }
220 }
221
222 } // namespace gfx
223 } // namespace nw
224