[NUI] Supports to build ModelNode Tree
authorseungho baek <sbsh.baek@samsung.com>
Tue, 7 Nov 2023 11:39:44 +0000 (20:39 +0900)
committerJaehyun Cho <jaehyun0cho@gmail.com>
Wed, 15 Nov 2023 07:09:04 +0000 (16:09 +0900)
Signed-off-by: seungho baek <sbsh.baek@samsung.com>
src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.ModelNode.cs
src/Tizen.NUI.Scene3D/src/public/Controls/Model.cs
src/Tizen.NUI.Scene3D/src/public/ModelComponents/ModelNode.cs
src/Tizen.NUI.Scene3D/src/public/ModelComponents/ModelPrimitive.cs

index fdb5d93..2277187 100755 (executable)
@@ -56,6 +56,12 @@ namespace Tizen.NUI.Scene3D
 
             [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_Model_Node_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_Node_GetChildModelNodeCount")]
+            public static extern uint GetChildModelNodeCount(global::System.Runtime.InteropServices.HandleRef model);
+
+            [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_Model_Node_GetChildModelNodeAt")]
+            public static extern global::System.IntPtr GetChildModelNodeAt(global::System.Runtime.InteropServices.HandleRef model, uint index);
         }
     }
 }
index 0d9d0a4..125e0d3 100755 (executable)
@@ -76,6 +76,7 @@ namespace Tizen.NUI.Scene3D
     /// <since_tizen> 10 </since_tizen>
     public partial class Model : View
     {
+        private bool isBuilt = false;
         internal Model(global::System.IntPtr cPtr, bool cMemoryOwn) : this(cPtr, cMemoryOwn, cMemoryOwn)
         {
         }
@@ -100,6 +101,7 @@ namespace Tizen.NUI.Scene3D
         {
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             this.PositionUsesPivotPoint = true;
+            ResourcesLoaded += OnResourcesLoaded;
         }
 
         /// <summary>
@@ -622,6 +624,29 @@ namespace Tizen.NUI.Scene3D
             return scaleFactor;
         }
 
+        private void OnResourcesLoaded(object sender, EventArgs e)
+        {
+            if(!isBuilt && this.ModelRoot != null)
+            {
+                this.ModelRoot.Build();
+                isBuilt = true;
+            }
+        }
+
+        /// <summary>
+        /// To make transitionSet instance be disposed.
+        /// </summary>
+        protected override void Dispose(DisposeTypes type)
+        {
+            if (disposed)
+            {
+                return;
+            }
+
+            ResourcesLoaded -= OnResourcesLoaded;
+            base.Dispose(type);
+        }
+
         /// <summary>
         /// Release swigCPtr.
         /// </summary>
index bd5d477..c0dc91b 100755 (executable)
@@ -18,6 +18,7 @@
 using System;
 using System.Runtime.InteropServices;
 using System.ComponentModel;
+using System.Collections.Generic;
 using Tizen.NUI;
 using Tizen.NUI.Binding;
 using Tizen.NUI.BaseComponents;
@@ -165,7 +166,7 @@ namespace Tizen.NUI.Scene3D
         }
 
         /// <summary>
-        /// Removes Returns a child ModelNode object with a name that matches nodeName.
+        /// Returns a child ModelNode object with a name that matches nodeName.
         /// </summary>
         /// <param name="nodeName">The name of the child ModelNode object you want to find.</param>
         /// <returns>Child ModelNode that has nodeName as name.</returns>
@@ -211,6 +212,73 @@ namespace Tizen.NUI.Scene3D
         }
 
         /// <summary>
