From: Eunki, Hong Date: Wed, 5 Jul 2023 07:26:59 +0000 (+0900) Subject: [NUI.Scene3D] Make MotionData use Native API, instead of C# X-Git-Tag: accepted/tizen/unified/20231205.024657~251 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8daef53db6c7f89634638b9ee689f3da75a088fc;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI.Scene3D] Make MotionData use Native API, instead of C# Since we allow to use MotionData feature in dali-side, let we use it. Now we can load motion data and blendshape animation from file asyncronously. Signed-off-by: Eunki, Hong --- diff --git a/src/Tizen.NUI.Scene3D/src/internal/Controls/Model.cs b/src/Tizen.NUI.Scene3D/src/internal/Controls/Model.cs deleted file mode 100755 index 2386593..0000000 --- a/src/Tizen.NUI.Scene3D/src/internal/Controls/Model.cs +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright(c) 2023 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -using System; -using System.Runtime.InteropServices; -using System.ComponentModel; -using Tizen.NUI; -using Tizen.NUI.Binding; -using Tizen.NUI.BaseComponents; - -namespace Tizen.NUI.Scene3D -{ - public partial class Model - { - internal Animation InternalGenerateMotionDataAnimation(MotionData motionData, int durationMilliSeconds) - { - if (motionData == null || motionData.MotionValues == null) - { - Tizen.Log.Error("NUI", $"MotionData was null\n"); - return null; - } - - Lazy ret = new Lazy(() => new Animation(durationMilliSeconds)); - - foreach (var indexValuePair in motionData.MotionValues) - { - var motionIndex = indexValuePair.Item1; - var motionValue = indexValuePair.Item2; - - if (motionIndex == null || motionValue == null || motionValue.Type == MotionValue.ValueType.Invalid) - { - continue; - } - - // TODO : Make we use ModelNode instead of Animatable. Currently, ModelNode have some problem. - if (motionIndex.ModelNodeId != null) - { - Animatable modelNode = null; - if (motionIndex.ModelNodeId.Type == PropertyKey.KeyType.String) - { - modelNode = FindChildAnimatableByName(motionIndex.ModelNodeId.StringKey); - } - else if (motionIndex.ModelNodeId.Type == PropertyKey.KeyType.Index) - { - // TODO : Not implement yet. - } - - if (modelNode != null) - { - KeyFrames keyFrames = null; - if (motionValue.Type == MotionValue.ValueType.KeyFrames) - { - keyFrames = motionValue.KeyFramesValue; - } - else if (motionValue.Type == MotionValue.ValueType.Property) - { - // Generate stable keyframe animation here. - keyFrames = new KeyFrames(); - keyFrames.Add(0.0f, motionValue.Value); - keyFrames.Add(1.0f, motionValue.Value); - } - - if (keyFrames != null) - { - string animatedPropertyName = motionIndex.GetPropertyName(modelNode as ModelNode); - if (!string.IsNullOrEmpty(animatedPropertyName)) - { - ret.Value.AnimateBetween(modelNode, animatedPropertyName, keyFrames); - } - } - } - } - else - { - if (motionIndex is BlendShapeIndex) - { - var blendShapeIndex = motionIndex as BlendShapeIndex; - if (blendShapeIndex.BlendShapeId?.Type == PropertyKey.KeyType.String) - { - // TODO : Not implement yet. (Set all blendshapes by string) - } - } - } - } - - return ret.IsValueCreated ? ret.Value : null; - } - - internal void InternalSetMotionData(MotionData motionData) - { - if (motionData == null || motionData.MotionValues == null) - { - Tizen.Log.Error("NUI", $"MotionData was null\n"); - return; - } - - foreach (var indexValuePair in motionData.MotionValues) - { - var motionIndex = indexValuePair.Item1; - var motionValue = indexValuePair.Item2; - - if (motionIndex == null || motionValue == null || motionValue.Type == MotionValue.ValueType.Invalid) - { - continue; - } - - if (motionIndex.ModelNodeId != null) - { - // TODO : Make we use ModelNode instead of Animatable. Currently, ModelNode have some problem. - Animatable modelNode = null; - if (motionIndex.ModelNodeId.Type == PropertyKey.KeyType.String) - { - modelNode = FindChildAnimatableByName(motionIndex.ModelNodeId.StringKey); - } - else if (motionIndex.ModelNodeId.Type == PropertyKey.KeyType.Index) - { - // TODO : Not implement yet. - } - - if (modelNode != null) - { - PropertyValue value = null; - if (motionValue.Type == MotionValue.ValueType.KeyFrames) - { - // TODO : Not implement yet. - } - else if (motionValue.Type == MotionValue.ValueType.Property) - { - value = motionValue.Value; - } - - if (value != null) - { - string propertyName = motionIndex.GetPropertyName(modelNode as ModelNode); - if (!string.IsNullOrEmpty(propertyName)) - { - modelNode.SetProperty(propertyName, value); - } - } - } - } - else - { - if (motionIndex is BlendShapeIndex) - { - var blendShapeIndex = motionIndex as BlendShapeIndex; - if (blendShapeIndex.BlendShapeId?.Type == PropertyKey.KeyType.String) - { - // TODO : Not implement yet. (Set all blendshapes by string) - } - } - } - } - } - } -} diff --git a/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.Model.cs b/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.Model.cs index 870e437..adf1bde 100755 --- a/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.Model.cs +++ b/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.Model.cs @@ -78,7 +78,7 @@ namespace Tizen.NUI.Scene3D [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_Model_GetCameraCount")] public static extern uint GetCameraCount(global::System.Runtime.InteropServices.HandleRef model); - + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_Model_GenerateCamera")] public static extern global::System.IntPtr GenerateCamera(global::System.Runtime.InteropServices.HandleRef model, uint index); @@ -89,6 +89,12 @@ namespace Tizen.NUI.Scene3D [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_Model_FindChildModelNodeByName")] public static extern global::System.IntPtr FindChildModelNodeByName(global::System.Runtime.InteropServices.HandleRef model, string nodeName); + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_Model_GenerateMotionDataAnimation")] + public static extern global::System.IntPtr GenerateMotionDataAnimation(global::System.Runtime.InteropServices.HandleRef model, global::System.Runtime.InteropServices.HandleRef motionData); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_Model_SetMotionData")] + public static extern void SetMotionData(global::System.Runtime.InteropServices.HandleRef model, global::System.Runtime.InteropServices.HandleRef motionData); + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_Model_LoadBvhAnimation_1")] public static extern global::System.IntPtr LoadBvhAnimation(global::System.Runtime.InteropServices.HandleRef model, string bvhFilename, global::System.Runtime.InteropServices.HandleRef scale, bool translateRootFromModelNode); diff --git a/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.MotionData.cs b/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.MotionData.cs new file mode 100755 index 0000000..6f8845b --- /dev/null +++ b/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.MotionData.cs @@ -0,0 +1,87 @@ +/* + * Copyright(c) 2023 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +namespace Tizen.NUI.Scene3D +{ + internal static partial class Interop + { + internal static partial class MotionData + { + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionData_New_SWIG_0")] + public static extern global::System.IntPtr MotionDataNew(); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionData_New_SWIG_1")] + public static extern global::System.IntPtr MotionDataNew(float duration); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_new_MotionData_SWIG_0")] + public static extern global::System.IntPtr NewMotionData(); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_new_MotionData_SWIG_1")] + public static extern global::System.IntPtr NewMotionData(global::System.Runtime.InteropServices.HandleRef motionData); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_delete_MotionData")] + public static extern void DeleteMotionData(global::System.Runtime.InteropServices.HandleRef motionData); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionData_Assign")] + public static extern global::System.IntPtr MotionDataAssign(global::System.Runtime.InteropServices.HandleRef motionData, global::System.Runtime.InteropServices.HandleRef sourceMotionData); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionData_DownCast")] + public static extern global::System.IntPtr MotionDataDownCast(global::System.Runtime.InteropServices.HandleRef motionData); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionData_GetMotionCount")] + public static extern uint GetMotionCount(global::System.Runtime.InteropServices.HandleRef motionData); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionData_GetIndex")] + public static extern global::System.IntPtr GetIndex(global::System.Runtime.InteropServices.HandleRef motionData, uint index); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionData_GetValue")] + public static extern global::System.IntPtr GetValue(global::System.Runtime.InteropServices.HandleRef motionData, uint index); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionData_Add")] + public static extern void Add(global::System.Runtime.InteropServices.HandleRef motionData, global::System.Runtime.InteropServices.HandleRef motionIndex, global::System.Runtime.InteropServices.HandleRef motionValue); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionData_Clear")] + public static extern void Clear(global::System.Runtime.InteropServices.HandleRef motionData); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionData_SetDuration")] + public static extern void SetDuration(global::System.Runtime.InteropServices.HandleRef motionData, float duration); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionData_GetDuration")] + public static extern float GetDuration(global::System.Runtime.InteropServices.HandleRef motionData); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionData_LoadBvh")] + public static extern float LoadMotionCaptureAnimation(global::System.Runtime.InteropServices.HandleRef motionData, string motionCaptureFilename, global::System.Runtime.InteropServices.HandleRef scale, bool synchronousLoad); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionData_LoadBvhFromBuffer")] + public static extern float LoadMotionCaptureAnimationFromBuffer(global::System.Runtime.InteropServices.HandleRef motionData, string motionCaptureBuffer, int motionCaptureBufferLength, global::System.Runtime.InteropServices.HandleRef scale, bool synchronousLoad); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionData_LoadFacialAnimation")] + public static extern float LoadBlendShapeAnimation(global::System.Runtime.InteropServices.HandleRef motionData, string blendShapeFilename, bool synchronousLoad); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionData_LoadFacialAnimationFromBuffer")] + public static extern float LoadBlendShapeAnimationFromBuffer(global::System.Runtime.InteropServices.HandleRef motionData, string blendShapeBuffer, int blendShapeBufferLength, bool synchronousLoad); + + // Signals + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionData_LoadCompletedSignal_Connect")] + public static extern void LoadCompletedConnect(global::System.Runtime.InteropServices.HandleRef motionData, global::System.Runtime.InteropServices.HandleRef handler); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionData_LoadCompletedSignal_Disconnect")] + public static extern void LoadCompletedDisconnect(global::System.Runtime.InteropServices.HandleRef motionData, global::System.Runtime.InteropServices.HandleRef handler); + } + } +} diff --git a/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.MotionIndex.cs b/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.MotionIndex.cs new file mode 100755 index 0000000..b0ae286 --- /dev/null +++ b/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.MotionIndex.cs @@ -0,0 +1,138 @@ +/* + * Copyright(c) 2023 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +namespace Tizen.NUI.Scene3D +{ + internal static partial class Interop + { + internal static partial class MotionIndex + { + #region MotionIndex + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_new_MotionIndex_SWIG_0")] + public static extern global::System.IntPtr NewMotionIndex(); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_new_MotionIndex_SWIG_1")] + public static extern global::System.IntPtr NewMotionIndex(global::System.Runtime.InteropServices.HandleRef motionIndex); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_delete_MotionIndex")] + public static extern void DeleteMotionIndex(global::System.Runtime.InteropServices.HandleRef motionIndex); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionIndex_Assign")] + public static extern global::System.IntPtr MotionIndexAssign(global::System.Runtime.InteropServices.HandleRef motionIndex, global::System.Runtime.InteropServices.HandleRef sourceMotionIndex); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionIndex_DownCast")] + public static extern global::System.IntPtr MotionIndexDownCast(global::System.Runtime.InteropServices.HandleRef motionIndex); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionIndex_SetModelNodeId")] + public static extern void SetModelNodeId(global::System.Runtime.InteropServices.HandleRef motionIndex, global::System.Runtime.InteropServices.HandleRef modelNodeId); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionIndex_GetModelNodeId")] + public static extern global::System.IntPtr GetModelNodeId(global::System.Runtime.InteropServices.HandleRef motionIndex); + #endregion + + #region BlendShapeIndex + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_BlendShapeIndex_New_SWIG_0")] + public static extern global::System.IntPtr BlendShapeIndexNew(); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_BlendShapeIndex_New_SWIG_1")] + public static extern global::System.IntPtr BlendShapeIndexNew(global::System.Runtime.InteropServices.HandleRef blendShapePropertyKey); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_BlendShapeIndex_New_SWIG_2")] + public static extern global::System.IntPtr BlendShapeIndexNew(global::System.Runtime.InteropServices.HandleRef modelNodePropertKey, global::System.Runtime.InteropServices.HandleRef blendShapePropertyKey); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_new_BlendShapeIndex_SWIG_0")] + public static extern global::System.IntPtr NewBlendShapeIndex(); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_new_BlendShapeIndex_SWIG_1")] + public static extern global::System.IntPtr NewBlendShapeIndex(global::System.Runtime.InteropServices.HandleRef blendShapeIndex); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_delete_BlendShapeIndex")] + public static extern void DeleteBlendShapeIndex(global::System.Runtime.InteropServices.HandleRef blendShapeIndex); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_BlendShapeIndex_Assign")] + public static extern global::System.IntPtr BlendShapeIndexAssign(global::System.Runtime.InteropServices.HandleRef blendShapeIndex, global::System.Runtime.InteropServices.HandleRef sourceBlendShapeIndex); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_BlendShapeIndex_DownCast")] + public static extern global::System.IntPtr BlendShapeIndexDownCast(global::System.Runtime.InteropServices.HandleRef blendShapeIndex); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_BlendShapeIndex_SetBlendShapeId")] + public static extern void SetBlendShapeId(global::System.Runtime.InteropServices.HandleRef blendShapeIndex, global::System.Runtime.InteropServices.HandleRef modelNodeId); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_BlendShapeIndex_GetBlendShapeId")] + public static extern global::System.IntPtr GetBlendShapeId(global::System.Runtime.InteropServices.HandleRef blendShapeIndex); + #endregion + + #region MotionPropertyIndex + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionPropertyIndex_New_SWIG_0")] + public static extern global::System.IntPtr MotionPropertyIndexNew(); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionPropertyIndex_New_SWIG_1")] + public static extern global::System.IntPtr MotionPropertyIndexNew(global::System.Runtime.InteropServices.HandleRef modelNodePropertKey, global::System.Runtime.InteropServices.HandleRef propertyKey); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_new_MotionPropertyIndex_SWIG_0")] + public static extern global::System.IntPtr NewMotionPropertyIndex(); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_new_MotionPropertyIndex_SWIG_1")] + public static extern global::System.IntPtr NewMotionPropertyIndex(global::System.Runtime.InteropServices.HandleRef motionPropertyIndex); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_delete_MotionPropertyIndex")] + public static extern void DeleteMotionPropertyIndex(global::System.Runtime.InteropServices.HandleRef motionPropertyIndex); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionPropertyIndex_Assign")] + public static extern global::System.IntPtr MotionPropertyIndexAssign(global::System.Runtime.InteropServices.HandleRef motionPropertyIndex, global::System.Runtime.InteropServices.HandleRef sourceMotionPropertyIndex); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionTransformIndex_DownCast")] + public static extern global::System.IntPtr MotionPropertyIndexDownCast(global::System.Runtime.InteropServices.HandleRef motionPropertyIndex); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionTransformIndex_SetTransformType")] + public static extern void SetPropertyId(global::System.Runtime.InteropServices.HandleRef motionPropertyIndex, global::System.Runtime.InteropServices.HandleRef propertyKey); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionTransformIndex_GetTransformType")] + public static extern global::System.IntPtr GetPropertyId(global::System.Runtime.InteropServices.HandleRef motionPropertyIndex); + #endregion + + #region MotionTransformIndex + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionTransformIndex_New_SWIG_0")] + public static extern global::System.IntPtr MotionTransformIndexNew(); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionTransformIndex_New_SWIG_1")] + public static extern global::System.IntPtr MotionTransformIndexNew(global::System.Runtime.InteropServices.HandleRef modelNodePropertKey, int transformType); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_new_MotionTransformIndex_SWIG_0")] + public static extern global::System.IntPtr NewMotionTransformIndex(); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_new_MotionTransformIndex_SWIG_1")] + public static extern global::System.IntPtr NewMotionTransformIndex(global::System.Runtime.InteropServices.HandleRef motionTransformIndex); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_delete_MotionTransformIndex")] + public static extern void DeleteMotionTransformIndex(global::System.Runtime.InteropServices.HandleRef motionTransformIndex); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionTransformIndex_Assign")] + public static extern global::System.IntPtr MotionTransformIndexAssign(global::System.Runtime.InteropServices.HandleRef motionTransformIndex, global::System.Runtime.InteropServices.HandleRef sourceMotionTransformIndex); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionTransformIndex_DownCast")] + public static extern global::System.IntPtr MotionTransformIndexDownCast(global::System.Runtime.InteropServices.HandleRef motionTransformIndex); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionTransformIndex_SetTransformType")] + public static extern void SetTransformType(global::System.Runtime.InteropServices.HandleRef motionTransformIndex, int transformType); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionTransformIndex_GetTransformType")] + public static extern int GetTransformType(global::System.Runtime.InteropServices.HandleRef motionTransformIndex); + #endregion + } + } +} diff --git a/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.MotionValue.cs b/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.MotionValue.cs new file mode 100755 index 0000000..c740250 --- /dev/null +++ b/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.MotionValue.cs @@ -0,0 +1,67 @@ +/* + * Copyright(c) 2023 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +namespace Tizen.NUI.Scene3D +{ + internal static partial class Interop + { + internal static partial class MotionValue + { + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionValue_New_SWIG_0")] + public static extern global::System.IntPtr MotionValueNew(); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionValue_New_SWIG_1")] + public static extern global::System.IntPtr MotionValueNewPropertyValue(global::System.Runtime.InteropServices.HandleRef propertyValue); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionValue_New_SWIG_2")] + public static extern global::System.IntPtr MotionValueNewKeyFrames(global::System.Runtime.InteropServices.HandleRef keyFrames); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_new_MotionValue_SWIG_0")] + public static extern global::System.IntPtr NewMotionValue(); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_new_MotionValue_SWIG_1")] + public static extern global::System.IntPtr NewMotionValue(global::System.Runtime.InteropServices.HandleRef motionValue); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_delete_MotionValue")] + public static extern void DeleteMotionValue(global::System.Runtime.InteropServices.HandleRef motionValue); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionValue_Assign")] + public static extern global::System.IntPtr MotionValueAssign(global::System.Runtime.InteropServices.HandleRef motionValue, global::System.Runtime.InteropServices.HandleRef sourceMotionValue); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionValue_DownCast")] + public static extern global::System.IntPtr MotionValueDownCast(global::System.Runtime.InteropServices.HandleRef motionValue); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionValue_GetValueType")] + public static extern int GetValueType(global::System.Runtime.InteropServices.HandleRef motionValue); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionValue_SetValue_PropertyValue")] + public static extern void SetValuePropertyValue(global::System.Runtime.InteropServices.HandleRef motionValue, global::System.Runtime.InteropServices.HandleRef propertyValue); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionValue_SetValue_KeyFrames")] + public static extern void SetValueKeyFrames(global::System.Runtime.InteropServices.HandleRef motionValue, global::System.Runtime.InteropServices.HandleRef keyFrames); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionValue_Clear")] + public static extern void Clear(global::System.Runtime.InteropServices.HandleRef motionValue); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionValue_GetPropertyValue")] + public static extern global::System.IntPtr GetPropertyValue(global::System.Runtime.InteropServices.HandleRef motionValue); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_MotionValue_GetKeyFrames")] + public static extern global::System.IntPtr GetKeyFrames(global::System.Runtime.InteropServices.HandleRef motionValue); + } + } +} diff --git a/src/Tizen.NUI.Scene3D/src/public/Controls/Model.cs b/src/Tizen.NUI.Scene3D/src/public/Controls/Model.cs index 5c21300..b3aff77 100755 --- a/src/Tizen.NUI.Scene3D/src/public/Controls/Model.cs +++ b/src/Tizen.NUI.Scene3D/src/public/Controls/Model.cs @@ -373,6 +373,7 @@ namespace Tizen.NUI.Scene3D /// Animaion of bvh // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("Do not use this LoadBvhAnimation. Use MotionData.LoadMotionCaptureAnimation and GenerateMotionDataAnimation instead.")] public Animation LoadBvhAnimation(string bvhFilename, Vector3 scale = null, bool translateRootFromModelNode = true) { global::System.IntPtr cPtr = Interop.Model.LoadBvhAnimation(SwigCPtr, bvhFilename, Vector3.getCPtr(scale), translateRootFromModelNode); @@ -405,6 +406,7 @@ namespace Tizen.NUI.Scene3D /// Animaion of bvh // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("Do not use this LoadBvhAnimationFromBuffer. Use MotionData.LoadMotionCaptureAnimationFromBuffer and GenerateMotionDataAnimation instead.")] public Animation LoadBvhAnimationFromBuffer(string bvhBuffer, Vector3 scale = null, bool translateRootFromModelNode = true) { global::System.IntPtr cPtr = Interop.Model.LoadBvhAnimationFromBuffer(SwigCPtr, bvhBuffer, bvhBuffer.Length, Vector3.getCPtr(scale), translateRootFromModelNode); @@ -432,7 +434,7 @@ namespace Tizen.NUI.Scene3D /// Animaion of facial // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("Do not use this LoadFacialAnimation. Use LoadBlendShapeAnimation instead.")] + [Obsolete("Do not use this LoadFacialAnimation. Use MotionData.LoadBlendShapeAnimation and GenerateMotionDataAnimation instead.")] public Animation LoadFacialAnimation(string facialFilename) { return LoadBlendShapeAnimation(facialFilename); @@ -445,7 +447,7 @@ namespace Tizen.NUI.Scene3D /// Animaion of facial // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("Do not use this LoadFacialAnimationFromBuffer. Use LoadBlendShapeAnimationFromBuffer instead.")] + [Obsolete("Do not use this LoadFacialAnimationFromBuffer. Use MotionData.LoadBlendShapeAnimationFromBuffer and GenerateMotionDataAnimation instead.")] public Animation LoadFacialAnimationFromBuffer(string facialBuffer) { return LoadBlendShapeAnimationFromBuffer(facialBuffer); @@ -458,6 +460,7 @@ namespace Tizen.NUI.Scene3D /// Animaion of facial // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("Do not use this LoadBlendShapeAnimation. Use MotionData.LoadBlendShapeAnimation and GenerateMotionDataAnimation instead.")] public Animation LoadBlendShapeAnimation(string jsonFilename) { global::System.IntPtr cPtr = Interop.Model.LoadBlendShapeAnimation(SwigCPtr, jsonFilename); @@ -485,6 +488,7 @@ namespace Tizen.NUI.Scene3D /// Animaion of facial // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("Do not use this LoadBlendShapeAnimationFromBuffer. Use MotionData.LoadBlendShapeAnimationFromBuffer and GenerateMotionDataAnimation instead.")] public Animation LoadBlendShapeAnimationFromBuffer(string jsonBuffer) { global::System.IntPtr cPtr = Interop.Model.LoadBlendShapeAnimationFromBuffer(SwigCPtr, jsonBuffer, jsonBuffer.Length); @@ -506,29 +510,53 @@ namespace Tizen.NUI.Scene3D } /// - /// Prototype of animation generate by MotionData + /// Generate animation by MotionData. + /// If there is no animatable item for MotionData, return null. /// - /// Inputed list of pair of MotionIndex and MotionValue. - /// The duration in milliseconds. - /// Generated animation by input motion data + /// Inputed list of pair of MotionIndex and MotionValue, and duration. + /// Generated animation by input motion data, or null if there is no animatable item exist about inputed motionData // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] - public Animation GenerateMotionDataAnimation(MotionData motionData, int durationMilliSeconds) + public Animation GenerateMotionDataAnimation(MotionData motionData) { - return InternalGenerateMotionDataAnimation(motionData, durationMilliSeconds); + global::System.IntPtr cPtr = Interop.Model.GenerateMotionDataAnimation(SwigCPtr, MotionData.getCPtr(motionData)); + Animation ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animation; + if (ret == null) + { + // Register new animation into Registry. + ret = new Animation(cPtr, true); + } + else + { + // We found matched NUI animation. Reduce cPtr reference count. + HandleRef handle = new HandleRef(this, cPtr); + Tizen.NUI.Interop.Animation.DeleteAnimation(handle); + handle = new HandleRef(null, IntPtr.Zero); + } + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + + // It is possible if there is no animatable properties exist on inputed motionData. + // In this case, let we return null. + if (!ret.HasBody()) + { + ret.Dispose(); + ret = null; + } + return ret; } /// /// Prototype of MotionData setter. /// Note that this API didn't apply KeyFrames animation. - /// If you want to apply the animation, please use and play the result. + /// If you want to apply the animation, please use and play the result. /// /// Inputed list of pair of MotionIndex and MotionValue. // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] public void SetMotionData(MotionData motionData) { - InternalSetMotionData(motionData); + Interop.Model.SetMotionData(SwigCPtr, MotionData.getCPtr(motionData)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// diff --git a/src/Tizen.NUI.Scene3D/src/public/ModelMotion/BlendShapeIndex.cs b/src/Tizen.NUI.Scene3D/src/public/ModelMotion/BlendShapeIndex.cs deleted file mode 100644 index 88c7d73..0000000 --- a/src/Tizen.NUI.Scene3D/src/public/ModelMotion/BlendShapeIndex.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System.Numerics; -/* - * Copyright(c) 2023 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -using System; -using System.ComponentModel; -using System.Collections.Generic; -using Tizen.NUI; - -namespace Tizen.NUI.Scene3D -{ - /// - /// Index of BlendShape feature. - /// MotionValue should be float type. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public class BlendShapeIndex : MotionIndex - { - /// - /// Create an initialized motion index. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public BlendShapeIndex() - { - } - - /// - /// The key of BlendShape. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public PropertyKey BlendShapeId { get; set; } = null; - - /// - /// Convert from index to DALi engine using blend shape uniform name. - /// - internal static string GetPropertyNameFromIndex(int index) - { - if (index >= 0) - { - return "uBlendShapeWeight[" + index.ToString() + "]"; - } - return null; - } - - /// - /// Get uniform name of blendshape. - /// - internal override string GetPropertyName(ModelNode node) - { - if (BlendShapeId != null) - { - if (BlendShapeId.Type == PropertyKey.KeyType.Index) - { - return GetPropertyNameFromIndex(BlendShapeId.IndexKey); - } - if (node != null) - { - // TODO : Not implement yet. We should make API that get the blendshape index from node by name. - } - } - return null; - } - } -} diff --git a/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionData.cs b/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionData.cs index 6651291..6769d07 100644 --- a/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionData.cs +++ b/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionData.cs @@ -16,109 +16,397 @@ */ using System; +using System.Runtime.InteropServices; using System.ComponentModel; using System.Collections.Generic; namespace Tizen.NUI.Scene3D { /// - /// List of each motion value. + /// List of model motion definitions. + /// Each motion has pair of and . + /// MotionIndex is abstract class that specify the target of motion. + /// MotionValue is target value of motion. It can be KeyFrames. + /// + /// We can generate list of motions by MotionIndex and MotionValue classes. + /// + /// + /// MotionData motionData = new MotionData(3.0f); + /// + /// // Make MotionIndex with MotionPropertyIndex + /// // Make MotionValue with PropertyValue + /// motionData.Add(new MotionPropertyIndex(new PropertyKey("nodeName"), new PropertyKey("color")), new MotionValue(new PropertyValue(Color.Red))); + /// + /// // Make MotionIndex with MotionTransformIndex + /// // Make MotionValue with Dali::KeyFrames + /// KeyFrames keyFrames = new KeyFrames(); + /// keyFrames.Add(0.0f, 0.0f); + /// keyFrames.Add(0.0f, 1.0f); + /// motionData.Add(new MotionTransformIndex(new PropertyKey("nodeName"), MotionTransformIndex.TransformType.PositionX), new MotionValue(keyFrames)); + /// + /// // Make MotionIndex with BlendShapeIndex + /// motionData.Add(new BlendShapeIndex(new PropertyKey("nodeName"), new PropertyKey("blendShapeName")), motionData.GetValue(1u)); + /// + /// + /// We can request to load MotionData from file or buffer asynchronously. + /// If load completed, event will be invoked. + /// If we try to load before LoadCompleted event invoked, previous load request cancel and only latest request loaded. + /// + /// + /// MotionData motionData = new MotionData(); + /// motionData.LoadCompleted += OnLoadCompleted; + /// motionData.LoadBvh("bvhFilename.bvh", Vector3.One); + /// + /// ... + /// + /// void OnLoadCompleted(object o, event e) + /// { + /// MotionData motionData = o as MotionData; + /// /// Do something. + /// } + /// + /// + /// We can generate animation of Scene3D.Model from MotionData class. + /// Or, just set values. + /// + /// + /// // Generate animation from loaded Model + /// Animation animation = model.GenerateMotionDataAnimation(motionData); + /// animation.Play(); + /// + /// // Set values from loaded Model. + /// model2.SetMotionData(motionData); + /// /// /// + /// We don't check duplicated MotionIndex internally. /// We don't check MotionValue type is matched with MotionIndex. /// [EditorBrowsable(EditorBrowsableState.Never)] - public class MotionData : IDisposable + public class MotionData : BaseHandle { - private List<(MotionIndex, MotionValue)> motionValues { get; set; } = null; + private EventHandler loadCompletedEventHandler; + private LoadCompletedCallbackType loadCompletedCallback; + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void LoadCompletedCallbackType(IntPtr motionData); /// - /// Owned motion value list. + /// Create an initialized motion data. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public MotionData() : this(Interop.MotionData.MotionDataNew(), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Create an initialized motion data with duration. + /// + /// Duration of this motion data when it be generated as Animation in milliseconds. + [EditorBrowsable(EditorBrowsableState.Never)] + public MotionData(int durationMilliSeconds) : this(Interop.MotionData.MotionDataNew(MilliSecondsToSeconds(durationMilliSeconds)), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Copy constructor. + /// + /// Source object to copy. + [EditorBrowsable(EditorBrowsableState.Never)] + public MotionData(MotionData motionData) : this(Interop.MotionData.NewMotionData(MotionData.getCPtr(motionData)), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Assignment operator. + /// + /// Source object to be assigned. + /// Reference to this. + internal MotionData Assign(MotionData motionData) + { + MotionData ret = new MotionData(Interop.MotionData.MotionDataAssign(SwigCPtr, MotionData.getCPtr(motionData)), false); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + internal MotionData(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) + { + } + + /// + /// Get or set the duration of this motion data in milliseconds. /// [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("Do not use this MotionValues property directly. Use Add and GetIndex, GetValue instead.")] - public List<(MotionIndex, MotionValue)> MotionValues + public int Duration { get { - return motionValues; + return SecondsToMilliSeconds(GetDuration()); } set { - motionValues = value; + SetDuration(MilliSecondsToSeconds(value)); } } /// + /// Get the number of MotionIndex / MotionValue pair list what this hold. + /// + /// The number of motions what this hold. + [EditorBrowsable(EditorBrowsableState.Never)] + public uint GetMotionCount() + { + uint ret = Interop.MotionData.GetMotionCount(SwigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + /// /// Append pair of MotionIndex and MotionValue end of list. /// + /// MotionIndex to be added + /// MotionValue to be added [EditorBrowsable(EditorBrowsableState.Never)] public void Add(MotionIndex index, MotionValue value) { - if(motionValues == null) - { - motionValues = new List<(MotionIndex, MotionValue)>(); - } - motionValues.Add((index, value)); + Interop.MotionData.Add(SwigCPtr, MotionIndex.getCPtr(index), MotionValue.getCPtr(value)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Get MotionIndex at index'th. null if invalid index inputed /// + /// The index of motion data list + /// The index'th MotionIndex. Or empty handle that doesn't have body [EditorBrowsable(EditorBrowsableState.Never)] public MotionIndex GetIndex(uint index) { - if(motionValues != null && index < motionValues.Count) + IntPtr cPtr = Interop.MotionData.GetIndex(SwigCPtr, index); + MotionIndex ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as MotionIndex; + if (ret == null) + { + // Register new animation into Registry. + ret = new MotionIndex(cPtr, true); + } + else { - return motionValues[(int)index].Item1; + // We found matched NUI animation. Reduce cPtr reference count. + HandleRef handle = new HandleRef(this, cPtr); + Interop.MotionIndex.DeleteMotionIndex(handle); + handle = new HandleRef(null, IntPtr.Zero); } - return null; + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; } /// /// Get MotionValue at index'th. null if invalid index inputed /// + /// The index of motion data list + /// The index'th MotionValue. Or empty handle that doesn't have body [EditorBrowsable(EditorBrowsableState.Never)] public MotionValue GetValue(uint index) { - if(motionValues != null && index < motionValues.Count) + IntPtr cPtr = Interop.MotionData.GetValue(SwigCPtr, index); + MotionValue ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as MotionValue; + if (ret == null) { - return motionValues[(int)index].Item2; + // Register new animation into Registry. + ret = new MotionValue(cPtr, true); } - return null; + else + { + // We found matched NUI animation. Reduce cPtr reference count. + HandleRef handle = new HandleRef(this, cPtr); + Interop.MotionValue.DeleteMotionValue(handle); + handle = new HandleRef(null, IntPtr.Zero); + } + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; } /// - /// Clear all inputed values. + /// Load motion capture animation. + /// Scale is additional scale factor of motion capture animation. It is possible that + /// Model's scale may not matched with motion capture animation scale. + /// If scale is null, default use as Vector3.ONE + /// We support bvh format. + /// After load completed, event will be invoked. /// + /// Name of motion capture format file. + /// Scale value of motion capture animation match with model. + /// Load synchronously or not. Default is async load. + // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] - public void Clear() + public void LoadMotionCaptureAnimation(string motionCaptureFilename, Vector3 scale = null, bool synchronousLoad = false) { - motionValues = null; + Interop.MotionData.LoadMotionCaptureAnimation(SwigCPtr, motionCaptureFilename, Vector3.getCPtr(scale), synchronousLoad); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// - /// Create an initialized motion data. + /// Load motion capture animation. + /// Scale is additional scale factor of motion capture animation. It is possible that + /// Model's scale may not matched with motion capture animation scale. + /// If scale is null, default use as Vector3.ONE + /// We support bvh format. + /// After load completed, event will be invoked. /// - public MotionData() + /// Contents of motion capture format file. + /// Scale value of motion capture animation match with model. + /// Load synchronously or not. Default is async load. + // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) + [EditorBrowsable(EditorBrowsableState.Never)] + public void LoadMotionCaptureAnimationFromBuffer(string motionCaptureBuffer, Vector3 scale = null, bool synchronousLoad = false) { + Interop.MotionData.LoadMotionCaptureAnimationFromBuffer(SwigCPtr, motionCaptureBuffer, motionCaptureBuffer.Length, Vector3.getCPtr(scale), synchronousLoad); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// - /// IDisposable.Dipsose. + /// Load blendshape animation from json file. + /// After load completed, event will be invoked. /// + /// Name of json format file what we predefined. + /// Load synchronously or not. Default is async load. + // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] - public void Dispose() + public void LoadBlendShapeAnimation(string blendShapeFilename, bool synchronousLoad = false) { - if (motionValues != null) + Interop.MotionData.LoadBlendShapeAnimation(SwigCPtr, blendShapeFilename, synchronousLoad); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Load morphing animation from json string. + /// After load completed, event will be invoked. + /// + /// Contents of json format file what we predefined. + /// Load synchronously or not. Default is async load. + // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) + [EditorBrowsable(EditorBrowsableState.Never)] + public void LoadBlendShapeAnimationFromBuffer(string blendShapeBuffer, bool synchronousLoad = false) + { + Interop.MotionData.LoadBlendShapeAnimationFromBuffer(SwigCPtr, blendShapeBuffer, blendShapeBuffer.Length, synchronousLoad); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// LoadCompleted event. + /// It will be invoked only for latest load request. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler LoadCompleted + { + add { - foreach (var indexValuePair in motionValues) + if (loadCompletedEventHandler == null) { - indexValuePair.Item1?.Dispose(); - indexValuePair.Item2?.Dispose(); + loadCompletedCallback = OnLoadCompleted; + Interop.MotionData.LoadCompletedConnect(SwigCPtr, loadCompletedCallback.ToHandleRef(this)); + NDalicPINVOKE.ThrowExceptionIfExists(); } - motionValues = null; + loadCompletedEventHandler += value; + } + remove + { + loadCompletedEventHandler -= value; + if (loadCompletedEventHandler == null && loadCompletedCallback != null) + { + Interop.MotionData.LoadCompletedDisconnect(SwigCPtr, loadCompletedCallback.ToHandleRef(this)); + NDalicPINVOKE.ThrowExceptionIfExists(); + loadCompletedCallback = null; + } + } + } + + private void OnLoadCompleted(IntPtr motionData) + { + if (loadCompletedEventHandler != null) + { + loadCompletedEventHandler(this, null); } } + + /// + /// Clear all inputed values. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public void Clear() + { + Interop.MotionData.Clear(SwigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + internal void SetDuration(float durationSeconds) + { + Interop.MotionData.SetDuration(SwigCPtr, durationSeconds); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + internal float GetDuration() + { + float ret = Interop.MotionData.GetDuration(SwigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + private static float MilliSecondsToSeconds(int millisec) + { + return (float)millisec / 1000.0f; + } + + private static int SecondsToMilliSeconds(float sec) + { + return (int)(sec * 1000); + } + + /// + /// you can override it to clean-up your own resources. + /// + /// DisposeTypes + // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) + [EditorBrowsable(EditorBrowsableState.Never)] + protected override void Dispose(DisposeTypes type) + { + if (disposed) + { + return; + } + + if (type == DisposeTypes.Explicit) + { + //Called by User + //Release your own managed resources here. + //You should release all of your own disposable objects here. + } + + //Release your own unmanaged resources here. + //You should not access any managed member here except static instance. + //because the execution order of Finalizes is non-deterministic. + + if (loadCompletedCallback != null) + { + NUILog.Debug($"[Dispose] loadCompletedCallback"); + + Interop.MotionData.LoadCompletedDisconnect(SwigCPtr, loadCompletedCallback.ToHandleRef(this)); + NDalicPINVOKE.ThrowExceptionIfExists(); + loadCompletedCallback = null; + } + + base.Dispose(type); + } + + /// + /// Release swigCPtr. + /// + // This will be public opened. + [EditorBrowsable(EditorBrowsableState.Never)] + protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr) + { + Interop.MotionData.DeleteMotionData(swigCPtr); + } } } diff --git a/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionIndex.cs b/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionIndex.cs deleted file mode 100644 index 9bcbf5a..0000000 --- a/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionIndex.cs +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright(c) 2023 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -using System; -using System.ComponentModel; -using System.Collections.Generic; -using Tizen.NUI; - -namespace Tizen.NUI.Scene3D -{ - /// - /// Index of motion value. It will be used to specify the target of motion applied. - /// - /// There are two kinds of MotionIndex : MotionTransformIndex and BlendShapeIndex. - /// MotionTransformIndex will be used for control the ModelNode's Position / Orientation / Scale, or each components. - /// BlendShapeIndex will be used for control some blendshape animation. - /// - /// We can use this class below cases - /// - ModelNodeId (string key) , MotionTransformIndex : Target is ModelNode's transform property - /// - ModelNodeId (int key) , MotionTransformIndex : Target is ModelNode's transform property [not implemented yet] - /// - ModelNodeId (string key) , BlendShapeIndex (int key) : Target is ModelNode's BlendShape - /// - ModelNodeId (string key) , BlendShapeIndex (string key) : Target is ModelNode's BlendShape [not implemented yet] - /// - ModelNodeId (int key) , BlendShapeIndex (int key) : Target is ModelNode's BlendShape [not implemented yet] - /// - ModelNodeId (int key) , BlendShapeIndex (string key) : Target is ModelNode's BlendShape [not implemented yet] - /// - ModelNodeId (null) , BlendShapeIndex (string key) : Target is all BlendShape [not implemented yet] - /// All other cases are invalid. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public abstract class MotionIndex : IDisposable - { - /// - /// The id of ModelNode. If you want to apply to all ModelNodes who has BlendShape string, let this value as null. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public PropertyKey ModelNodeId { get; set; } = null; - - /// - /// Abstract API to get uniform name of index, or null if invalid. Only can be used for internal API - /// - abstract internal string GetPropertyName(ModelNode node); - - /// - /// IDisposable.Dipsose. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public void Dispose() - { - ModelNodeId?.Dispose(); - ModelNodeId = null; - } - } -} diff --git a/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionIndex/BlendShapeIndex.cs b/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionIndex/BlendShapeIndex.cs new file mode 100644 index 0000000..de59586 --- /dev/null +++ b/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionIndex/BlendShapeIndex.cs @@ -0,0 +1,150 @@ +/* + * Copyright(c) 2023 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +using System; +using System.ComponentModel; +using System.Collections.Generic; +using Tizen.NUI; + +namespace Tizen.NUI.Scene3D +{ + /// + /// Specialized to control blend shape. + /// We can control the blend shape by index (when we set BlendShapeId as IndexKey), + /// or by name (when we set BlendShapeId as StringKey). + /// + /// should be float type. + /// + /// + /// BlendShapeIndex blendShapeIndex0 = new BlendShapeIndex(new PropertyKey("nodeName"), new PropertyKey(0u)); + /// BlendShapeIndex blendShapeIndex1 = new BlendShapeIndex(new PropertyKey("nodeName"), new PropertyKey("Target_1")); + /// + /// // We can change the property later. + /// BlendShapeIndex blendShapeIndex2 = new BlendShapeIndex; + /// blendShapeIndex2.ModelNodeId = new PropertyKey("nodeName"); + /// blendShapeIndex2.BlendShapeId = new PropertyKey("Target_2"); + /// + /// + /// Specially, if ModelNodeId is invalid and BlendShapeId is StringKey, + /// It will control all ModelNode that has the inputed blend shape name. + /// + /// + /// // If "node0" and "node1" has same BlendShape named "Smile", + /// // blendShapeIndexAll will control both nodes. + /// BlendShapeIndex blendShapeIndexAll = new BlendShapeIndex(new PropertyKey("Smile")); + /// + /// BlendShapeIndex blendShapeIndex0 = new BlendShapeIndex(new PropertyKey("node0"), new PropertyKey("Smile")); + /// BlendShapeIndex blendShapeIndex1 = new BlendShapeIndex(new PropertyKey("node1"), new PropertyKey("Smile")); + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public class BlendShapeIndex : MotionIndex + { + /// + /// Create an initialized blend shape index. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public BlendShapeIndex() : this(Interop.MotionIndex.BlendShapeIndexNew(), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Create an initialized blend shape index with invalid node id, and input blend shape id. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public BlendShapeIndex(PropertyKey blendShapeId) : this(Interop.MotionIndex.BlendShapeIndexNew(PropertyKey.getCPtr(blendShapeId)), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Create an initialized blend shape index with input node id, and input blend shape id. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public BlendShapeIndex(PropertyKey modelNodeId, PropertyKey blendShapeId) : this(Interop.MotionIndex.BlendShapeIndexNew(PropertyKey.getCPtr(modelNodeId), PropertyKey.getCPtr(blendShapeId)), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Copy constructor. + /// + /// Source object to copy. + [EditorBrowsable(EditorBrowsableState.Never)] + public BlendShapeIndex(BlendShapeIndex blendShapeIndex) : this(Interop.MotionIndex.NewBlendShapeIndex(BlendShapeIndex.getCPtr(blendShapeIndex)), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Assignment operator. + /// + /// Source object to be assigned. + /// Reference to this. + internal BlendShapeIndex Assign(BlendShapeIndex blendShapeIndex) + { + BlendShapeIndex ret = new BlendShapeIndex(Interop.MotionIndex.BlendShapeIndexAssign(SwigCPtr, BlendShapeIndex.getCPtr(blendShapeIndex)), false); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + internal BlendShapeIndex(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) + { + } + + /// + /// The key of blend shape. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public PropertyKey BlendShapeId + { + get + { + return GetBlendShapeId(); + } + set + { + SetBlendShapeId(value); + } + } + + internal void SetBlendShapeId(PropertyKey blendShapeId) + { + Interop.MotionIndex.SetBlendShapeId(SwigCPtr, Property.getCPtr(blendShapeId)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + internal PropertyKey GetBlendShapeId() + { + IntPtr cPtr = Interop.MotionIndex.GetBlendShapeId(SwigCPtr); + PropertyKey ret = new PropertyKey(cPtr, true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + /// + /// Release swigCPtr. + /// + // This will be public opened. + [EditorBrowsable(EditorBrowsableState.Never)] + protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr) + { + Interop.MotionIndex.DeleteBlendShapeIndex(swigCPtr); + } + } +} diff --git a/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionIndex/MotionIndex.cs b/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionIndex/MotionIndex.cs new file mode 100644 index 0000000..8d02401 --- /dev/null +++ b/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionIndex/MotionIndex.cs @@ -0,0 +1,114 @@ +/* + * Copyright(c) 2023 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +using System; +using System.ComponentModel; +using System.Collections.Generic; +using Tizen.NUI; + +namespace Tizen.NUI.Scene3D +{ + /// + /// Index of motion value. It will be used to specify the target of motion applied. + /// + /// There are three kinds of MotionIndex : , and . + /// MotionPropertyIndex will be used for control whole kind of properties. + /// The loaded from files / buffer will have this kind of MotionIndex. + /// + /// MotionTransformIndex will be used for control the 's Position / Orientation / Scale, or each components. + /// BlendShapeIndex will be used for control some blend shape animation. + /// + /// We can use this class below cases + /// - ModelNodeId (string key) , MotionTransformIndex : Target is ModelNode's transform property + /// - ModelNodeId (int key) , MotionTransformIndex : Target is ModelNode's transform property [not implemented yet] + /// - ModelNodeId (string key) , BlendShapeIndex (int key) : Target is ModelNode's BlendShape + /// - ModelNodeId (string key) , BlendShapeIndex (string key) : Target is ModelNode's BlendShape + /// - ModelNodeId (int key) , BlendShapeIndex (int key) : Target is ModelNode's BlendShape [not implemented yet] + /// - ModelNodeId (int key) , BlendShapeIndex (string key) : Target is ModelNode's BlendShape [not implemented yet] + /// - ModelNodeId (null) , BlendShapeIndex (string key) : Target is all ModelNode's BlendShape + /// All other cases are invalid. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public class MotionIndex : BaseHandle + { + /// + /// Copy constructor. + /// + /// Source object to copy. + [EditorBrowsable(EditorBrowsableState.Never)] + public MotionIndex(MotionIndex motionIndex) : this(Interop.MotionIndex.NewMotionIndex(MotionIndex.getCPtr(motionIndex)), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Assignment operator. + /// + /// Source object to be assigned. + /// Reference to this. + internal MotionIndex Assign(MotionIndex motionIndex) + { + MotionIndex ret = new MotionIndex(Interop.MotionIndex.MotionIndexAssign(SwigCPtr, MotionIndex.getCPtr(motionIndex)), false); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + internal MotionIndex(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) + { + } + + /// + /// The id of ModelNode. If you want to apply to all ModelNodes who has BlendShape string, let this value as null. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public PropertyKey ModelNodeId + { + get + { + return GetModelNodeId(); + } + set + { + SetModelNodeId(value); + } + } + + internal void SetModelNodeId(PropertyKey modelNodeId) + { + Interop.MotionIndex.SetModelNodeId(SwigCPtr, Property.getCPtr(modelNodeId)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + internal PropertyKey GetModelNodeId() + { + IntPtr cPtr = Interop.MotionIndex.GetModelNodeId(SwigCPtr); + PropertyKey ret = new PropertyKey(cPtr, true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + /// + /// Release swigCPtr. + /// + // This will be public opened. + [EditorBrowsable(EditorBrowsableState.Never)] + protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr) + { + Interop.MotionIndex.DeleteMotionIndex(swigCPtr); + } + } +} diff --git a/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionIndex/MotionPropertyIndex.cs b/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionIndex/MotionPropertyIndex.cs new file mode 100644 index 0000000..f892c35 --- /dev/null +++ b/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionIndex/MotionPropertyIndex.cs @@ -0,0 +1,132 @@ +/* + * Copyright(c) 2023 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +using System; +using System.ComponentModel; +using System.Collections.Generic; +using Tizen.NUI; + +namespace Tizen.NUI.Scene3D +{ + /// + /// Basic to control Dali's Property. + /// It can control more general case. + /// + /// + /// + /// MotionPropertyIndex color = new MotionPropertyIndex(new PropertyKey("nodeName"), new PropertyKey("color")); + /// + /// // We can change the property later. + /// MotionPropertyIndex custom = newMotionPropertyIndex(); + /// orientation.ModelNodeId = new PropertyKey("nodeName"); + /// orientation.PropertyId = new PropertyKey("some_custom_property"); + /// + /// // Note that all cases of MotionTransformIndex can be controled by MotionPropertyIndex + /// // Both position0 and position1 can control the node's Position. + /// MotionTransformIndex position0 = new MotionTransformIndex(new PropertyKey("nodeName"), MotionTransformIndex.TransformTypes.Position); + /// MotionPropertyIndex position1 = new MotionPropertyIndex(new PropertyKey("nodeName"), new PropertyKey("position")); + /// + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public class MotionPropertyIndex : MotionIndex + { + /// + /// Create an initialized blend shape index. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public MotionPropertyIndex() : this(Interop.MotionIndex.MotionPropertyIndexNew(), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Create an initialized blend shape index with input node id, and property id. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public MotionPropertyIndex(PropertyKey modelNodeId, PropertyKey propertyId) : this(Interop.MotionIndex.MotionPropertyIndexNew(PropertyKey.getCPtr(modelNodeId), PropertyKey.getCPtr(propertyId)), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Copy constructor. + /// + /// Source object to copy. + [EditorBrowsable(EditorBrowsableState.Never)] + public MotionPropertyIndex(MotionPropertyIndex motionPropertyIndex) : this(Interop.MotionIndex.NewMotionPropertyIndex(MotionPropertyIndex.getCPtr(motionPropertyIndex)), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Assignment operator. + /// + /// Source object to be assigned. + /// Reference to this. + internal MotionPropertyIndex Assign(MotionPropertyIndex motionPropertyIndex) + { + MotionPropertyIndex ret = new MotionPropertyIndex(Interop.MotionIndex.MotionPropertyIndexAssign(SwigCPtr, MotionPropertyIndex.getCPtr(motionPropertyIndex)), false); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + internal MotionPropertyIndex(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) + { + } + + /// + /// The key of property + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public PropertyKey PropertyId + { + get + { + return GetPropertyId(); + } + set + { + SetPropertyId(value); + } + } + + internal void SetPropertyId(PropertyKey propertyId) + { + Interop.MotionIndex.SetPropertyId(SwigCPtr, Property.getCPtr(propertyId)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + internal PropertyKey GetPropertyId() + { + IntPtr cPtr = Interop.MotionIndex.GetPropertyId(SwigCPtr); + PropertyKey ret = new PropertyKey(cPtr, true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + /// + /// Release swigCPtr. + /// + // This will be public opened. + [EditorBrowsable(EditorBrowsableState.Never)] + protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr) + { + Interop.MotionIndex.DeleteMotionPropertyIndex(swigCPtr); + } + } +} diff --git a/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionIndex/MotionTransformIndex.cs b/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionIndex/MotionTransformIndex.cs new file mode 100644 index 0000000..930df04 --- /dev/null +++ b/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionIndex/MotionTransformIndex.cs @@ -0,0 +1,196 @@ +/* + * Copyright(c) 2023 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +using System; +using System.ComponentModel; +using System.Collections.Generic; +using Tizen.NUI; + +namespace Tizen.NUI.Scene3D +{ + /// + /// Specialized to control transform. + /// It will be used when app developer don't care about Property index list, + /// but want to change the transform properties anyway fast enough. + /// + /// Each TransformTypes has their own matched type. + /// + /// + /// + /// MotionTransformIndex position = new MotionTransformIndex(new PropertyKey("nodeName"), MotionTransformIndex.TransformTypes.Position); + /// + /// // We can change the property later. + /// MotionTransformIndex orientation = new MotionTransformIndex(); + /// orientation.ModelNodeId = new PropertyKey("nodeName"); + /// orientation.TransformType = MotionTransformIndex.TransformTypes.Orientation; + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public class MotionTransformIndex : MotionIndex + { + /// + /// The list of component types what this MotionIndex can control. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names")] + public enum TransformTypes + { + /// + /// Invalid type. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + Invalid = -1, + + /// + /// The position of ModelNode. MotionValue should be Vector3. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + Position = 0, + + /// + /// The x position of ModelNode. MotionValue should be float. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + PositionX, + + /// + /// The y position of ModelNode. MotionValue should be float. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + PositionY, + + /// + /// The z position of ModelNode. MotionValue should be float. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + PositionZ, + + /// + /// The orientation of ModelNode. MotionValue should be Rotation. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + Orientation, + + /// + /// The scale of ModelNode. MotionValue should be Vector3. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + Scale, + + /// + /// The x scale of ModelNode. MotionValue should be float. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + ScaleX, + + /// + /// The y scale of ModelNode. MotionValue should be float. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + ScaleY, + + /// + /// The z scale of ModelNode. MotionValue should be float. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + ScaleZ, + } + + /// + /// Create an initialized blend shape index. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public MotionTransformIndex() : this(Interop.MotionIndex.MotionTransformIndexNew(), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Create an initialized blend shape index with input node id, and transform type. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public MotionTransformIndex(PropertyKey modelNodeId, TransformTypes transformType) : this(Interop.MotionIndex.MotionTransformIndexNew(PropertyKey.getCPtr(modelNodeId), (int)transformType), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Copy constructor. + /// + /// Source object to copy. + [EditorBrowsable(EditorBrowsableState.Never)] + public MotionTransformIndex(BlendShapeIndex motionTransformIndex) : this(Interop.MotionIndex.NewMotionTransformIndex(MotionTransformIndex.getCPtr(motionTransformIndex)), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Assignment operator. + /// + /// Source object to be assigned. + /// Reference to this. + internal MotionTransformIndex Assign(MotionTransformIndex motionTransformIndex) + { + MotionTransformIndex ret = new MotionTransformIndex(Interop.MotionIndex.MotionTransformIndexAssign(SwigCPtr, MotionTransformIndex.getCPtr(motionTransformIndex)), false); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + internal MotionTransformIndex(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) + { + } + + /// + /// The component type what this MotionIndex want to control. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public TransformTypes TransformType + { + get + { + return GetTransformType(); + } + set + { + SetTransformType(value); + } + } + + internal void SetTransformType(TransformTypes transformType) + { + Interop.MotionIndex.SetTransformType(SwigCPtr, (int)transformType); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + internal TransformTypes GetTransformType() + { + int ret = Interop.MotionIndex.GetTransformType(SwigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return (TransformTypes)ret; + } + + /// + /// Release swigCPtr. + /// + // This will be public opened. + [EditorBrowsable(EditorBrowsableState.Never)] + protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr) + { + Interop.MotionIndex.DeleteMotionTransformIndex(swigCPtr); + } + } +} diff --git a/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionTransformIndex.cs b/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionTransformIndex.cs deleted file mode 100644 index 865efce..0000000 --- a/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionTransformIndex.cs +++ /dev/null @@ -1,157 +0,0 @@ -using System.Numerics; -/* - * Copyright(c) 2023 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -using System; -using System.ComponentModel; -using System.Collections.Generic; -using Tizen.NUI; - -namespace Tizen.NUI.Scene3D -{ - /// - /// Index of Transform feature. - /// Each TransformTypes has their own matched MotionValue type. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public class MotionTransformIndex : MotionIndex - { - /// - /// The list of component types what this MotionIndex can control. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names")] - public enum TransformTypes - { - /// - /// The position of ModelNode. MotionValue should be Vector3. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - Position, - - /// - /// The x position of ModelNode. MotionValue should be float. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - PositionX, - - /// - /// The y position of ModelNode. MotionValue should be float. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - PositionY, - - /// - /// The z position of ModelNode. MotionValue should be float. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - PositionZ, - - /// - /// The orientation of ModelNode. MotionValue should be Rotation. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - Orientation, - - /// - /// The scale of ModelNode. MotionValue should be Vector3. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - Scale, - - /// - /// The x scale of ModelNode. MotionValue should be float. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - ScaleX, - - /// - /// The y scale of ModelNode. MotionValue should be float. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - ScaleY, - - /// - /// The z scale of ModelNode. MotionValue should be float. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - ScaleZ, - } - - /// - /// Create an initialized motion index. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public MotionTransformIndex() - { - } - - /// - /// The component type what this MotionIndex want to control. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public TransformTypes TransformType { get; set; } = TransformTypes.Position; - - /// - /// Get uniform name of TransformType. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - internal override string GetPropertyName(ModelNode node) - { - switch (TransformType) - { - case TransformTypes.Position: - { - return "Position"; - } - case TransformTypes.PositionX: - { - return "PositionX"; - } - case TransformTypes.PositionY: - { - return "PositionY"; - } - case TransformTypes.PositionZ: - { - return "PositionZ"; - } - case TransformTypes.Orientation: - { - return "Orientation"; - } - case TransformTypes.Scale: - { - return "Scale"; - } - case TransformTypes.ScaleX: - { - return "ScaleX"; - } - case TransformTypes.ScaleY: - { - return "ScaleY"; - } - case TransformTypes.ScaleZ: - { - return "ScaleZ"; - } - } - return null; - } - } -} diff --git a/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionValue.cs b/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionValue.cs index 293ecaf..f9a1627 100644 --- a/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionValue.cs +++ b/src/Tizen.NUI.Scene3D/src/public/ModelMotion/MotionValue.cs @@ -16,6 +16,7 @@ */ using System; +using System.Runtime.InteropServices; using System.ComponentModel; using System.Collections.Generic; using Tizen.NUI; @@ -23,13 +24,18 @@ using Tizen.NUI; namespace Tizen.NUI.Scene3D { /// - /// Target value of motion. It can be define as specific PropertyValue, or KeyFrames + /// This MotionValue be used for target value of each . + /// We can get and set MotionValue as 2 types : PropertyValue and KeyFrames. + /// + /// Each types will be cross-converted internally. + /// For example, when we set PropertyValue, we can get KeyFrames with 2 frames, and target value is set. /// + /// + /// The type of property should be matched with MotionIndex required. + /// [EditorBrowsable(EditorBrowsableState.Never)] - public class MotionValue : IDisposable + public class MotionValue : BaseHandle { - private IDisposable internalValue = null; - /// /// Determine whether current stored value is PropertyValue, or KeyFrames. /// @@ -40,13 +46,13 @@ namespace Tizen.NUI.Scene3D /// Value is null, or invalid class. /// [EditorBrowsable(EditorBrowsableState.Never)] - Invalid, + Invalid = -1, /// /// Value is PropertyValue. /// [EditorBrowsable(EditorBrowsableState.Never)] - Property, + Property = 0, /// /// Value is KeyFrames. @@ -59,71 +65,166 @@ namespace Tizen.NUI.Scene3D /// Create an initialized motion value with invalid. /// [EditorBrowsable(EditorBrowsableState.Never)] - public MotionValue() + public MotionValue() : this(Interop.MotionValue.MotionValueNew(), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Create an initialized motion value with PropertyValue. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public MotionValue(PropertyValue propertyValue) : this(Interop.MotionValue.MotionValueNewPropertyValue(PropertyValue.getCPtr(propertyValue)), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Create an initialized motion value with KeyFrames. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public MotionValue(KeyFrames keyFrames) : this(Interop.MotionValue.MotionValueNewKeyFrames(KeyFrames.getCPtr(keyFrames)), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Copy constructor. + /// + /// Source object to copy. + [EditorBrowsable(EditorBrowsableState.Never)] + public MotionValue(MotionValue motionValue) : this(Interop.MotionValue.NewMotionValue(MotionValue.getCPtr(motionValue)), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Assignment operator. + /// + /// Source object to be assigned. + /// Reference to this. + internal MotionValue Assign(MotionValue motionValue) + { + MotionValue ret = new MotionValue(Interop.MotionValue.MotionValueAssign(SwigCPtr, MotionValue.getCPtr(motionValue)), false); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + internal MotionValue(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) { } + /// /// Get or set the value as PropertyValue type. - /// It will return null if value is not PropertyValue. + /// If ValueType is ValueType.KeyFrames, it will return last value of stored KeyFrames. /// [EditorBrowsable(EditorBrowsableState.Never)] - public PropertyValue Value + public PropertyValue PropertyValue { get { - return internalValue as PropertyValue; + return GetPropertyValue(); } set { - internalValue = (Disposable)value; + SetPropertyValue(value); } } /// /// Get or set the value as KeyFrames type. - /// It will return null if value is not KeyFrames. + /// If ValueType is ValueType.PropertyValue, it will create new KeyFrames by stored PropertyValue. /// [EditorBrowsable(EditorBrowsableState.Never)] public KeyFrames KeyFramesValue { get { - return internalValue as KeyFrames; + return GetKeyFrames(); } set { - internalValue = (BaseHandle)value; + SetKeyFrames(value); } } /// - /// Get the type of value what we setted. + /// Get the type of value what we set. /// [EditorBrowsable(EditorBrowsableState.Never)] public ValueType Type { get { - if (internalValue is KeyFrames) - { - return ValueType.KeyFrames; - } - if (internalValue is PropertyValue) - { - return ValueType.Property; - } - return ValueType.Invalid; + return GetMotionValueType(); + } + } + + /// + /// Invalidate the value what we set. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public void Invalidate() + { + Interop.MotionValue.Clear(SwigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + internal void SetPropertyValue(PropertyValue propertyValue) + { + Interop.MotionValue.SetValuePropertyValue(SwigCPtr, PropertyValue.getCPtr(propertyValue)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + internal PropertyValue GetPropertyValue() + { + IntPtr cPtr = Interop.MotionValue.GetPropertyValue(SwigCPtr); + PropertyValue ret = new PropertyValue(cPtr, true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + internal void SetKeyFrames(KeyFrames keyFrames) + { + Interop.MotionValue.SetValueKeyFrames(SwigCPtr, KeyFrames.getCPtr(keyFrames)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + internal KeyFrames GetKeyFrames() + { + IntPtr cPtr = Interop.MotionValue.GetKeyFrames(SwigCPtr); + KeyFrames ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as KeyFrames; + if (ret == null) + { + // Register new animation into Registry. + ret = new KeyFrames(cPtr, true); + } + else + { + // We found matched NUI animation. Reduce cPtr reference count. + HandleRef handle = new HandleRef(this, cPtr); + Tizen.NUI.Interop.KeyFrames.DeleteKeyFrames(handle); + handle = new HandleRef(null, IntPtr.Zero); } + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + internal ValueType GetMotionValueType() + { + int ret = Interop.MotionValue.GetValueType(SwigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return (ValueType)ret; } /// - /// IDisposable.Dipsose. + /// Release swigCPtr. /// + // This will be public opened. [EditorBrowsable(EditorBrowsableState.Never)] - public void Dispose() + protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr) { - internalValue?.Dispose(); + Interop.MotionValue.DeleteMotionValue(swigCPtr); } } } diff --git a/test/Tizen.NUI.Scene3D.Sample/Scene3DSample.cs b/test/Tizen.NUI.Scene3D.Sample/Scene3DSample.cs index 06fa774..ea1f775 100644 --- a/test/Tizen.NUI.Scene3D.Sample/Scene3DSample.cs +++ b/test/Tizen.NUI.Scene3D.Sample/Scene3DSample.cs @@ -307,6 +307,8 @@ class Scene3DSample : NUIApplication mStaticRevertMotionData = new MotionData(); mAnimateMotionData = new MotionData(); + mAnimateMotionData.Duration = modelMotionAnimationDurationMilliseconds; + mStaticMotionData.Add( new MotionTransformIndex() { @@ -315,7 +317,7 @@ class Scene3DSample : NUIApplication }, new MotionValue() { - Value = new PropertyValue(new Rotation(new Radian(new Degree(-45.0f)), Vector3.ZAxis)), + PropertyValue = new PropertyValue(new Rotation(new Radian(new Degree(-45.0f)), Vector3.ZAxis)), } ); mStaticRevertMotionData.Add( @@ -326,7 +328,7 @@ class Scene3DSample : NUIApplication }, new MotionValue() { - Value = new PropertyValue(new Rotation(new Radian(new Degree(0.0f)), Vector3.ZAxis)), + PropertyValue = new PropertyValue(new Rotation(new Radian(new Degree(0.0f)), Vector3.ZAxis)), } ); mStaticRevertMotionData.Add( @@ -337,7 +339,7 @@ class Scene3DSample : NUIApplication }, new MotionValue() { - Value = new PropertyValue(Vector3.One), + PropertyValue = new PropertyValue(Vector3.One), } ); @@ -349,7 +351,7 @@ class Scene3DSample : NUIApplication }, new MotionValue() { - Value = new PropertyValue(new Vector3(0.5f, 1.5f, 1.0f)), + PropertyValue = new PropertyValue(new Vector3(0.5f, 1.5f, 1.0f)), } ); for (int i = 0; i < 8; ++i) @@ -454,7 +456,7 @@ class Scene3DSample : NUIApplication { if (mModel != null && mModelLoadFinished) { - mMotionAnimation = mModel.GenerateMotionDataAnimation(mAnimateMotionData, modelMotionAnimationDurationMilliseconds); + mMotionAnimation = mModel.GenerateMotionDataAnimation(mAnimateMotionData); if (mMotionAnimation != null) {