1 #ifndef TRANSFORM_MANAGER_PROPERTY_H_
2 #define TRANSFORM_MANAGER_PROPERTY_H_
5 * Copyright (c) 2020 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.
21 #include <dali/internal/update/manager/transform-manager.h>
22 #include <dali/internal/update/common/animatable-property.h>
32 struct TransformManagerPropertyHandler : public AnimatablePropertyBase
37 TransformManagerPropertyHandler()
39 mId( INVALID_TRANSFORM_ID )
43 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
45 Dali::Property::Type GetType() const override = 0;
48 * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
50 virtual T& Get( BufferIndex bufferIndex ) = 0;
53 * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
55 virtual const T& Get( BufferIndex bufferIndex ) const = 0;
58 * @copydoc Dali::PropertyInput::GetVector3()
60 const Vector3& GetVector3( BufferIndex bufferIndex ) const override{ return Vector3::ZERO; }
63 * Retrieve a component of property
64 * @param[in] component The component of the property
66 virtual const float& GetFloatComponent(uint32_t component) const
68 DALI_ASSERT_DEBUG( 0 && "Invalid call");
70 static const float value = 0.0f;
75 * Set the property value. This will only persist for the current frame; the property
76 * will be reset with the base value, at the beginning of the next frame.
77 * @param[in] bufferIndex Not used
78 * @param[in] value The new property value.
80 virtual void Set(BufferIndex bufferIndex, const T& value) = 0;
83 * Change a component of property
84 * @param[in] value The new value of the component
85 * @param[in] component The component of the property
87 virtual void SetFloatComponent( float value, uint32_t component){}
90 * @copydoc Dali::AnimatableProperty::Bake()
92 virtual void Bake(BufferIndex bufferIndex, const T& value) = 0;
95 * Bake a component of a property
96 * @param[in] value The new value of the component
97 * @param[in] component The component of the property
99 virtual void BakeFloatComponent( float value, uint32_t component){}
102 * @copydoc Dali::AnimatableProperty::BakeX()
104 virtual void BakeX(BufferIndex bufferIndex, float value){}
107 * @copydoc Dali::AnimatableProperty::BakeY()
109 virtual void BakeY(BufferIndex bufferIndex, float value){}
112 * @copydoc Dali::AnimatableProperty::BakeZ()
114 virtual void BakeZ(BufferIndex bufferIndex, float value){}
117 * @copydoc Dali::AnimatableProperty::BakeRelative()
119 virtual void BakeRelative(BufferIndex bufferIndex, const T& value) = 0;
122 * @copydoc Dali::AnimatableProperty::BakeRelativeMultiply()
124 virtual void BakeRelativeMultiply(BufferIndex bufferIndex, const T& value){};
127 * @copydoc Dali::AnimatableProperty::ResetToBaseValue()
129 void ResetToBaseValue(BufferIndex updateBufferIndex) override{}
132 * @copydoc Dali::AnimatableProperty::IsClean()
134 bool IsClean() const override{ return false; }
137 * Initializes the property
138 * @param[in] transformManager Pointer to the transform manager
139 * @param[in] Id of the transformation the property is associated with
141 void Initialize( TransformManager* transformManager, TransformId id )
143 mTxManager = transformManager;
148 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
150 bool IsTransformManagerProperty() const override
155 TransformManager* mTxManager;
159 struct TransformManagerPropertyVector3 : public TransformManagerPropertyHandler<Vector3>
162 TransformManagerPropertyVector3(TransformManagerProperty property)
163 :TransformManagerPropertyHandler(),
164 mProperty( property )
167 Dali::Property::Type GetType() const override
169 return Dali::PropertyTypes::Get<Vector3>();
172 Vector3& Get( BufferIndex bufferIndex ) override
174 return mTxManager->GetVector3PropertyValue( mId, mProperty );
177 const Vector3& Get( BufferIndex bufferIndex ) const override
179 const TransformManager* txManager = mTxManager;
180 return txManager->GetVector3PropertyValue( mId, mProperty );
183 const Vector3& GetVector3( BufferIndex bufferIndex ) const override
185 return Get(bufferIndex);
188 const float& GetFloatComponent( uint32_t component ) const override
190 const TransformManager* txManager = mTxManager;
191 return txManager->GetVector3PropertyComponentValue( mId, mProperty, component );
194 void Set(BufferIndex bufferIndex, const Vector3& value) override
196 mTxManager->SetVector3PropertyValue( mId, mProperty, value );
199 void SetComponent(BufferIndex bufferIndex, float value, uint32_t component)
201 mTxManager->SetVector3PropertyComponentValue( mId, mProperty, value, component);
204 void BakeComponent(BufferIndex bufferIndex, float value, uint32_t component)
206 mTxManager->BakeVector3PropertyComponentValue( mId, mProperty, value, component);
209 void Bake(BufferIndex bufferIndex, const Vector3& value) override
211 mTxManager->BakeVector3PropertyValue(mId, mProperty, value );
214 void BakeX(BufferIndex bufferIndex, float value) override
216 mTxManager->BakeXVector3PropertyValue(mId, mProperty, value );
219 void BakeY(BufferIndex bufferIndex, float value) override
221 mTxManager->BakeYVector3PropertyValue(mId, mProperty, value );
224 void BakeZ(BufferIndex bufferIndex, float value) override
226 mTxManager->BakeZVector3PropertyValue(mId, mProperty, value );
229 void SetFloatComponent( float value, uint32_t component) override
231 mTxManager->SetVector3PropertyComponentValue( mId, mProperty, value, component);
234 void BakeFloatComponent( float value, uint32_t component ) override
236 mTxManager->BakeVector3PropertyComponentValue( mId, mProperty, value, component);
239 void BakeRelative(BufferIndex bufferIndex, const Vector3& value) override
241 mTxManager->BakeRelativeVector3PropertyValue(mId, mProperty, value );
244 void BakeRelativeMultiply(BufferIndex bufferIndex, const Vector3& value) override
246 mTxManager->BakeMultiplyVector3PropertyValue(mId, mProperty, value );
249 TransformManagerProperty mProperty;
252 class TransformManagerPropertyQuaternion : public TransformManagerPropertyHandler<Quaternion>
256 TransformManagerPropertyQuaternion()
257 :TransformManagerPropertyHandler()
260 Dali::Property::Type GetType() const override
262 return Dali::PropertyTypes::Get<Quaternion>();
265 Quaternion& Get( BufferIndex bufferIndex ) override
267 return mTxManager->GetQuaternionPropertyValue( mId );
270 const Quaternion& Get( BufferIndex bufferIndex ) const override
272 const TransformManager* txManager = mTxManager;
273 return txManager->GetQuaternionPropertyValue( mId );
276 void Set(BufferIndex bufferIndex, const Quaternion& value) override
278 return mTxManager->SetQuaternionPropertyValue( mId, value );
281 void Bake(BufferIndex bufferIndex, const Quaternion& value) override
283 return mTxManager->BakeQuaternionPropertyValue( mId, value );
286 void BakeRelative(BufferIndex bufferIndex, const Quaternion& value) override
288 return mTxManager->BakeRelativeQuaternionPropertyValue( mId, value );
291 const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const override
293 return Get(bufferIndex);
299 * A Vector3 property used as input.
301 class TransformManagerVector3Input : public PropertyInputImpl
306 * Create an TransformManagerVector3Input
308 TransformManagerVector3Input( TransformManagerProperty property, const Vector3& initialValue )
309 :mTxManager(nullptr),
310 mId(INVALID_TRANSFORM_ID),
316 * Virtual destructor.
318 ~TransformManagerVector3Input() override = default;
321 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
323 Dali::Property::Type GetType() const override
325 return Dali::PropertyTypes::Get<Vector3>();
329 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
331 virtual bool IsClean() const
337 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
339 bool InputInitialized() const override
345 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
346 * @note A constraint can only receive the inherited property from the previous frame.
348 bool InputChanged() const override
354 * Helper function to get the transform components out of the world matrix.
355 * It stores the value in the mValue member variable
357 void ComputeTransformComponent() const
359 const TransformManager* txManager = mTxManager;
362 const Matrix& worldMatrix = txManager->GetWorldMatrix(mId);
364 if( mProperty == TRANSFORM_PROPERTY_WORLD_POSITION )
366 mValue = worldMatrix.GetTranslation3();
368 else if( mProperty == TRANSFORM_PROPERTY_WORLD_SCALE )
371 Quaternion orientation;
372 worldMatrix.GetTransformComponents(position, orientation, mValue);
378 * @copydoc Dali::PropertyInput::GetVector3()
380 const Vector3& GetVector3( BufferIndex bufferIndex ) const override
382 ComputeTransformComponent();
387 * @copydoc Dali::PropertyInput::GetConstraintInputVector3()
389 const Vector3& GetConstraintInputVector3( BufferIndex bufferIndex ) const override
391 ComputeTransformComponent();
396 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
398 Vector3& Get( BufferIndex bufferIndex )
400 ComputeTransformComponent();
405 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
407 const Vector3& Get( BufferIndex bufferIndex ) const
409 ComputeTransformComponent();
414 * Retrieve the property value.
415 * @param[in] bufferIndex The buffer to read.
416 * @return The property value.
418 const Vector3& operator[]( BufferIndex bufferIndex ) const
420 ComputeTransformComponent();
425 * Initializes the property
426 * @param[in] transformManager Pointer to the transform manager
427 * @param[in] Id of the transformation the property is associated with
429 void Initialize( TransformManager* transformManager, TransformId id )
431 mTxManager = transformManager;
436 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
438 bool IsTransformManagerProperty() const override
446 TransformManagerVector3Input(const TransformManagerVector3Input& property);
449 TransformManagerVector3Input& operator=(const TransformManagerVector3Input& rhs);
453 TransformManager* mTxManager;
455 TransformManagerProperty mProperty;
456 mutable Vector3 mValue;
460 * A Quaternion property used as input.
462 class TransformManagerQuaternionInput : public PropertyInputImpl
469 TransformManagerQuaternionInput()
470 :mTxManager(nullptr),
471 mId(INVALID_TRANSFORM_ID),
472 mValue(1.0f,0.0f,0.0f,0.0f)
477 * Virtual destructor.
479 ~TransformManagerQuaternionInput() override = default;
482 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
484 Dali::Property::Type GetType() const override
486 return Dali::PropertyTypes::Get<Quaternion>();
490 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
492 virtual bool IsClean() const
498 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
500 bool InputInitialized() const override
506 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
507 * @note A constraint can only receive the inherited property from the previous frame.
509 bool InputChanged() const override
515 * Helper function to get the orientation out of the world matrix.
516 * It stores the result in the mValue member variable
518 void ComputeTransformComponent() const
520 const TransformManager* txManager = mTxManager;
523 const Matrix& worldMatrix = txManager->GetWorldMatrix(mId);
524 Vector3 position, scale;
525 worldMatrix.GetTransformComponents(position, mValue, scale);
530 * @copydoc Dali::PropertyInput::GetQuaternion()
532 const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const override
534 ComputeTransformComponent();
539 * @copydoc Dali::PropertyInput::GetConstraintInputQuaternion()
541 const Quaternion& GetConstraintInputQuaternion( BufferIndex bufferIndex ) const override
543 ComputeTransformComponent();
548 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
550 Quaternion& Get( BufferIndex bufferIndex )
552 ComputeTransformComponent();
557 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
559 const Quaternion& Get( BufferIndex bufferIndex ) const
561 ComputeTransformComponent();
566 * Retrieve the property value.
567 * @param[in] bufferIndex The buffer to read.
568 * @return The property value.
570 const Quaternion& operator[]( BufferIndex bufferIndex) const
572 ComputeTransformComponent();
577 * Initializes the property
578 * @param[in] transformManager Pointer to the transform manager
579 * @param[in] Id of the transformation the property is associated with
581 void Initialize( TransformManager* transformManager, TransformId id )
583 mTxManager = transformManager;
588 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
590 bool IsTransformManagerProperty() const override
598 TransformManagerQuaternionInput(const TransformManagerQuaternionInput& property);
601 TransformManagerQuaternionInput& operator=(const TransformManagerQuaternionInput& rhs);
605 TransformManager* mTxManager;
607 mutable Quaternion mValue;
611 * A Matrix property used as input.
613 class TransformManagerMatrixInput : public PropertyInputImpl
620 TransformManagerMatrixInput()
621 :mTxManager(nullptr),
622 mId(INVALID_TRANSFORM_ID)
627 * Virtual destructor.
629 ~TransformManagerMatrixInput() override = default;
632 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
634 Dali::Property::Type GetType() const override
636 return Dali::PropertyTypes::Get<Matrix>();
640 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
642 virtual bool IsClean() const
648 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
650 bool InputInitialized() const override
656 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
657 * @note A constraint can only receive the inherited property from the previous frame.
659 bool InputChanged() const override
665 * @copydoc Dali::PropertyInput::GetMatrix()
667 const Matrix& GetMatrix( BufferIndex bufferIndex ) const override
669 const TransformManager* txManager = mTxManager;
672 return txManager->GetWorldMatrix(mId);
675 return Matrix::IDENTITY;
679 * @copydoc Dali::PropertyInput::GetConstraintInputMatrix()
681 const Matrix& GetConstraintInputMatrix( BufferIndex bufferIndex ) const override
683 const TransformManager* txManager = mTxManager;
686 return txManager->GetWorldMatrix(mId);
689 return Matrix::IDENTITY;
693 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
695 Matrix& Get( BufferIndex bufferIndex )
697 DALI_ASSERT_ALWAYS( mTxManager != nullptr );
698 return mTxManager->GetWorldMatrix(mId);
702 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
704 const Matrix& Get( BufferIndex bufferIndex ) const
706 return GetMatrix( bufferIndex );
710 * Retrieve the property value.
711 * @param[in] bufferIndex The buffer to read.
712 * @return The property value.
714 const Matrix& operator[]( BufferIndex bufferIndex ) const
716 return GetMatrix( bufferIndex );
719 void Initialize( TransformManager* transformManager, TransformId id )
721 mTxManager = transformManager;
726 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
728 bool IsTransformManagerProperty() const override
736 TransformManagerMatrixInput(const TransformManagerMatrixInput& property);
739 TransformManagerMatrixInput& operator=(const TransformManagerMatrixInput& rhs);
743 TransformManager* mTxManager;
748 } //namespace SceneGraph
749 } //namespace Internal
752 #endif // TRANSFORM_MANAGER_PROPERTY_H_