1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: anim_ResAnimGroup.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: $
16 *---------------------------------------------------------------------------*/
17
18 #include "../precompiled.h"
19
20 #include <nw/anim/res/anim_ResAnimGroup.h>
21 #include <nw/gfx/gfx_SkeletalModel.h>
22 #include <nw/gfx/gfx_Model.h>
23 #include <nw/gfx/res/gfx_ResTexture.h>
24 #include <nw/gfx/gfx_Camera.h>
25 #include <nw/gfx/gfx_Light.h>
26 #include <nw/gfx/gfx_FragmentLight.h>
27 #include <nw/gfx/gfx_AmbientLight.h>
28 #include <nw/gfx/gfx_VertexLight.h>
29 #include <nw/gfx/gfx_HemiSphereLight.h>
30 #include <nw/gfx/gfx_Fog.h>
31
32 using namespace nw::gfx;
33
34 namespace nw {
35 namespace anim {
36 namespace res {
37
38 //----------------------------------------
39 void
SetValueForType(void * object,const void * value) const40 ResAnimGroupMember::SetValueForType(void* object, const void* value) const
41 {
42 NW_NULL_ASSERT(object);
43 NW_NULL_ASSERT(value);
44
45 // ObjectTypeに対応する派生クラスに処理を委譲
46 switch(GetObjectType())
47 {
48 case OBJECT_TYPE_BONE:
49 ResStaticCast<ResBoneMember>(*this).SetValue(object, value);
50 break;
51
52 case OBJECT_TYPE_MATERIAL_COLOR:
53 ResStaticCast<ResMaterialColorMember>(*this).SetValue(object, value);
54 break;
55
56 case OBJECT_TYPE_TEXTURE_SAMPLER:
57 ResStaticCast<ResTextureSamplerMember>(*this).SetValue(object, value);
58 break;
59
60 case OBJECT_TYPE_TEXTURE_MAPPER:
61 ResStaticCast<ResTextureMapperMember>(*this).SetValue(object, value);
62 break;
63
64 case OBJECT_TYPE_BLEND_OPERATION:
65 ResStaticCast<ResBlendOperationMember>(*this).SetValue(object, value);
66 break;
67
68 case OBJECT_TYPE_TEXTURE_COORDINATOR:
69 ResStaticCast<ResTextureCoordinatorMember>(*this).SetValue(object, value);
70 break;
71
72 case OBJECT_TYPE_MODEL:
73 ResStaticCast<ResModelMember>(*this).SetValue(object, value);
74 break;
75
76 case OBJECT_TYPE_MESH:
77 ResStaticCast<ResMeshMember>(*this).SetValue(object, value);
78 break;
79
80 case OBJECT_TYPE_MESH_NODE_VISIBILITY:
81 ResStaticCast<ResMeshNodeVisibilityMember>(*this).SetValue(object, value);
82 break;
83
84 case OBJECT_TYPE_TRANSFORM:
85 ResStaticCast<ResTransformMember>(*this).SetValue(object, value);
86 break;
87
88 case OBJECT_TYPE_VIEW_UPDATER:
89 ResStaticCast<ResViewUpdaterMember>(*this).SetValue(object, value);
90 break;
91
92 case OBJECT_TYPE_PROJECTION_UPDATER:
93 ResStaticCast<ResProjectionUpdaterMember>(*this).SetValue(object, value);
94 break;
95
96 case OBJECT_TYPE_LIGHT:
97 ResStaticCast<ResLightMember>(*this).SetValue(object, value);
98 break;
99
100 case OBJECT_TYPE_FRAGMENT_LIGHT:
101 ResStaticCast<ResFragmentLightMember>(*this).SetValue(object, value);
102 break;
103
104 case OBJECT_TYPE_AMBIENT_LIGHT:
105 ResStaticCast<ResAmbientLightMember>(*this).SetValue(object, value);
106 break;
107
108 case OBJECT_TYPE_VERTEX_LIGHT:
109 ResStaticCast<ResVertexLightMember>(*this).SetValue(object, value);
110 break;
111
112 case OBJECT_TYPE_HEMISPHERE_LIGHT:
113 ResStaticCast<ResHemiSphereLightMember>(*this).SetValue(object, value);
114 break;
115
116 case OBJECT_TYPE_FOG:
117 ResStaticCast<ResFogMember>(*this).SetValue(object, value);
118 break;
119
120 default:
121 NW_ASSERT(false);
122 break;
123 }
124 }
125
126 //----------------------------------------
127 void
SetValue(void * object,const void * value) const128 ResBoneMember::SetValue(void* object, const void* value) const
129 {
130 CalculatedTransform* bone =
131 reinterpret_cast<CalculatedTransform*>(object);
132 const math::Transform3* transform =
133 reinterpret_cast<const math::Transform3*>(value);
134
135 bone->SetTransform(*transform);
136 bone->UpdateScaleFlags();
137 bone->UpdateRotateFlags();
138 bone->UpdateTranslateFlags();
139 bone->UpdateCompositeFlags();
140 }
141
142
143 //----------------------------------------
144 void
SetValue(void * object,const void * value) const145 ResMaterialColorMember::SetValue(void* object, const void* value) const
146 {
147 ResMaterialColor materialColor(object);
148 const ut::FloatColor& color = *reinterpret_cast<const ut::FloatColor*>(value);
149
150 // MemberTypeに対応するsetterを呼び出す
151 switch(GetMemberType())
152 {
153 case MEMBER_TYPE_EMISSION:
154 materialColor.SetEmission(color);
155 break;
156
157 case MEMBER_TYPE_AMBIENT:
158 materialColor.SetAmbient(color.r, color.g, color.b);
159 break;
160
161 case MEMBER_TYPE_DIFFUSE:
162 materialColor.SetDiffuse(color);
163 break;
164
165 case MEMBER_TYPE_SPECULAR0:
166 materialColor.SetSpecular0(color);
167 break;
168
169 case MEMBER_TYPE_SPECULAR1:
170 materialColor.SetSpecular1(color);
171 break;
172
173 case MEMBER_TYPE_CONSTANT0:
174 materialColor.SetConstant0(color);
175 break;
176
177 case MEMBER_TYPE_CONSTANT1:
178 materialColor.SetConstant1(color);
179 break;
180
181 case MEMBER_TYPE_CONSTANT2:
182 materialColor.SetConstant2(color);
183 break;
184
185 case MEMBER_TYPE_CONSTANT3:
186 materialColor.SetConstant3(color);
187 break;
188
189 case MEMBER_TYPE_CONSTANT4:
190 materialColor.SetConstant4(color);
191 break;
192
193 case MEMBER_TYPE_CONSTANT5:
194 materialColor.SetConstant5(color);
195 break;
196
197 default:
198 NW_ASSERT(false);
199 }
200 }
201
202 //----------------------------------------
203 void
SetValue(void * object,const void * value) const204 ResTextureSamplerMember::SetValue(void* object, const void* value) const
205 {
206 ResPixelBasedTextureMapper mapper(object);
207 const ut::FloatColor& color = *reinterpret_cast<const ut::FloatColor*>(value);
208
209 NW_NULL_ASSERT(ResDynamicCast<ResStandardTextureSampler>(mapper.GetSampler()).ptr());
210
211 // mapper.GetSampler()はconstなので、内部に直接アクセスする
212 ResStandardTextureSampler sampler(mapper.ref().toSampler.to_ptr());
213
214 switch(GetMemberType())
215 {
216 case MEMBER_TYPE_BORDER_COLOR:
217 sampler.SetBorderColor(color);
218 break;
219
220 default:
221 NW_ASSERT(false);
222 }
223 }
224
225 //----------------------------------------
226 void
SetValue(void * object,const void * value) const227 ResTextureMapperMember::SetValue(void* object, const void* value) const
228 {
229 ResPixelBasedTextureMapper mapper(object);
230 const ut::Offset& offset = *reinterpret_cast<const ut::Offset*>(value);
231
232 ResReferenceTexture texture(offset.to_ptr());
233
234 switch(GetMemberType())
235 {
236 case MEMBER_TYPE_TEXTURE:
237 mapper.SetTexture(texture.GetTargetTexture());
238 break;
239
240 default:
241 NW_ASSERT(false);
242 }
243 }
244
245 //----------------------------------------
246 void
SetValue(void * object,const void * value) const247 ResBlendOperationMember::SetValue(void* object, const void* value) const
248 {
249 ResBlendOperation operation(object);
250 const ut::FloatColor& color = *reinterpret_cast<const ut::FloatColor*>(value);
251
252 switch(GetMemberType())
253 {
254 case MEMBER_TYPE_BLEND_COLOR:
255 operation.SetBlendColor(color);
256 break;
257
258 default:
259 NW_ASSERT(false);
260 }
261 }
262
263 //----------------------------------------
264 void
SetValue(void * object,const void * value) const265 ResTextureCoordinatorMember::SetValue(void* object, const void* value) const
266 {
267 ResTextureCoordinator coordinator(object);
268
269 switch(GetMemberType())
270 {
271 case MEMBER_TYPE_SCALE:
272 {
273 const math::VEC2& scale = *reinterpret_cast<const math::VEC2*>(value);
274 coordinator.SetScale(scale);
275 }
276 break;
277
278 case MEMBER_TYPE_ROTATE:
279 {
280 float rotate = *reinterpret_cast<const float*>(value);
281 coordinator.SetRotate(rotate);
282 }
283 break;
284
285 case MEMBER_TYPE_TRANSLATE:
286 {
287 const math::VEC2& translate = *reinterpret_cast<const math::VEC2*>(value);
288 coordinator.SetTranslate(translate);
289 }
290 break;
291
292 default:
293 NW_ASSERT(false);
294 }
295
296 // Coordinator内で、値が変化した場合のみDirtyフラグを立てるようになっている。
297 // しかし、ここ以前に直接メモリに書き込んでいるので、
298 // 値が変化していないと判定されてしまう。そのため、明示的にフラグを立てる。
299 coordinator.SetDirty(true);
300 }
301
302 //----------------------------------------
303 void
SetValue(void * object,const void * value) const304 ResModelMember::SetValue(void* object, const void* value) const
305 {
306 Model* model = reinterpret_cast<Model*>(object);
307
308 switch(GetMemberType())
309 {
310 case MEMBER_TYPE_BRANCH_VISIBLE:
311 {
312 const bool visibility = *static_cast<const bool*>(value);
313 model->SetBranchVisible(visibility);
314 }
315 break;
316 case MEMBER_TYPE_VISIBLE:
317 {
318 const bool visibility = *static_cast<const bool*>(value);
319 model->SetVisible(visibility);
320 }
321 break;
322 default:
323 NW_ASSERT(false);
324 }
325 }
326
327 //----------------------------------------
328 void
SetValue(void * object,const void * value) const329 ResMeshMember::SetValue(void* object, const void* value) const
330 {
331 ResMesh mesh(object);
332
333 const bool visibility = *static_cast<const bool*>(value);
334 mesh.SetVisible(visibility);
335 }
336
337 //----------------------------------------
338 void
SetValue(void * object,const void * value) const339 ResMeshNodeVisibilityMember::SetValue(void* object, const void* value) const
340 {
341 ResMeshNodeVisibility nodeVisibility(object);
342
343 const bool visibility = *static_cast<const bool*>(value);
344 nodeVisibility.SetVisible(visibility);
345 }
346
347 //----------------------------------------
348 void
SetValue(void * object,const void * value) const349 ResTransformMember::SetValue(void* object, const void* value) const
350 {
351 TransformNode* transformNode = reinterpret_cast<TransformNode*>(object);
352
353 switch(GetMemberType())
354 {
355 case MEMBER_TYPE_TRANSFORM:
356 {
357 transformNode->Transform().SetTransform(*reinterpret_cast<const math::Transform3*>(value));
358 transformNode->Transform().EnableFlags(CalculatedTransform::FLAG_IS_DIRTY);
359 }
360 break;
361
362 default:
363 NW_ASSERT(false);
364 }
365 }
366
367 //----------------------------------------
368 void
SetValue(void * object,const void * value) const369 ResViewUpdaterMember::SetValue(void* object, const void* value) const
370 {
371 ResCameraViewUpdater viewUpdater(object);
372
373 switch(viewUpdater.GetTypeInfo())
374 {
375 case ResAimTargetViewUpdater::TYPE_INFO:
376 {
377 ResAimTargetViewUpdater aimUpdater(object);
378
379 switch(GetMemberType())
380 {
381 case MEMBER_TYPE_TARGET_POSITION:
382 {
383 const math::VEC3& position = *reinterpret_cast<const math::VEC3*>(value);
384 aimUpdater.SetTargetPosition(position);
385 }
386 break;
387
388 case MEMBER_TYPE_TWIST:
389 {
390 float twist = *reinterpret_cast<const float*>(value);
391 aimUpdater.SetTwist(twist);
392 }
393 break;
394
395 default:
396 NW_ASSERT(false);
397 }
398 }
399 break;
400
401 case ResLookAtTargetViewUpdater::TYPE_INFO:
402 {
403 ResLookAtTargetViewUpdater lookAtUpdater(object);
404
405 switch(GetMemberType())
406 {
407 case MEMBER_TYPE_TARGET_POSITION:
408 {
409 const math::VEC3& position = *reinterpret_cast<const math::VEC3*>(value);
410 lookAtUpdater.SetTargetPosition(position);
411 }
412 break;
413
414 case MEMBER_TYPE_UPWARD_VECTOR:
415 {
416 const math::VEC3& upVector = *reinterpret_cast<const math::VEC3*>(value);
417 lookAtUpdater.SetUpwardVector(upVector);
418 }
419 break;
420
421 default:
422 NW_ASSERT(false);
423 }
424 }
425 break;
426
427 case ResRotateViewUpdater::TYPE_INFO:
428 {
429 ResRotateViewUpdater rotateUpdater(object);
430
431 switch(GetMemberType())
432 {
433 case MEMBER_TYPE_VIEW_ROTATE:
434 {
435 const math::VEC3& rotate = *reinterpret_cast<const math::VEC3*>(value);
436 rotateUpdater.SetViewRotate(rotate);
437 }
438 break;
439
440 default:
441 NW_ASSERT(false);
442 }
443 }
444 break;
445
446 default:
447 NW_ASSERT(false);
448 }
449 }
450
451 //----------------------------------------
452 void
SetValue(void * object,const void * value) const453 ResProjectionUpdaterMember::SetValue(void* object, const void* value) const
454 {
455 ResCameraProjectionUpdater projectionUpdater(object);
456
457 switch(projectionUpdater.GetTypeInfo())
458 {
459 case ResPerspectiveProjectionUpdater::TYPE_INFO:
460 {
461 ResPerspectiveProjectionUpdater perspectiveUpdater(object);
462 float floatValue = *reinterpret_cast<const float*>(value);
463
464 switch(GetMemberType())
465 {
466 case MEMBER_TYPE_NEAR:
467 perspectiveUpdater.SetNear(floatValue);
468 break;
469
470 case MEMBER_TYPE_FAR:
471 perspectiveUpdater.SetFar(floatValue);
472 break;
473
474 case MEMBER_TYPE_FOVY:
475 perspectiveUpdater.SetFovy(floatValue);
476 break;
477
478 case MEMBER_TYPE_ASPECT_RATIO:
479 perspectiveUpdater.SetAspectRatio(floatValue);
480 break;
481
482 default:
483 NW_ASSERT(false);
484 }
485 }
486 break;
487
488 case ResOrthoProjectionUpdater::TYPE_INFO:
489 {
490 ResOrthoProjectionUpdater orthoUpdater(object);
491 float floatValue = *reinterpret_cast<const float*>(value);
492
493 switch(GetMemberType())
494 {
495 case MEMBER_TYPE_NEAR:
496 orthoUpdater.SetNear(floatValue);
497 break;
498
499 case MEMBER_TYPE_FAR:
500 orthoUpdater.SetFar(floatValue);
501 break;
502
503 case MEMBER_TYPE_ASPECT_RATIO:
504 {
505 ResProjectionRect rect = orthoUpdater.GetRect();
506 rect.Set(floatValue, rect.GetHeight(), rect.GetCenter());
507 orthoUpdater.SetRect(rect);
508 }
509 break;
510
511 case MEMBER_TYPE_HEIGHT:
512 {
513 ResProjectionRect rect = orthoUpdater.GetRect();
514 rect.Set(rect.GetAspectRatio(), floatValue, rect.GetCenter());
515 orthoUpdater.SetRect(rect);
516 }
517 break;
518
519 case MEMBER_TYPE_CENTER:
520 {
521 const math::VEC2& center = *reinterpret_cast<const math::VEC2*>(value);
522
523 ResProjectionRect rect = orthoUpdater.GetRect();
524 rect.Set(rect.GetAspectRatio(), rect.GetHeight(), center);
525 orthoUpdater.SetRect(rect);
526 }
527 break;
528
529 default:
530 NW_ASSERT(false);
531 }
532 }
533 break;
534
535 // ResFrustumProjectionUpdaterは、アニメーションを設定できない
536
537 default:
538 NW_ASSERT(false);
539 }
540 }
541
542 //----------------------------------------
543 void
SetValue(void * object,const void * value) const544 ResLightMember::SetValue(void* object, const void* value) const
545 {
546 ResLight light(object);
547 bool boolValue = *static_cast<const bool*>(value);
548
549 switch (GetMemberType())
550 {
551 case MEMBER_TYPE_IS_LIGHT_ENABLED:
552 light.SetLightEnabled(boolValue);
553 break;
554
555 default:
556 NW_ASSERT(false);
557 }
558 }
559
560 //----------------------------------------
561 void
SetValue(void * object,const void * value) const562 ResFragmentLightMember::SetValue(void* object, const void* value) const
563 {
564 ResFragmentLight light(object);
565 const ut::FloatColor& color = *reinterpret_cast<const ut::FloatColor*>(value);
566
567 switch (GetMemberType())
568 {
569 case MEMBER_TYPE_AMBIENT:
570 light.SetAmbient(color);
571 break;
572
573 case MEMBER_TYPE_DIFFUSE:
574 light.SetDiffuse(color);
575 break;
576
577 case MEMBER_TYPE_SPECULAR0:
578 light.SetSpecular0(color);
579 break;
580
581 case MEMBER_TYPE_SPECULAR1:
582 light.SetSpecular1(color);
583 break;
584
585 case MEMBER_TYPE_DIRECTION:
586 {
587 math::VEC3 direction = *reinterpret_cast<const math::VEC3*>(value);
588 direction.Normalize();
589 light.SetDirection(direction);
590 }
591 break;
592
593 case MEMBER_TYPE_DISTANCE_ATTENUATION_START:
594 {
595 float start = *reinterpret_cast<const float*>(value);
596 light.SetDistanceAttenuationStart(start);
597 }
598 break;
599
600 case MEMBER_TYPE_DISTANCE_ATTENUATION_END:
601 {
602 float end = *reinterpret_cast<const float*>(value);
603 light.SetDistanceAttenuationEnd(end);
604 }
605 break;
606
607 default:
608 NW_ASSERT(false);
609 }
610 }
611
612 //----------------------------------------
613 void
SetValue(void * object,const void * value) const614 ResAmbientLightMember::SetValue(void* object, const void* value) const
615 {
616 ResAmbientLight light(object);
617 const ut::FloatColor& color = *reinterpret_cast<const ut::FloatColor*>(value);
618
619 switch (GetMemberType())
620 {
621 case MEMBER_TYPE_AMBIENT:
622 light.SetAmbient(color);
623 break;
624
625 default:
626 NW_ASSERT(false);
627 }
628 }
629
630 //----------------------------------------
631 void
SetValue(void * object,const void * value) const632 ResVertexLightMember::SetValue(void* object, const void* value) const
633 {
634 ResVertexLight light(object);
635 const ut::FloatColor& color = *reinterpret_cast<const ut::FloatColor*>(value);
636 float floatValue = *static_cast<const float*>(value);
637
638 switch (GetMemberType())
639 {
640 case MEMBER_TYPE_AMBIENT:
641 light.SetAmbient(color);
642 break;
643
644 case MEMBER_TYPE_DIFFUSE:
645 light.SetDiffuse(color);
646 break;
647
648 case MEMBER_TYPE_DIRECTION:
649 {
650 math::VEC3 direction = *reinterpret_cast<const math::VEC3*>(value);
651 direction.Normalize();
652 light.SetDirection(direction);
653 }
654 break;
655
656 case MEMBER_TYPE_DISTANCE_ATTENUATION_CONSTANT:
657 {
658 math::VEC3 attenuation = light.GetDistanceAttenuation();
659 attenuation.x = floatValue;
660 light.SetDistanceAttenuation(attenuation);
661 }
662 break;
663
664 case MEMBER_TYPE_DISTANCE_ATTENUATION_LINEAR:
665 {
666 math::VEC3 attenuation = light.GetDistanceAttenuation();
667 attenuation.y = floatValue;
668 light.SetDistanceAttenuation(attenuation);
669 }
670 break;
671
672 case MEMBER_TYPE_DISTANCE_ATTENUATION_QUADRATIC:
673 {
674 math::VEC3 attenuation = light.GetDistanceAttenuation();
675 attenuation.z = floatValue;
676 light.SetDistanceAttenuation(attenuation);
677 }
678 break;
679
680 case MEMBER_TYPE_SPOT_EXPONENT:
681 {
682 math::VEC2 spotFactor = light.GetSpotFactor();
683 spotFactor.x = floatValue;
684 light.SetSpotFactor(spotFactor);
685 }
686 break;
687
688 case MEMBER_TYPE_SPOT_CUTOFF_ANGLE:
689 {
690 math::VEC2 spotFactor = light.GetSpotFactor();
691 spotFactor.y = floatValue;
692 light.SetSpotFactor(spotFactor);
693 }
694 break;
695
696 default:
697 NW_ASSERT(false);
698 }
699 }
700
701 //----------------------------------------
702 void
SetValue(void * object,const void * value) const703 ResHemiSphereLightMember::SetValue(void* object, const void* value) const
704 {
705 ResHemiSphereLight light(object);
706 const ut::FloatColor& color = *reinterpret_cast<const ut::FloatColor*>(value);
707
708 switch (GetMemberType())
709 {
710 case MEMBER_TYPE_GROUND_COLOR:
711 light.SetGroundColor(color);
712 break;
713
714 case MEMBER_TYPE_SKY_COLOR:
715 light.SetSkyColor(color);
716 break;
717
718 case MEMBER_TYPE_DIRECTION:
719 {
720 math::VEC3 direction = *reinterpret_cast<const math::VEC3*>(value);
721 direction.Normalize();
722 light.SetDirection(direction);
723 }
724 break;
725
726 case MEMBER_TYPE_LERP_FACTOR:
727 {
728 float floatValue = *static_cast<const float*>(value);
729 light.SetLerpFactor(floatValue);
730 }
731 break;
732
733 default:
734 NW_ASSERT(false);
735 }
736 }
737
738 //----------------------------------------
739 void
SetValue(void * object,const void * value) const740 ResFogMember::SetValue(void* object, const void* value) const
741 {
742 ResFog fog(object);
743
744 switch (GetMemberType())
745 {
746 case MEMBER_TYPE_COLOR:
747 {
748 const ut::FloatColor& color = *reinterpret_cast<const ut::FloatColor*>(value);
749 fog.SetColor(color);
750 }
751 break;
752
753 default:
754 NW_ASSERT(false);
755 }
756 }
757
758 } // namespace res
759 } // namespace anim
760 } // namespace nw
761