1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_NODE_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_NODE_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/actors/actor-enumerations.h>
23 #include <dali/public-api/actors/draw-mode.h>
24 #include <dali/public-api/common/set-wrapper.h>
25 #include <dali/public-api/math/quaternion.h>
26 #include <dali/public-api/math/math-utils.h>
27 #include <dali/public-api/math/vector3.h>
28 #include <dali/internal/common/message.h>
29 #include <dali/internal/update/common/animatable-property.h>
30 #include <dali/internal/update/common/property-owner.h>
31 #include <dali/internal/update/common/property-vector3.h>
32 #include <dali/internal/update/common/scene-graph-buffers.h>
33 #include <dali/internal/update/common/inherited-property.h>
34 #include <dali/integration-api/debug.h>
35 #include <dali/internal/update/nodes/node-declarations.h>
36 #include <dali/internal/update/node-attachments/node-attachment-declarations.h>
37 #include <dali/internal/render/renderers/render-data-provider.h>
45 // value types used by messages
46 template <> struct ParameterType< ColorMode > : public BasicType< ColorMode > {};
47 template <> struct ParameterType< PositionInheritanceMode > : public BasicType< PositionInheritanceMode > {};
48 template <> struct ParameterType< SizeMode > : public BasicType< SizeMode > {};
60 * Flag whether property has changed, during the Update phase.
62 enum NodePropertyFlags
65 TransformFlag = 0x001,
70 SortModifierFlag = 0x020,
71 ChildDeletedFlag = 0x040
74 static const int AllFlags = ( ChildDeletedFlag << 1 ) - 1; // all the flags
77 * Size is not inherited.
78 * VisibleFlag is inherited so that attachments can be synchronized with nodes after they become visible
80 static const int InheritedDirtyFlags = TransformFlag | VisibleFlag | ColorFlag | OverlayFlag;
82 // Flags which require the scene renderable lists to be updated
83 static const int RenderableUpdateFlags = TransformFlag | SortModifierFlag | ChildDeletedFlag;
86 * Node is the base class for all nodes in the Scene Graph.
87 * Each node provides a transformation which applies to the node and its children.
88 * Node data is double-buffered. This allows an update thread to modify node data, without interferring
89 * with another thread reading the values from the previous update traversal.
91 class Node : public PropertyOwner, public RenderDataProvider
96 static const PositionInheritanceMode DEFAULT_POSITION_INHERITANCE_MODE;
97 static const ColorMode DEFAULT_COLOR_MODE;
98 static const SizeMode DEFAULT_SIZE_MODE;
103 * Construct a new Node.
113 * When a Node is marked "active" it has been disconnected, but its properties have been modified.
114 * @note An inactive Node will be skipped during the UpdateManager ResetProperties stage.
115 * @param[in] isActive True if the Node is active.
117 void SetActive( bool isActive )
119 mIsActive = isActive;
123 * Query whether the Node is active.
124 * @return True if the Node is active.
126 bool IsActive() const
132 * Called during UpdateManager::DestroyNode shortly before Node is destroyed.
139 * Query whether the node is a layer.
140 * @return True if the node is a layer.
144 return (GetLayer() != NULL);
148 * Convert a node to a layer.
149 * @return A pointer to the layer, or NULL.
151 virtual Layer* GetLayer()
159 * Attach an object to this Node; This should only be done by UpdateManager::AttachToNode.
160 * @pre The Node does not already have an attachment.
161 * @param[in] attachment The object to attach.
163 void Attach( NodeAttachment& attachment );
166 * Query the node if it has an attachment.
167 * @return True if it has an attachment.
169 bool HasAttachment() const
175 * Retreive the object attached to this node.
176 * @return The attachment.
178 NodeAttachment& GetAttachment() const
183 // Containment methods
186 * Query whether a node is the root node. Root nodes cannot have a parent node.
187 * A node becomes a root node, when it is installed by UpdateManager.
188 * @return True if the node is a root node.
196 * Set whether a node is the root node. Root nodes cannot have a parent node.
197 * This method should only be called by UpdateManager.
198 * @pre When isRoot is true, the node must not have a parent.
199 * @param[in] isRoot Whether the node is now a root node.
201 void SetRoot(bool isRoot);
204 * Retrieve the parent of a Node.
205 * @return The parent node, or NULL if the Node has not been added to the scene-graph.
213 * Retrieve the parent of a Node.
214 * @return The parent node, or NULL if the Node has not been added to the scene-graph.
216 const Node* GetParent() const
222 * Connect a node to the scene-graph.
223 * @pre A node cannot be added to itself.
224 * @pre The parent node is connected to the scene-graph.
225 * @pre The childNode does not already have a parent.
226 * @pre The childNode is not a root node.
227 * @param[in] childNode The child to add.
228 * @param[in] index to insert at, if not supplied or -1 it will be appended
231 void ConnectChild( Node* childNode, int index = -1);
234 * Disconnect a child (& its children) from the scene-graph.
235 * @pre childNode is a child of this Node.
236 * @param[in] updateBufferIndex The current update buffer index.
237 * @param[in] childNode The node to disconnect.
238 * @param[in] connectedNodes Disconnected Node attachments should be removed from here.
239 * @param[in] disconnectedNodes Disconnected Node attachments should be added here.
241 void DisconnectChild( BufferIndex updateBufferIndex, Node& childNode, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes );
244 * Retrieve the children a Node.
245 * @return The container of children.
247 const NodeContainer& GetChildren() const
253 * Retrieve the children a Node.
254 * @return The container of children.
256 NodeContainer& GetChildren()
264 * Flag that one of the node values has changed in the current frame.
265 * @param[in] flag The flag to set.
267 void SetDirtyFlag(NodePropertyFlags flag)
273 * Flag that all of the node values are dirty.
275 void SetAllDirtyFlags()
277 mDirtyFlags = AllFlags;
281 * Query whether a node is dirty.
282 * @return The dirty flags
284 int GetDirtyFlags() const;
287 * Query whether a node is clean.
288 * @return True if the node is clean.
292 return ( NothingFlag == GetDirtyFlags() );
296 * Retrieve the parent-origin of the node.
297 * @return The parent-origin.
299 const Vector3& GetParentOrigin() const
301 return mParentOrigin.mValue;
305 * Sets both the local & base parent-origins of the node.
306 * @param[in] origin The new local & base parent-origins.
308 void SetParentOrigin(const Vector3& origin)
310 mParentOrigin.mValue = origin;
311 mParentOrigin.OnSet();
315 * Retrieve the anchor-point of the node.
316 * @return The anchor-point.
318 const Vector3& GetAnchorPoint() const
320 return mAnchorPoint.mValue;
324 * Sets both the local & base anchor-points of the node.
325 * @param[in] anchor The new local & base anchor-points.
327 void SetAnchorPoint(const Vector3& anchor)
329 mAnchorPoint.mValue = anchor;
330 mAnchorPoint.OnSet();
334 * Retrieve the local position of the node, relative to its parent.
335 * @param[in] bufferIndex The buffer to read from.
336 * @return The local position.
338 const Vector3& GetPosition(BufferIndex bufferIndex) const
340 return mPosition[bufferIndex];
344 * Sets both the local & base positions of the node.
345 * @param[in] updateBufferIndex The current update buffer index.
346 * @param[in] position The new local & base position.
348 void BakePosition(BufferIndex updateBufferIndex, const Vector3& position)
350 mPosition.Bake( updateBufferIndex, position );
354 * Sets the world of the node derived from the position of all its parents.
355 * @param[in] updateBufferIndex The current update buffer index.
356 * @param[in] position The world position.
358 void SetWorldPosition( BufferIndex updateBufferIndex, const Vector3& position )
360 mWorldPosition.Set( updateBufferIndex, position );
364 * Sets the position of the node derived from the position of all its parents.
365 * This method should only be called when the parent's world position is up-to-date.
366 * With a non-central anchor-point, the local orientation and scale affects the world position.
367 * Therefore the world orientation & scale must be updated before the world position.
368 * @pre The node has a parent.
369 * @param[in] updateBufferIndex The current update buffer index.
371 void InheritWorldPosition(BufferIndex updateBufferIndex)
373 DALI_ASSERT_DEBUG(mParent != NULL);
375 switch( mPositionInheritanceMode )
377 case INHERIT_PARENT_POSITION : ///@see Dali::PositionInheritanceMode for how these modes are expected to work
379 Vector3 finalPosition(-0.5f, -0.5f, -0.5f);
381 finalPosition += mParentOrigin.mValue;
382 finalPosition *= mParent->GetSize(updateBufferIndex);
383 finalPosition += mPosition[updateBufferIndex];
384 finalPosition *= mParent->GetWorldScale(updateBufferIndex);
385 const Quaternion& parentWorldOrientation = mParent->GetWorldOrientation(updateBufferIndex);
386 if(!parentWorldOrientation.IsIdentity())
388 finalPosition *= parentWorldOrientation;
391 // check if a node needs to be offsetted locally (only applies when AnchorPoint is not central)
392 // dont use operator== as that does a slower comparison (and involves function calls)
393 Vector3 localOffset(0.5f, 0.5f, 0.5f); // AnchorPoint::CENTER
394 localOffset -= mAnchorPoint.mValue;
396 if( ( fabsf( localOffset.x ) >= Math::MACHINE_EPSILON_0 ) ||
397 ( fabsf( localOffset.y ) >= Math::MACHINE_EPSILON_0 ) ||
398 ( fabsf( localOffset.z ) >= Math::MACHINE_EPSILON_0 ) )
400 localOffset *= mSize[updateBufferIndex];
402 Vector3 scale = mWorldScale[updateBufferIndex];
403 if(GetTransmitGeometryScaling())
405 // Remove geometry scaling to get back to actor scale
406 scale /= mGeometryScale;
408 // Also pick up sign of local scale
409 if (mScale[updateBufferIndex].x < 0.0f)
413 if (mScale[updateBufferIndex].y < 0.0f)
417 if (mScale[updateBufferIndex].z < 0.0f)
422 // If the anchor-point is not central, then position is affected by the local orientation & scale
423 localOffset *= scale;
424 const Quaternion& localWorldOrientation = mWorldOrientation[updateBufferIndex];
425 if(!localWorldOrientation.IsIdentity())
427 localOffset *= localWorldOrientation;
429 finalPosition += localOffset;
432 finalPosition += mParent->GetWorldPosition(updateBufferIndex);
433 mWorldPosition.Set( updateBufferIndex, finalPosition );
436 case USE_PARENT_POSITION_PLUS_LOCAL_POSITION :
438 // copy parents position plus local transform
439 mWorldPosition.Set( updateBufferIndex, mParent->GetWorldPosition(updateBufferIndex) + mPosition[updateBufferIndex] );
442 case USE_PARENT_POSITION :
444 // copy parents position
445 mWorldPosition.Set( updateBufferIndex, mParent->GetWorldPosition(updateBufferIndex) );
448 case DONT_INHERIT_POSITION :
450 // use local position as world position
451 mWorldPosition.Set( updateBufferIndex, mPosition[updateBufferIndex] );
458 * Copies the previous inherited position, if this changed in the previous frame.
459 * This method should be called instead of InheritWorldPosition i.e. if the inherited position
460 * does not need to be recalculated in the current frame.
461 * @param[in] updateBufferIndex The current update buffer index.
463 void CopyPreviousWorldPosition( BufferIndex updateBufferIndex )
465 mWorldPosition.CopyPrevious( updateBufferIndex );
469 * Retrieve the position of the node derived from the position of all its parents.
470 * @return The world position.
472 const Vector3& GetWorldPosition( BufferIndex bufferIndex ) const
474 return mWorldPosition[bufferIndex];
478 * Set the position inheritance mode.
479 * @see Dali::Actor::PositionInheritanceMode
480 * @param[in] mode The new position inheritance mode.
482 void SetPositionInheritanceMode( PositionInheritanceMode mode )
484 mPositionInheritanceMode = mode;
486 SetDirtyFlag(TransformFlag);
490 * @return The position inheritance mode.
492 PositionInheritanceMode GetPositionInheritanceMode() const
494 return mPositionInheritanceMode;
498 * Retrieve the local orientation of the node, relative to its parent.
499 * @param[in] bufferIndex The buffer to read from.
500 * @return The local orientation.
502 const Quaternion& GetOrientation(BufferIndex bufferIndex) const
504 return mOrientation[bufferIndex];
508 * Sets both the local & base orientations of the node.
509 * @param[in] updateBufferIndex The current update buffer index.
510 * @param[in] orientation The new local & base orientation.
512 void BakeOrientation(BufferIndex updateBufferIndex, const Quaternion& orientation)
514 mOrientation.Bake( updateBufferIndex, orientation );
518 * Sets the orientation of the node derived from the rotation of all its parents.
519 * @param[in] updateBufferIndex The current update buffer index.
520 * @param[in] orientation The world orientation.
522 void SetWorldOrientation( BufferIndex updateBufferIndex, const Quaternion& orientation )
524 mWorldOrientation.Set( updateBufferIndex, orientation );
528 * Sets the orientation of the node derived from the rotation of all its parents.
529 * This method should only be called when the parents world orientation is up-to-date.
530 * @pre The node has a parent.
531 * @param[in] updateBufferIndex The current update buffer index.
533 void InheritWorldOrientation( BufferIndex updateBufferIndex )
535 DALI_ASSERT_DEBUG(mParent != NULL);
537 const Quaternion& localOrientation = mOrientation[updateBufferIndex];
539 if(localOrientation.IsIdentity())
541 mWorldOrientation.Set( updateBufferIndex, mParent->GetWorldOrientation(updateBufferIndex) );
545 Quaternion finalOrientation( mParent->GetWorldOrientation(updateBufferIndex) );
546 finalOrientation *= localOrientation;
547 mWorldOrientation.Set( updateBufferIndex, finalOrientation );
552 * Copies the previous inherited orientation, if this changed in the previous frame.
553 * This method should be called instead of InheritWorldOrientation i.e. if the inherited orientation
554 * does not need to be recalculated in the current frame.
555 * @param[in] updateBufferIndex The current update buffer index.
557 void CopyPreviousWorldOrientation( BufferIndex updateBufferIndex )
559 mWorldOrientation.CopyPrevious( updateBufferIndex );
563 * Retrieve the orientation of the node derived from the rotation of all its parents.
564 * @param[in] bufferIndex The buffer to read from.
565 * @return The world rotation.
567 const Quaternion& GetWorldOrientation( BufferIndex bufferIndex ) const
569 return mWorldOrientation[bufferIndex];
573 * Set whether the Node inherits orientation.
574 * @param[in] inherit True if the parent orientation is inherited.
576 void SetInheritOrientation(bool inherit)
578 if (inherit != mInheritOrientation)
580 mInheritOrientation = inherit;
582 SetDirtyFlag(TransformFlag);
587 * Query whether the node inherits orientation from its parent.
588 * @return True if the parent orientation is inherited.
590 bool IsOrientationInherited() const
592 return mInheritOrientation;
596 * @brief Defines how a child actor's size is affected by its parent's size.
597 * @param[in] mode The size relative to parent mode to use.
599 void SetSizeMode( SizeMode mode )
601 if ( mode != mSizeMode )
605 SetDirtyFlag( TransformFlag );
610 * Query how the child actor's size is affected by its parent's size.
611 * @return The size relative to parent mode in use.
613 SizeMode GetSizeMode() const
619 * Sets the factor of the parents size used for the child actor.
620 * Note: Only used for certain SizeModes.
621 * @param[in] factor The vector to multiply the parents size by to get the childs size.
623 void SetSizeModeFactor( const Vector3& factor )
625 mSizeModeFactor = factor;
627 SetDirtyFlag( TransformFlag );
631 * Gets the factor of the parents size used for the child actor.
632 * Note: Only used for certain SizeModes.
633 * @return The vector being used to multiply the parents size by to get the childs size.
635 const Vector3& GetSizeModeFactor() const
637 return mSizeModeFactor;
641 * Set the initial volume of the node. Used for calculating geometry scaling
642 * as the node size is changed when transmitGeometryScaling is set to true.
644 * This property is not animatable.
646 * @param[in] volume The initial volume of this nodes meshes & children
648 void SetInitialVolume( const Vector3& volume )
650 mInitialVolume = volume;
651 SetDirtyFlag(SizeFlag);
655 * Get the initial volume. Used for calculating geometry scaling
656 * when TransmitGeometryScaling is true (i.e., the scaling is baked
657 * into the node tranform)
659 * @return The initial volume of this node and children.
661 Vector3 GetInitialVolume()
663 return mInitialVolume;
667 * Sets whether the geometry scaling should be applied to the node
668 * (In which case, set the initial scale using SetInitialVolume()).
670 * If it is applied to the node, then the attachments are not scaled,
671 * as the scaling is then already baked into the node transform.
673 * @param[in] transmitGeometryScaling true if scaling is to be applied
676 void SetTransmitGeometryScaling(bool transmitGeometryScaling)
678 mTransmitGeometryScaling = transmitGeometryScaling;
679 SetDirtyFlag(SizeFlag);
683 * Find out whether the node allows geometry scaling to be transmitted to its children.
684 * @return true if transmitted.
686 bool GetTransmitGeometryScaling() const
688 return mTransmitGeometryScaling;
692 * Retrieve the local scale of the node, relative to its parent.
693 * @param[in] bufferIndex The buffer to read from.
694 * @return The local scale.
696 const Vector3& GetScale(BufferIndex bufferIndex) const
698 return mScale[bufferIndex];
702 * Sets the scale of the node derived from the scale of all its parents and a pre-scale
703 * @param[in] updateBufferIndex The current update buffer index.
704 * @param[in] scale The world scale.
706 void SetWorldScale(BufferIndex updateBufferIndex, const Vector3& scale)
708 mWorldScale.Set( updateBufferIndex, mGeometryScale * scale );
712 * Sets the scale of the node derived from the scale of all its parents and a pre-scale.
713 * This method should only be called when the parents world scale is up-to-date.
714 * @pre The node has a parent.
715 * @param[in] updateBufferIndex The current update buffer index.
717 void InheritWorldScale(BufferIndex updateBufferIndex)
719 DALI_ASSERT_DEBUG(mParent != NULL);
721 mWorldScale.Set( updateBufferIndex, mParent->GetWorldScale(updateBufferIndex) * mGeometryScale * mScale[updateBufferIndex] );
725 * Copies the previous inherited scale, if this changed in the previous frame.
726 * This method should be called instead of InheritWorldScale i.e. if the inherited scale
727 * does not need to be recalculated in the current frame.
728 * @param[in] updateBufferIndex The current update buffer index.
730 void CopyPreviousWorldScale( BufferIndex updateBufferIndex )
732 mWorldScale.CopyPrevious( updateBufferIndex );
736 * Retrieve the scale of the node derived from the scale of all its parents.
737 * @param[in] bufferIndex The buffer to read from.
738 * @return The world scale.
740 const Vector3& GetWorldScale( BufferIndex bufferIndex ) const
742 return mWorldScale[bufferIndex];
746 * Set whether the Node inherits scale.
747 * @param inherit True if the Node inherits scale.
749 void SetInheritScale( bool inherit )
751 if( inherit != mInheritScale )
753 mInheritScale = inherit;
755 SetDirtyFlag( TransformFlag );
760 * Query whether the Node inherits scale.
761 * @return if scale is inherited
763 bool IsScaleInherited() const
765 return mInheritScale;
769 * Sets a geometry scale, calculated when TransmitGeometryScaling is true.
770 * Must only be used from render thread.
771 * @param[in] geometryScale The geometry scale value
773 void SetGeometryScale(Vector3 geometryScale)
775 mGeometryScale = geometryScale;
777 SetDirtyFlag( TransformFlag );
781 * Retrieve the geometry scale, calculated when TransmitGeometryScaling is true.
782 * @return The geometry scale value.
784 const Vector3& GetGeometryScale() const
786 return mGeometryScale;
790 * Copies the previously used size, if this changed in the previous frame.
791 * @param[in] updateBufferIndex The current update buffer index.
793 void CopyPreviousSize( BufferIndex updateBufferIndex )
795 SetSize( updateBufferIndex, GetSize( 1u - updateBufferIndex ) );
799 * Retrieve the visibility of the node.
800 * @param[in] bufferIndex The buffer to read from.
801 * @return True if the node is visible.
803 bool IsVisible(BufferIndex bufferIndex) const
805 return mVisible[bufferIndex];
809 * Retrieves whether a node is fully visible.
810 * A node is fully visible if is visible and all its ancestors are visible.
811 * @param[in] updateBufferIndex The current update buffer index.
812 * @return True if the node is fully visible.
814 bool IsFullyVisible( BufferIndex updateBufferIndex ) const;
817 * Retrieve the opacity of the node.
818 * @param[in] bufferIndex The buffer to read from.
819 * @return The opacity.
821 float GetOpacity(BufferIndex bufferIndex) const
823 return mColor[bufferIndex].a;
827 * Retrieve the color of the node.
828 * @param[in] bufferIndex The buffer to read from.
831 const Vector4& GetColor(BufferIndex bufferIndex) const
833 return mColor[bufferIndex];
837 * Sets the color of the node derived from the color of all its parents.
838 * @param[in] color The world color.
839 * @param[in] updateBufferIndex The current update buffer index.
841 void SetWorldColor(const Vector4& color, BufferIndex updateBufferIndex)
843 mWorldColor.Set( updateBufferIndex, color );
847 * Sets the color of the node derived from the color of all its parents.
848 * This method should only be called when the parents world color is up-to-date.
849 * @pre The node has a parent.
850 * @param[in] updateBufferIndex The current update buffer index.
852 void InheritWorldColor( BufferIndex updateBufferIndex )
854 DALI_ASSERT_DEBUG(mParent != NULL);
857 if( mColorMode == USE_OWN_MULTIPLY_PARENT_ALPHA )
859 const Vector4& ownColor = mColor[updateBufferIndex];
860 mWorldColor.Set( updateBufferIndex, ownColor.r, ownColor.g, ownColor.b, ownColor.a * mParent->GetWorldColor(updateBufferIndex).a );
862 else if( mColorMode == USE_OWN_MULTIPLY_PARENT_COLOR )
864 mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) * mColor[updateBufferIndex] );
866 else if( mColorMode == USE_PARENT_COLOR )
868 mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) );
870 else // USE_OWN_COLOR
872 mWorldColor.Set( updateBufferIndex, mColor[updateBufferIndex] );
877 * Copies the previous inherited scale, if this changed in the previous frame.
878 * This method should be called instead of InheritWorldScale i.e. if the inherited scale
879 * does not need to be recalculated in the current frame.
880 * @param[in] updateBufferIndex The current update buffer index.
882 void CopyPreviousWorldColor( BufferIndex updateBufferIndex )
884 mWorldColor.CopyPrevious( updateBufferIndex );
888 * Retrieve the color of the node, possibly derived from the color
889 * of all its parents, depending on the value of mColorMode.
890 * @param[in] bufferIndex The buffer to read from.
891 * @return The world color.
893 const Vector4& GetWorldColor(BufferIndex bufferIndex) const
895 return mWorldColor[bufferIndex];
899 * Set the color mode. This specifies whether the Node uses its own color,
900 * or inherits its parent color.
901 * @param[in] colorMode The new color mode.
903 void SetColorMode(ColorMode colorMode)
905 mColorMode = colorMode;
907 SetDirtyFlag(ColorFlag);
911 * Retrieve the color mode.
912 * @return The color mode.
914 ColorMode GetColorMode() const
920 * Sets the size of the node.
921 * @param[in] bufferIndex The buffer to write to.
922 * @param[in] size The size to write.
924 void SetSize( BufferIndex bufferIndex, const Vector3& size )
926 mSize[bufferIndex] = size;
930 * Retrieve the size of the node.
931 * @param[in] bufferIndex The buffer to read from.
934 const Vector3& GetSize(BufferIndex bufferIndex) const
936 return mSize[bufferIndex];
940 * Set the world-matrix of a node, with scale + rotation + translation.
941 * Scale and rotation are centered at the origin.
942 * Translation is applied independently of the scale or rotatation axis.
943 * @param[in] updateBufferIndex The current update buffer index.
944 * @param[in] scale The scale.
945 * @param[in] rotation The rotation.
946 * @param[in] translation The translation.
948 void SetWorldMatrix( BufferIndex updateBufferIndex, const Vector3& scale, const Quaternion& rotation, const Vector3& translation )
950 mWorldMatrix.Get( updateBufferIndex ).SetTransformComponents( scale, rotation, translation );
951 mWorldMatrix.SetDirty( updateBufferIndex );
955 * Retrieve the cached world-matrix of a node.
956 * @param[in] bufferIndex The buffer to read from.
957 * @return The world-matrix.
959 const Matrix& GetWorldMatrix( BufferIndex bufferIndex ) const
961 return mWorldMatrix[ bufferIndex ];
965 * Copy previous frames world matrix
966 * @param[in] updateBufferIndex The current update buffer index.
968 void CopyPreviousWorldMatrix( BufferIndex updateBufferIndex )
970 mWorldMatrix.CopyPrevious( updateBufferIndex );
974 * Mark the node as exclusive to a single RenderTask.
975 * @param[in] renderTask The render-task, or NULL if the Node is not exclusive to a single RenderTask.
977 void SetExclusiveRenderTask( RenderTask* renderTask )
979 mExclusiveRenderTask = renderTask;
983 * Query whether the node is exclusive to a single RenderTask.
984 * @return The render-task, or NULL if the Node is not exclusive to a single RenderTask.
986 RenderTask* GetExclusiveRenderTask() const
988 return mExclusiveRenderTask;
992 * Set how the Node and its children should be drawn; see Dali::Actor::SetDrawMode() for more details.
993 * @param[in] drawMode The new draw-mode to use.
995 void SetDrawMode( const DrawMode::Type& drawMode )
997 mDrawMode = drawMode;
1001 * Returns whether node is an overlay or not.
1002 * @return True if node is an overlay, false otherwise.
1004 DrawMode::Type GetDrawMode() const
1010 * Equality operator, checks for identity, not values.
1013 bool operator==( const Node* rhs ) const
1023 * Set the inhibit local transform flag.@n
1024 * Setting this flag will stop the node's local transform (position, scale and orientation)
1025 * being applied on top of its parents transformation.
1026 * @param[in] flag When true, local transformation is inhibited when calculating the world matrix.
1028 void SetInhibitLocalTransform( bool flag )
1030 SetDirtyFlag( TransformFlag );
1031 mInhibitLocalTransform = flag;
1035 * Get the inhibit local transform flag.@n
1036 * See @ref SetInhibitLocalTransform
1037 * @result A flag, when true, local transformation is inhibited when calculating the world matrix.
1039 bool GetInhibitLocalTransform() const
1041 return mInhibitLocalTransform;
1047 * Set the parent of a Node.
1048 * @param[in] parentNode the new parent.
1050 void SetParent(Node& parentNode);
1053 * Protected constructor; See also Node::New()
1057 private: // from RenderDataProvider
1060 * @copydoc RenderDataProvider::GetModelMatrix
1062 virtual const Matrix& GetModelMatrix( unsigned int bufferId )
1064 return GetWorldMatrix( bufferId );
1068 * @copydoc RenderDataProvider::GetRenderColor
1070 virtual const Vector4& GetRenderColor( unsigned int bufferId )
1072 return GetWorldColor( bufferId );
1081 Node& operator=(const Node& rhs);
1084 * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
1086 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex );
1089 * Recursive helper to disconnect a Node and its children.
1090 * Disconnected Nodes have no parent or children.
1091 * @param[in] updateBufferIndex The current update buffer index.
1092 * @param[in] connectedNodes Disconnected Node attachments should be removed from here.
1093 * @param[in] disconnectedNodes Disconnected Node attachments should be added here.
1095 void RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes );
1097 public: // Default properties
1099 PropertyVector3 mParentOrigin; ///< Local transform; the position is relative to this. Sets the TransformFlag dirty when changed
1100 PropertyVector3 mAnchorPoint; ///< Local transform; local center of rotation. Sets the TransformFlag dirty when changed
1102 AnimatableProperty<Vector3> mSize; ///< Size is provided for layouting
1103 AnimatableProperty<Vector3> mPosition; ///< Local transform; distance between parent-origin & anchor-point
1104 AnimatableProperty<Quaternion> mOrientation; ///< Local transform; rotation relative to parent node
1105 AnimatableProperty<Vector3> mScale; ///< Local transform; scale relative to parent node
1106 AnimatableProperty<bool> mVisible; ///< Visibility can be inherited from the Node hierachy
1107 AnimatableProperty<Vector4> mColor; ///< Color can be inherited from the Node hierarchy
1109 // Inherited properties; read-only from public API
1111 InheritedVector3 mWorldPosition; ///< Full inherited position
1112 InheritedQuaternion mWorldOrientation; ///< Full inherited orientation
1113 InheritedVector3 mWorldScale; ///< Full inherited scale
1114 InheritedMatrix mWorldMatrix; ///< Full inherited world matrix
1115 InheritedColor mWorldColor; ///< Full inherited color
1119 Node* mParent; ///< Pointer to parent node (a child is owned by its parent)
1120 RenderTask* mExclusiveRenderTask; ///< Nodes can be marked as exclusive to a single RenderTask
1122 NodeAttachmentOwner mAttachment; ///< Optional owned attachment
1123 NodeContainer mChildren; ///< Container of children; not owned
1125 Vector3 mGeometryScale; ///< Applied before calculating world transform.
1126 Vector3 mInitialVolume; ///< Initial volume... TODO - need a better name.
1127 Vector3 mSizeModeFactor; ///< Factor of parent size. Used for certain SizeModes.
1129 // flags, compressed to bitfield
1130 int mDirtyFlags:10; ///< A composite set of flags for each of the Node properties
1132 bool mIsRoot:1; ///< True if the node cannot have a parent
1133 bool mInheritOrientation:1; ///< Whether the parent's orientation should be inherited.
1134 bool mInheritScale:1; ///< Whether the parent's scale should be inherited.
1135 bool mTransmitGeometryScaling:1; ///< Whether geometry scaling should be applied to world transform.
1136 bool mInhibitLocalTransform:1; ///< whether local transform should be applied.
1137 bool mIsActive:1; ///< When a Node is marked "active" it has been disconnected, and its properties have not been modified
1139 DrawMode::Type mDrawMode:2; ///< How the Node and its children should be drawn
1140 PositionInheritanceMode mPositionInheritanceMode:2;///< Determines how position is inherited, 2 bits is enough
1141 ColorMode mColorMode:2; ///< Determines whether mWorldColor is inherited, 2 bits is enough
1142 SizeMode mSizeMode:2; ///< Determines how the actors parent affects the actors size.
1144 // Changes scope, should be at end of class
1145 DALI_LOG_OBJECT_STRING_DECLARATION;
1148 // Messages for Node
1150 inline void SetInheritOrientationMessage( EventThreadServices& eventThreadServices, const Node& node, bool inherit )
1152 typedef MessageValue1< Node, bool > LocalType;
1154 // Reserve some memory inside the message queue
1155 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1157 // Construct message in the message queue memory; note that delete should not be called on the return value
1158 new (slot) LocalType( &node, &Node::SetInheritOrientation, inherit );
1161 inline void SetSizeModeMessage( EventThreadServices& eventThreadServices, const Node& node, SizeMode mode )
1163 typedef MessageValue1< Node, SizeMode > LocalType;
1165 // Reserve some memory inside the message queue
1166 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1168 // Construct message in the message queue memory; note that delete should not be called on the return value
1169 new (slot) LocalType( &node, &Node::SetSizeMode, mode );
1172 inline void SetSizeModeFactorMessage( EventThreadServices& eventThreadServices, const Node& node, const Vector3& factor )
1174 typedef MessageValue1< Node, Vector3 > LocalType;
1176 // Reserve some memory inside the message queue
1177 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1179 // Construct message in the message queue memory; note that delete should not be called on the return value
1180 new (slot) LocalType( &node, &Node::SetSizeModeFactor, factor );
1183 inline void SetInitialVolumeMessage( EventThreadServices& eventThreadServices, const Node& node, const Vector3& initialVolume )
1185 typedef MessageValue1< Node, Vector3 > LocalType;
1187 // Reserve some memory inside the message queue
1188 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1190 // Construct message in the message queue memory; note that delete should not be called on the return value
1191 new (slot) LocalType( &node, &Node::SetInitialVolume, initialVolume );
1194 inline void SetTransmitGeometryScalingMessage( EventThreadServices& eventThreadServices, const Node& node, bool transmitGeometryScaling )
1196 typedef MessageValue1< Node, bool > LocalType;
1198 // Reserve some memory inside the message queue
1199 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1201 // Construct message in the message queue memory; note that delete should not be called on the return value
1202 new (slot) LocalType( &node, &Node::SetTransmitGeometryScaling, transmitGeometryScaling );
1205 inline void SetParentOriginMessage( EventThreadServices& eventThreadServices, const Node& node, const Vector3& origin )
1207 typedef MessageValue1< Node, Vector3 > LocalType;
1209 // Reserve some memory inside the message queue
1210 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1212 // Construct message in the message queue memory; note that delete should not be called on the return value
1213 new (slot) LocalType( &node, &Node::SetParentOrigin, origin );
1216 inline void SetAnchorPointMessage( EventThreadServices& eventThreadServices, const Node& node, const Vector3& anchor )
1218 typedef MessageValue1< Node, Vector3 > LocalType;
1220 // Reserve some memory inside the message queue
1221 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1223 // Construct message in the message queue memory; note that delete should not be called on the return value
1224 new (slot) LocalType( &node, &Node::SetAnchorPoint, anchor );
1227 inline void SetPositionInheritanceModeMessage( EventThreadServices& eventThreadServices, const Node& node, PositionInheritanceMode mode )
1229 typedef MessageValue1< Node, PositionInheritanceMode > LocalType;
1231 // Reserve some memory inside the message queue
1232 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1234 // Construct message in the message queue memory; note that delete should not be called on the return value
1235 new (slot) LocalType( &node, &Node::SetPositionInheritanceMode, mode );
1238 inline void SetInheritScaleMessage( EventThreadServices& eventThreadServices, const Node& node, bool inherit )
1240 typedef MessageValue1< Node, bool > LocalType;
1242 // Reserve some memory inside the message queue
1243 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1245 // Construct message in the message queue memory; note that delete should not be called on the return value
1246 new (slot) LocalType( &node, &Node::SetInheritScale, inherit );
1249 inline void SetColorModeMessage( EventThreadServices& eventThreadServices, const Node& node, ColorMode colorMode )
1251 typedef MessageValue1< Node, ColorMode > LocalType;
1253 // Reserve some memory inside the message queue
1254 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1256 // Construct message in the message queue memory; note that delete should not be called on the return value
1257 new (slot) LocalType( &node, &Node::SetColorMode, colorMode );
1260 inline void SetDrawModeMessage( EventThreadServices& eventThreadServices, const Node& node, DrawMode::Type drawMode )
1262 typedef MessageValue1< Node, DrawMode::Type > LocalType;
1264 // Reserve some memory inside the message queue
1265 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1267 // Construct message in the message queue memory; note that delete should not be called on the return value
1268 new (slot) LocalType( &node, &Node::SetDrawMode, drawMode );
1271 } // namespace SceneGraph
1273 } // namespace Internal
1277 #endif // __DALI_INTERNAL_SCENE_GRAPH_NODE_H_