2 * Copyright(c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Collections.Generic;
20 using System.Runtime.InteropServices;
21 using System.ComponentModel;
23 using Tizen.NUI.Binding;
24 using Tizen.NUI.BaseComponents;
26 namespace Tizen.NUI.Scene3D
29 /// Model is a Class to show 3D mesh objects.
30 /// Model supports glTF 2.0 and DLI model formats.
31 /// Physically Based Rendering with Image Based Lighting is also supported.
35 /// Since NUI uses a left-handed coordinate system, loaded models are transformed into a left-handed coordinate system with Y pointing down.
36 /// The Animations defined in the glTF or DLI are also loaded and can be retrieved by using <see cref="GetAnimation(uint)"/> and <see cref="GetAnimation(string)"/> methods.
37 /// The number of animation is also retrieved by GetAnimationCount() method.
39 /// Model also supports Physically Based Rendering(PBR) with Image Based Lighting(IBL).
40 /// For the IBL, two cube map textures(diffuse and specular) are required.
41 /// Model supports 4 types layout for Cube Map: Vertical/Horizontal Cross layouts, and Vertical/Horizontal Array layouts.
42 /// And also, ktx format with cube map is supported.
44 /// The model and IBL textures start to be loaded asynchronously when the Model object is on Window.
45 /// ResourcesLoaded signal notifies that the loading of the model and IBL resources have been completed.
46 /// If Model or IBL is requested to be loaded before the other loading is completed, the ResourcesLoaded signal is called after all resources are loaded.
47 /// <see cref="GetAnimation(uint)"/> and <see cref="GetAnimation(string)"/> methods can be used after the model loading is finished.
49 /// By default, the loaded mesh has its own size and <see cref="PivotPoint"/> inferred from position of vertices.
50 /// The <see cref="PivotPoint"/> can be modified after model loading is finished.
51 /// If user set size property, the mesh will be scaled to the input size.
52 /// Default value of <see cref="ParentOrigin"/> of the Model is Center.
57 /// Model model = new Model(modelUrl)
59 /// Size = new Size(width, height),
61 /// model.ResourcesLoaded += (s, e) =>
63 /// model.PivotPoint = new Vector3(0.5f, 0.5f, 0.5f); // Use center as a Pivot.
65 /// int animationCount = model.GetAnimationCount();
66 /// if(animationCount > 0)
68 /// // Play an Animation of index 0.
69 /// model.GetAnimation(0).Play();
72 /// model.SetImageBasedLightSource(diffuseUrl, specularUrl, scaleFactor);
73 /// window.Add(model);
77 /// <since_tizen> 10 </since_tizen>
78 public partial class Model : View
80 private bool isBuilt = false;
81 private Position modelPivotPoint = new Position();
82 internal Model(global::System.IntPtr cPtr, bool cMemoryOwn) : this(cPtr, cMemoryOwn, cMemoryOwn)
86 internal Model(global::System.IntPtr cPtr, bool cMemoryOwn, bool cRegister) : base(cPtr, cMemoryOwn, true, cRegister)
91 /// Create an initialized Model.
93 /// <param name="modelUrl">model file url.(e.g. glTF, and DLI).</param>
94 /// <param name="resourceDirectoryUrl"> The url to derectory containing resources: binary, image etc.</param>
96 /// If resourceDirectoryUrl is empty, the parent directory url of modelUrl is used for resource url.
98 /// http://tizen.org/privilege/mediastorage for local files in media storage.
99 /// http://tizen.org/privilege/externalstorage for local files in external storage.
101 /// <since_tizen> 10 </since_tizen>
102 public Model(string modelUrl, string resourceDirectoryUrl = "") : this(Interop.Model.ModelNew(modelUrl, resourceDirectoryUrl), true)
104 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
105 this.PositionUsesPivotPoint = true;
106 ResourcesLoaded += OnResourcesLoaded;
110 /// Create an initialized Model.
112 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
113 [EditorBrowsable(EditorBrowsableState.Never)]
114 public Model() : this(Interop.Model.ModelNew(), true)
116 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
117 this.PositionUsesPivotPoint = true;
121 /// Copy constructor.
123 /// <param name="model">Source object to copy.</param>
124 /// <since_tizen> 10 </since_tizen>
125 public Model(Model model) : this(Interop.Model.NewModel(Model.getCPtr(model)), true, false)
127 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
128 this.PositionUsesPivotPoint = model.PositionUsesPivotPoint;
132 /// Assignment operator.
134 /// <param name="model">Source object to be assigned.</param>
135 /// <returns>Reference to this.</returns>
136 internal Model Assign(Model model)
138 Model ret = new Model(Interop.Model.ModelAssign(SwigCPtr, Model.getCPtr(model)), false);
139 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
140 ret.PositionUsesPivotPoint = model.PositionUsesPivotPoint;
145 /// Get The original pivot point of the model
148 /// This returns (0, 0, 0) before resources are loaded.
150 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
151 [EditorBrowsable(EditorBrowsableState.Never)]
152 public Position ModelPivotPoint
156 return modelPivotPoint;
161 /// Set/Get the ImageBasedLight ScaleFactor.
162 /// Scale factor controls light source intensity in [0.0f, 1.0f]
164 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
165 [EditorBrowsable(EditorBrowsableState.Never)]
166 public float ImageBasedLightScaleFactor
170 SetImageBasedLightScaleFactor(value);
174 return GetImageBasedLightScaleFactor();
179 /// Retrieves root ModelNode of this Model.
181 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
182 [EditorBrowsable(EditorBrowsableState.Never)]
183 public ModelNode ModelRoot
187 return GetModelRoot();
192 /// Adds modelNode to this Model.
194 /// <param name="modelNode">Root of a ModelNode tree</param>
195 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
196 [EditorBrowsable(EditorBrowsableState.Never)]
197 public void AddModelNode(ModelNode modelNode)
199 Interop.Model.AddModelNode(SwigCPtr, ModelNode.getCPtr(modelNode));
200 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
204 /// Removes modelNode from this Model.
206 /// <param name="modelNode">Root of a ModelNode tree to be removed</param>
207 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
208 [EditorBrowsable(EditorBrowsableState.Never)]
209 public void RemoveModelNode(ModelNode modelNode)
211 Interop.Model.RemoveModelNode(SwigCPtr, ModelNode.getCPtr(modelNode));
212 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
216 /// Removes Returns a child ModelNode object with a name that matches nodeName.
218 /// <param name="nodeName">The name of the child ModelNode object you want to find.</param>
219 /// <returns>Child ModelNode that has nodeName as name.</returns>
220 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
221 [EditorBrowsable(EditorBrowsableState.Never)]
222 public ModelNode FindChildModelNodeByName(string nodeName)
224 global::System.IntPtr cPtr = Interop.Model.FindChildModelNodeByName(SwigCPtr, nodeName);
225 ModelNode ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as ModelNode;
228 // Store the value of PositionUsesAnchorPoint from dali object (Since View object automatically change PositionUsesPivotPoint value as false, we need to keep value.)
229 HandleRef handle = new HandleRef(this, cPtr);
231 // Use original value as 'true' if we got invalid ModelNode.
232 bool originalPositionUsesAnchorPoint = (cPtr == global::System.IntPtr.Zero || !Tizen.NUI.Interop.BaseHandle.HasBody(handle)) || Object.InternalGetPropertyBool(handle, View.Property.PositionUsesAnchorPoint);
233 handle = new HandleRef(null, IntPtr.Zero);
235 // Register new animatable into Registry.
236 ret = new ModelNode(cPtr, true);
239 ret.PositionUsesPivotPoint = originalPositionUsesAnchorPoint;
244 // We found matched NUI animatable. Reduce cPtr reference count.
245 HandleRef handle = new HandleRef(this, cPtr);
246 Tizen.NUI.Interop.BaseHandle.DeleteBaseHandle(handle);
247 handle = new HandleRef(null, IntPtr.Zero);
249 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
254 /// Changes Image Based Light according to the given input textures.
256 /// <param name="diffuseUrl">The path of Cube map image that will be used as a diffuse IBL source.</param>
257 /// <param name="specularUrl">The path of Cube map image that will be used as a specular IBL source.</param>
258 /// <param name="scaleFactor">Scale factor that controls light source intensity in [0.0f, 1.0f]. Default value is 1.0f.</param>
260 /// http://tizen.org/privilege/mediastorage for local files in media storage.
261 /// http://tizen.org/privilege/externalstorage for local files in external storage.
263 /// <since_tizen> 10 </since_tizen>
264 public void SetImageBasedLightSource(string diffuseUrl, string specularUrl, float scaleFactor = 1.0f)
266 Interop.Model.SetImageBasedLightSource(SwigCPtr, diffuseUrl, specularUrl, scaleFactor);
267 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271 /// Gets number of animations that has been loaded from model file.
274 /// This method should be called after Model load has been finished.
276 /// <returns>The number of loaded animations.</returns>
277 /// <since_tizen> 10 </since_tizen>
278 public uint GetAnimationCount()
280 uint ret = Interop.Model.GetAnimationCount(SwigCPtr);
281 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286 /// Gets animation at the index.
289 /// This method should be called after Model load has been finished.
291 /// <param name="index">Index of animation to be retrieved.</param>
292 /// <returns>Animation at the index.</returns>
293 /// <since_tizen> 10 </since_tizen>
294 public Animation GetAnimation(uint index)
296 global::System.IntPtr cPtr = Interop.Model.GetAnimation(SwigCPtr, index);
297 Animation ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animation;
300 // Register new animation into Registry.
301 ret = new Animation(cPtr, true);
305 // We found matched NUI animation. Reduce cPtr reference count.
306 HandleRef handle = new HandleRef(this, cPtr);
307 Tizen.NUI.Interop.Animation.DeleteAnimation(handle);
308 handle = new HandleRef(null, IntPtr.Zero);
310 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
315 /// Retrieves animation with the given name.
316 /// Note: This method should be called after Model load finished.
318 /// <param name="name">String name of animation to be retrieved.</param>
319 /// <returns>Animation that has the given name.</returns>
320 /// <since_tizen> 10 </since_tizen>
321 public Animation GetAnimation(string name)
323 global::System.IntPtr cPtr = Interop.Model.GetAnimation(SwigCPtr, name);
324 Animation ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animation;
327 // Register new animation into Registry.
328 ret = new Animation(cPtr, true);
332 // We found matched NUI animation. Reduce cPtr reference count.
333 HandleRef handle = new HandleRef(this, cPtr);
334 Tizen.NUI.Interop.Animation.DeleteAnimation(handle);
335 handle = new HandleRef(null, IntPtr.Zero);
337 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
342 /// Gets number of camera parameters that has been loaded from model file.
345 /// This method should be called after Model load has been finished.
347 /// <returns>The number of loaded camera parameters.</returns>
348 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
349 [EditorBrowsable(EditorBrowsableState.Never)]
350 public uint GetCameraCount()
352 uint ret = Interop.Model.GetCameraCount(SwigCPtr);
353 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
358 /// Generate Camera using camera parameters at the index.
359 /// If camera parameter is valid, create new Camera.
360 /// Else, return empty Handle.
363 /// This method should be called after Model load has been finished.
365 /// <param name="index">Index of camera to be generated.</param>
366 /// <returns>Generated Camera by the index, or empty Handle if generation failed.</returns>
367 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
368 [EditorBrowsable(EditorBrowsableState.Never)]
369 public Camera GenerateCamera(uint index)
371 global::System.IntPtr cPtr = Interop.Model.GenerateCamera(SwigCPtr, index);
372 Camera ret = new Camera(cPtr, true); // Always create new camera.
373 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
378 /// Apply camera parameters at the index to inputed Camera.
379 /// If camera parameter is valid and camera is not empty, apply parameters.
380 /// It will change camera's transform and near / far / fov or orthographic size / aspect ratio (if defined)
383 /// This method should be called after Model load has been finished.
385 /// <param name="index">Index of camera to be retrieved.</param>
386 /// <param name="camera">Camera to be applied parameter.</param>
387 /// <returns>True if Apply successed. False otherwise.</returns>
388 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
389 [EditorBrowsable(EditorBrowsableState.Never)]
390 public bool ApplyCamera(uint index, Camera camera)
393 if (camera?.HasBody() == true)
395 ret = Interop.Model.ApplyCamera(SwigCPtr, index, Camera.getCPtr(camera));
396 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
402 /// Load bvh animation and assign to model.
403 /// Scale is additional scale factor of bvh animation. It is possible that
404 /// Model's scale may not matched with bvh animation scale.
405 /// If scale is null, default use as Vector3.ONE
407 /// <param name="bvhFilename">Name of bvh format file.</param>
408 /// <param name="scale">Scale value of bvh animation match with model.</param>
409 /// <param name="translateRootFromModelNode">Whether we should translate the bvh root from it's ModelNode position or not.</param>
410 /// <returns>Animaion of bvh</returns>
411 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
412 [EditorBrowsable(EditorBrowsableState.Never)]
413 [Obsolete("Do not use this LoadBvhAnimation. Use MotionData.LoadMotionCaptureAnimation and GenerateMotionDataAnimation instead.")]
414 public Animation LoadBvhAnimation(string bvhFilename, Vector3 scale = null, bool translateRootFromModelNode = true)
416 global::System.IntPtr cPtr = Interop.Model.LoadBvhAnimation(SwigCPtr, bvhFilename, Vector3.getCPtr(scale), translateRootFromModelNode);
417 Animation ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animation;
420 // Register new animation into Registry.
421 ret = new Animation(cPtr, true);
425 // We found matched NUI animation. Reduce cPtr reference count.
426 HandleRef handle = new HandleRef(this, cPtr);
427 Tizen.NUI.Interop.Animation.DeleteAnimation(handle);
428 handle = new HandleRef(null, IntPtr.Zero);
430 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
435 /// Load bvh animation and assign to model.
436 /// Scale is additional scale factor of bvh animation. It is possible that
437 /// Model's scale may not matched with bvh animation scale.
438 /// If scale is null, default use as Vector3.ONE
440 /// <param name="bvhBuffer">Contents of bvh format file.</param>
441 /// <param name="scale">Scale value of bvh animation match with model.</param>
442 /// <param name="translateRootFromModelNode">Whether we should translate the bvh root from it's ModelNode position or not.</param>
443 /// <returns>Animaion of bvh</returns>
444 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
445 [EditorBrowsable(EditorBrowsableState.Never)]
446 [Obsolete("Do not use this LoadBvhAnimationFromBuffer. Use MotionData.LoadMotionCaptureAnimationFromBuffer and GenerateMotionDataAnimation instead.")]
447 public Animation LoadBvhAnimationFromBuffer(string bvhBuffer, Vector3 scale = null, bool translateRootFromModelNode = true)
449 global::System.IntPtr cPtr = Interop.Model.LoadBvhAnimationFromBuffer(SwigCPtr, bvhBuffer, bvhBuffer.Length, Vector3.getCPtr(scale), translateRootFromModelNode);
450 Animation ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animation;
453 // Register new animation into Registry.
454 ret = new Animation(cPtr, true);
458 // We found matched NUI animation. Reduce cPtr reference count.
459 HandleRef handle = new HandleRef(this, cPtr);
460 Tizen.NUI.Interop.Animation.DeleteAnimation(handle);
461 handle = new HandleRef(null, IntPtr.Zero);
463 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
468 /// Load facial animation and assign to model.
470 /// <param name="facialFilename">Name of json format file what we predefined.</param>
471 /// <returns>Animaion of facial</returns>
472 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
473 [EditorBrowsable(EditorBrowsableState.Never)]
474 [Obsolete("Do not use this LoadFacialAnimation. Use MotionData.LoadBlendShapeAnimation and GenerateMotionDataAnimation instead.")]
475 public Animation LoadFacialAnimation(string facialFilename)
477 return LoadBlendShapeAnimation(facialFilename);
481 /// Load facial animation and assign to model.
483 /// <param name="facialBuffer">Contents of json format file what we predefined.</param>
484 /// <returns>Animaion of facial</returns>
485 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
486 [EditorBrowsable(EditorBrowsableState.Never)]
487 [Obsolete("Do not use this LoadFacialAnimationFromBuffer. Use MotionData.LoadBlendShapeAnimationFromBuffer and GenerateMotionDataAnimation instead.")]
488 public Animation LoadFacialAnimationFromBuffer(string facialBuffer)
490 return LoadBlendShapeAnimationFromBuffer(facialBuffer);
494 /// Load blendshape animation and assign to model from json file.
496 /// <param name="jsonFilename">Name of json format file what we predefined.</param>
497 /// <returns>Animaion of facial</returns>
498 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
499 [EditorBrowsable(EditorBrowsableState.Never)]
500 [Obsolete("Do not use this LoadBlendShapeAnimation. Use MotionData.LoadBlendShapeAnimation and GenerateMotionDataAnimation instead.")]
501 public Animation LoadBlendShapeAnimation(string jsonFilename)
503 global::System.IntPtr cPtr = Interop.Model.LoadBlendShapeAnimation(SwigCPtr, jsonFilename);
504 Animation ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animation;
507 // Register new animation into Registry.
508 ret = new Animation(cPtr, true);
512 // We found matched NUI animation. Reduce cPtr reference count.
513 HandleRef handle = new HandleRef(this, cPtr);
514 Tizen.NUI.Interop.Animation.DeleteAnimation(handle);
515 handle = new HandleRef(null, IntPtr.Zero);
517 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
522 /// Load morphing animation and assign to model from json string.
524 /// <param name="jsonBuffer">Contents of json format file what we predefined.</param>
525 /// <returns>Animaion of facial</returns>
526 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
527 [EditorBrowsable(EditorBrowsableState.Never)]
528 [Obsolete("Do not use this LoadBlendShapeAnimationFromBuffer. Use MotionData.LoadBlendShapeAnimationFromBuffer and GenerateMotionDataAnimation instead.")]
529 public Animation LoadBlendShapeAnimationFromBuffer(string jsonBuffer)
531 global::System.IntPtr cPtr = Interop.Model.LoadBlendShapeAnimationFromBuffer(SwigCPtr, jsonBuffer, jsonBuffer.Length);
532 Animation ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animation;
535 // Register new animation into Registry.
536 ret = new Animation(cPtr, true);
540 // We found matched NUI animation. Reduce cPtr reference count.
541 HandleRef handle = new HandleRef(this, cPtr);
542 Tizen.NUI.Interop.Animation.DeleteAnimation(handle);
543 handle = new HandleRef(null, IntPtr.Zero);
545 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
550 /// Generate animation by MotionData.
551 /// If there is no animatable item for MotionData, return null.
553 /// <param name="motionData">Source motion data.</param>
554 /// <returns>Generated animation from then given motion data, or null if there is no animatable item in <paramref name="motionData"/></returns>
555 /// <since_tizen> 11 </since_tizen>
556 public Animation GenerateMotionDataAnimation(MotionData motionData)
558 global::System.IntPtr cPtr = Interop.Model.GenerateMotionDataAnimation(SwigCPtr, MotionData.getCPtr(motionData));
559 Animation ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animation;
562 // Register new animation into Registry.
563 ret = new Animation(cPtr, true);
567 // We found matched NUI animation. Reduce cPtr reference count.
568 HandleRef handle = new HandleRef(this, cPtr);
569 Tizen.NUI.Interop.Animation.DeleteAnimation(handle);
570 handle = new HandleRef(null, IntPtr.Zero);
572 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
574 // It is possible if there is no animatable properties exist on inputed motionData.
575 // In this case, let we return null.
585 /// Set values from MotionData.
586 /// Note that this method doesn not apply KeyFrames animation.
587 /// If you want to apply the animation, please use <see cref="GenerateMotionDataAnimation(MotionData)"/> and play the result.
589 /// <param name="motionData">Source motion data.</param>
590 /// <since_tizen> 11 </since_tizen>
591 public void SetMotionData(MotionData motionData)
593 Interop.Model.SetMotionData(SwigCPtr, MotionData.getCPtr(motionData));
594 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
598 /// Sets whether this Model casts shadow or not.
599 /// If it is true, this model is drawn on Shadow Map.
600 /// Note: This method affects all of the child ModelNode.
601 /// However, same property of each child ModelNode can be changed respectively and it not changes parent's property.
603 /// <param name="castShadow">Whether this Model casts shadow or not.</param>
604 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
605 [EditorBrowsable(EditorBrowsableState.Never)]
606 public void CastShadow(bool castShadow)
608 Interop.Model.CastShadow(SwigCPtr, castShadow);
609 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
613 /// Retrieves whether the Model casts shadow or not for Light.
614 /// Note: IBL does not cast any shadow.
616 /// <returns>True if this model casts shadow.</returns>
617 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
618 [EditorBrowsable(EditorBrowsableState.Never)]
619 public bool IsShadowCasting()
621 var isShadowCasting = Interop.Model.IsShadowCasting(SwigCPtr);
622 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
623 return isShadowCasting;
627 /// Sets whether this Model receives shadow or not.
628 /// If it is true, shadows are drawn on this model.
629 /// Note: This method affects all of the child ModelNode.
630 /// However, same property of each child ModelNode can be changed respectively and it not changes parent's property.
632 /// <param name="receiveShadow">Whether this Model receives shadow or not.</param>
633 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
634 [EditorBrowsable(EditorBrowsableState.Never)]
635 public void ReceiveShadow(bool receiveShadow)
637 Interop.Model.ReceiveShadow(SwigCPtr, receiveShadow);
638 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
642 /// Retrieves whether the Model receives shadow or not for Light
643 /// If it is true, this model is drawn on Shadow Map.
645 /// <returns>True if this model receives shadow.</returns>
646 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
647 [EditorBrowsable(EditorBrowsableState.Never)]
648 public bool IsShadowReceiving()
650 var isShadowReceiving = Interop.Model.IsShadowReceiving(SwigCPtr);
651 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
652 return isShadowReceiving;
656 /// Retrieves model root Actor.
658 /// <returns>Root View of the model.</returns>
659 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
660 [EditorBrowsable(EditorBrowsableState.Never)]
661 private ModelNode GetModelRoot()
663 global::System.IntPtr cPtr = Interop.Model.GetModelRoot(SwigCPtr);
664 ModelNode ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as ModelNode;
667 // Store the value of PositionUsesAnchorPoint from dali object (Since View object automatically change PositionUsesPivotPoint value as false, we need to keep value.)
668 HandleRef handle = new HandleRef(this, cPtr);
670 // Use original value as 'true' if we got invalid ModelNode.
671 bool originalPositionUsesAnchorPoint = (cPtr == global::System.IntPtr.Zero || !Tizen.NUI.Interop.BaseHandle.HasBody(handle)) || Object.InternalGetPropertyBool(handle, View.Property.PositionUsesAnchorPoint);
672 handle = new HandleRef(null, IntPtr.Zero);
674 // Register new animatable into Registry.
675 ret = new ModelNode(cPtr, true);
678 ret.PositionUsesPivotPoint = originalPositionUsesAnchorPoint;
683 // We found matched NUI animatable. Reduce cPtr reference count.
684 HandleRef handle = new HandleRef(this, cPtr);
685 Tizen.NUI.Interop.BaseHandle.DeleteBaseHandle(handle);
686 handle = new HandleRef(null, IntPtr.Zero);
688 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
693 /// Set the ImageBasedLight ScaleFactor.
695 /// <param name="scaleFactor">Scale factor that controls light source intensity in [0.0f, 1.0f].</param>
696 private void SetImageBasedLightScaleFactor(float scaleFactor)
698 Interop.Model.SetImageBasedLightScaleFactor(SwigCPtr, scaleFactor);
699 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
703 /// Get the ImageBasedLight ScaleFactor.
705 /// <returns>ImageBasedLightScaleFactor that controls light source intensity.</returns>
706 private float GetImageBasedLightScaleFactor()
708 float scaleFactor = Interop.Model.GetImageBasedLightScaleFactor(SwigCPtr);
709 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
713 private void OnResourcesLoaded(object sender, EventArgs e)
715 if (!isBuilt && this.ModelRoot != null)
717 this.ModelRoot.Build();
719 this.modelPivotPoint.X = this.PivotPoint.X;
720 this.modelPivotPoint.Y = this.PivotPoint.Y;
721 this.modelPivotPoint.Z = this.PivotPoint.Z;
726 /// To make transitionSet instance be disposed.
728 protected override void Dispose(DisposeTypes type)
735 ResourcesLoaded -= OnResourcesLoaded;
740 /// Release swigCPtr.
742 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
743 [EditorBrowsable(EditorBrowsableState.Never)]
744 protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr)
746 Interop.Model.DeleteModel(swigCPtr);
750 private EventHandler<MeshHitEventArgs> meshHitEventHandler;
751 private MeshHitCallbackType meshHitCallback;
752 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
753 private delegate void MeshHitCallbackType(IntPtr motionData);
757 /// Contains arguments when MeshHitSignal called
759 [EditorBrowsable(EditorBrowsableState.Never)]
760 public class MeshHitEventArgs : EventArgs
762 private ModelNode modelNode;
765 /// ModelNode that's been hit
767 [EditorBrowsable(EditorBrowsableState.Never)]
768 public ModelNode ModelNode
782 /// EventHandler event.
783 /// It will be invoked when collider mesh is hit.
785 [EditorBrowsable(EditorBrowsableState.Never)]
786 public event EventHandler<MeshHitEventArgs> ColliderMeshHitted
790 if (meshHitEventHandler == null)
792 meshHitCallback = MeshHitCollision;
793 Interop.Model.MeshHitSignalConnect(SwigCPtr, meshHitCallback.ToHandleRef(this));
794 NDalicPINVOKE.ThrowExceptionIfExists();
796 meshHitEventHandler += value;
800 meshHitEventHandler -= value;
801 if (meshHitEventHandler == null && meshHitCallback != null)
803 Interop.Model.MeshHitSignalDisconnect(SwigCPtr, meshHitCallback.ToHandleRef(this));
804 NDalicPINVOKE.ThrowExceptionIfExists();
805 meshHitCallback = null;
810 private void MeshHitCollision(IntPtr modelNode)
812 if (meshHitEventHandler != null)
814 var args = new MeshHitEventArgs();
815 args.ModelNode = new ModelNode(modelNode, false);
816 meshHitEventHandler(this, args);