[NUI] Supports to build ModelNode Tree
authorseungho baek <sbsh.baek@samsung.com>
Tue, 7 Nov 2023 11:39:44 +0000 (20:39 +0900)
committerhuiyu <35286162+huiyueun@users.noreply.github.com>
Wed, 17 Jan 2024 09:35:29 +0000 (18:35 +0900)
Signed-off-by: seungho baek <sbsh.baek@samsung.com>
Signed-off-by: huiyu.eun <huiyu.eun@samsung.com>
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 3823f9f..759a8c0 100755 (executable)
@@ -77,6 +77,7 @@ namespace Tizen.NUI.Scene3D
     /// <since_tizen> 10 </since_tizen>
     public partial class Model : View
     {
+        private bool isBuilt = false;
         private Position modelPivotPoint = new Position();
         internal Model(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
         {
@@ -638,6 +639,11 @@ namespace Tizen.NUI.Scene3D
 
         private void OnResourcesLoaded(object sender, EventArgs e)
         {
+            if(!isBuilt && this.ModelRoot != null)
+            {
+                this.ModelRoot.Build();
+                isBuilt = true;
+            }
             this.modelPivotPoint.X = this.PivotPoint.X;
             this.modelPivotPoint.Y = this.PivotPoint.Y;
             this.modelPivotPoint.Z = this.PivotPoint.Z;
index 878db87..093834f 100755 (executable)
@@ -19,6 +19,7 @@ using System;
 using System.Collections.Generic;
 using System.Runtime.InteropServices;
 using System.ComponentModel;
+using System.Collections.Generic;
 using Tizen.NUI;
 using Tizen.NUI.Binding;
 using Tizen.NUI.BaseComponents;
@@ -162,7 +163,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>
@@ -242,6 +243,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 0af4a90..a96594f 100755 (executable)
@@ -138,8 +138,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;
         }
 
@@ -163,9 +176,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;
         }