2 * Copyright(c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Runtime.InteropServices;
20 using System.ComponentModel;
22 using Tizen.NUI.Binding;
23 using Tizen.NUI.BaseComponents;
25 namespace Tizen.NUI.Scene3D
27 public partial class Model
29 internal Animation InternalGenerateMotionDataAnimation(MotionData motionData, int durationMilliSeconds)
31 if (motionData == null || motionData.MotionValues == null)
33 Tizen.Log.Error("NUI", $"MotionData was null\n");
37 Lazy<Animation> ret = new Lazy<Animation>(() => new Animation(durationMilliSeconds));
39 foreach (var indexValuePair in motionData.MotionValues)
41 var motionIndex = indexValuePair.Item1;
42 var motionValue = indexValuePair.Item2;
44 if (motionIndex == null || motionValue == null || motionValue.Type == MotionValue.ValueType.Invalid)
49 // TODO : Make we use ModelNode instead of Animatable. Currently, ModelNode have some problem.
50 if (motionIndex.ModelNodeId != null)
52 Animatable modelNode = null;
53 if (motionIndex.ModelNodeId.Type == PropertyKey.KeyType.String)
55 modelNode = FindChildAnimatableByName(motionIndex.ModelNodeId.StringKey);
57 else if (motionIndex.ModelNodeId.Type == PropertyKey.KeyType.Index)
59 // TODO : Not implement yet.
62 if (modelNode != null)
64 KeyFrames keyFrames = null;
65 if (motionValue.Type == MotionValue.ValueType.KeyFrames)
67 keyFrames = motionValue.KeyFramesValue;
69 else if (motionValue.Type == MotionValue.ValueType.Property)
71 // Generate stable keyframe animation here.
72 keyFrames = new KeyFrames();
73 keyFrames.Add(0.0f, motionValue.Value);
74 keyFrames.Add(1.0f, motionValue.Value);
77 if (keyFrames != null)
79 string animatedPropertyName = motionIndex.GetPropertyName(modelNode as ModelNode);
80 if (!string.IsNullOrEmpty(animatedPropertyName))
82 ret.Value.AnimateBetween(modelNode, animatedPropertyName, keyFrames);
89 if (motionIndex is BlendShapeIndex)
91 var blendShapeIndex = motionIndex as BlendShapeIndex;
92 if (blendShapeIndex.BlendShapeId?.Type == PropertyKey.KeyType.String)
94 // TODO : Not implement yet. (Set all blendshapes by string)
100 return ret.IsValueCreated ? ret.Value : null;
103 internal void InternalSetMotionData(MotionData motionData)
105 if (motionData == null || motionData.MotionValues == null)
107 Tizen.Log.Error("NUI", $"MotionData was null\n");
111 foreach (var indexValuePair in motionData.MotionValues)
113 var motionIndex = indexValuePair.Item1;
114 var motionValue = indexValuePair.Item2;
116 if (motionIndex == null || motionValue == null || motionValue.Type == MotionValue.ValueType.Invalid)
121 if (motionIndex.ModelNodeId != null)
123 // TODO : Make we use ModelNode instead of Animatable. Currently, ModelNode have some problem.
124 Animatable modelNode = null;
125 if (motionIndex.ModelNodeId.Type == PropertyKey.KeyType.String)
127 modelNode = FindChildAnimatableByName(motionIndex.ModelNodeId.StringKey);
129 else if (motionIndex.ModelNodeId.Type == PropertyKey.KeyType.Index)
131 // TODO : Not implement yet.
134 if (modelNode != null)
136 PropertyValue value = null;
137 if (motionValue.Type == MotionValue.ValueType.KeyFrames)
139 // TODO : Not implement yet.
141 else if (motionValue.Type == MotionValue.ValueType.Property)
143 value = motionValue.Value;
148 string propertyName = motionIndex.GetPropertyName(modelNode as ModelNode);
149 if (!string.IsNullOrEmpty(propertyName))
151 modelNode.SetProperty(propertyName, value);
158 if (motionIndex is BlendShapeIndex)
160 var blendShapeIndex = motionIndex as BlendShapeIndex;
161 if (blendShapeIndex.BlendShapeId?.Type == PropertyKey.KeyType.String)
163 // TODO : Not implement yet. (Set all blendshapes by string)