+        /// Build C# ModelNode Tree
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        internal void Build()
+        {
+            List<ModelNode> childModelNodes = new List<ModelNode>();
+            uint childModelNodeCount = GetChildModelNodeCount();
+            for(uint i = 0; i < childModelNodeCount; ++i)
+            {
+                ModelNode modelNode = GetChildModelNodeAt(i);
+                childModelNodes.Add(modelNode);
+                modelNode.Build();
+            }
+
+            foreach(ModelNode node in childModelNodes)
+            {
+                this.Add(node);
+            }
+        }
+
+        /// <summary>
+        /// Gets the number of child objects in the ModelNode object.
+        /// </summary>
+        /// <returns>The number of childchild objects in the ModelNode object.</returns>
+        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        private uint GetChildModelNodeCount()
+        {
+            uint ret = Interop.ModelNode.GetChildModelNodeCount(SwigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        /// <summary>
+        /// Returns a child ModelNode object at the index.
+        /// </summary>
+        /// <param name="index">The index of child ModelNode object you want to find.</param>
+        /// <returns>Child ModelNode</returns>
+        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        private ModelNode GetChildModelNodeAt(uint index)
+        {
+            global::System.IntPtr cPtr = Interop.ModelNode.GetChildModelNodeAt(SwigCPtr, index);
+            ModelNode ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as ModelNode;
+            if (ret == null)
+            {
+                // Store the value of PositionUsesAnchorPoint from dali object (Since View object automatically change PositionUsesPivotPoint value as false, we need to keep value.)
+                HandleRef handle = new HandleRef(this, cPtr);
+                bool originalPositionUsesAnchorPoint = Object.InternalGetPropertyBool(handle, View.Property.PositionUsesAnchorPoint);
+                handle = new HandleRef(null, IntPtr.Zero);
+
+                // Register new animatable into Registry.
+                ret = new ModelNode(cPtr, true);
+                ret.PositionUsesPivotPoint = originalPositionUsesAnchorPoint;
+            }
+            else
+            {
+                // We found matched NUI animatable. Reduce cPtr reference count.
+                HandleRef handle = new HandleRef(this, cPtr);
+                Tizen.NUI.Interop.BaseHandle.DeleteBaseHandle(handle);
+                handle = new HandleRef(null, IntPtr.Zero);
+            }
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        /// <summary>
         /// Release swigCPtr.
         /// </summary>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
index f1215dd..ff2eaa4 100755 (executable)
@@ -142,8 +142,21 @@ namespace Tizen.NUI.Scene3D
         private Geometry GetGeometry()
         {
             IntPtr cPtr = Interop.ModelPrimitive.GetGeometry(SwigCPtr);
+            Geometry ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Geometry;
+            if (ret == null)
+            {
+                HandleRef handle = new HandleRef(this, cPtr);
+                handle = new HandleRef(null, IntPtr.Zero);
+
+                ret = new Geometry(cPtr, true);
+            }
+            else
+            {
+                HandleRef handle = new HandleRef(this, cPtr);
+                Tizen.NUI.Interop.BaseHandle.DeleteBaseHandle(handle);
+                handle = new HandleRef(null, IntPtr.Zero);
+            }
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            Geometry ret = (cPtr == IntPtr.Zero) ? null : Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Geometry;
             return ret;
         }
 
@@ -167,9 +180,22 @@ namespace Tizen.NUI.Scene3D
         [EditorBrowsable(EditorBrowsableState.Never)]
         private Material GetMaterial()
         {
-            IntPtr cPtr = Interop.ModelPrimitive.GetMaterial(SwigCPtr);
+            global::System.IntPtr cPtr = Interop.ModelPrimitive.GetMaterial(SwigCPtr);
+            Material ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Material;
+            if (ret == null)
+            {
+                HandleRef handle = new HandleRef(this, cPtr);
+                handle = new HandleRef(null, IntPtr.Zero);
+
+                ret = new Material(cPtr, true);
+            }
+            else
+            {
+                HandleRef handle = new HandleRef(this, cPtr);
+                Tizen.NUI.Interop.BaseHandle.DeleteBaseHandle(handle);
+                handle = new HandleRef(null, IntPtr.Zero);
+            }
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            Material ret = (cPtr == IntPtr.Zero) ? null : Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Material;
             return ret;
         }