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() = default;
40 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
42 Dali::Property::Type GetType() const override = 0;
45 * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
47 virtual T& Get( BufferIndex bufferIndex ) = 0;
50 * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
52 virtual const T& Get( BufferIndex bufferIndex ) const = 0;
55 * @copydoc Dali::PropertyInput::GetVector3()
57 const Vector3& GetVector3( BufferIndex bufferIndex ) const override{ return Vector3::ZERO; }
60 * Retrieve a component of property
61 * @param[in] component The component of the property
63 virtual const float& GetFloatComponent(uint32_t component) const
65 DALI_ASSERT_DEBUG( 0 && "Invalid call");
67 static const float value = 0.0f;
72 * Set the property value. This will only persist for the current frame; the property
73 * will be reset with the base value, at the beginning of the next frame.
74 * @param[in] bufferIndex Not used
75 * @param[in] value The new property value.
77 virtual void Set(BufferIndex bufferIndex, const T& value) = 0;
80 * Change a component of property
81 * @param[in] value The new value of the component
82 * @param[in] component The component of the property
84 virtual void SetFloatComponent( float value, uint32_t component){}
87 * @copydoc Dali::AnimatableProperty::Bake()
89 virtual void Bake(BufferIndex bufferIndex, const T& value) = 0;
92 * Bake a component of a property
93 * @param[in] value The new value of the component
94 * @param[in] component The component of the property
96 virtual void BakeFloatComponent( float value, uint32_t component){}
99 * @copydoc Dali::AnimatableProperty::BakeX()
101 virtual void BakeX(BufferIndex bufferIndex, float value){}
104 * @copydoc Dali::AnimatableProperty::BakeY()
106 virtual void BakeY(BufferIndex bufferIndex, float value){}
109 * @copydoc Dali::AnimatableProperty::BakeZ()
111 virtual void BakeZ(BufferIndex bufferIndex, float value){}
114 * @copydoc Dali::AnimatableProperty::BakeRelative()
116 virtual void BakeRelative(BufferIndex bufferIndex, const T& value) = 0;
119 * @copydoc Dali::AnimatableProperty::BakeRelativeMultiply()
121 virtual void BakeRelativeMultiply(BufferIndex bufferIndex, const T& value){};
124 * @copydoc Dali::AnimatableProperty::ResetToBaseValue()
126 void ResetToBaseValue(BufferIndex updateBufferIndex) override{}
129 * @copydoc Dali::AnimatableProperty::IsClean()
131 bool IsClean() const override{ return false; }
134 * Initializes the property
135 * @param[in] transformManager Pointer to the transform manager
136 * @param[in] Id of the transformation the property is associated with
138 void Initialize( TransformManagerData* data)
140 DALI_ASSERT_ALWAYS( data != nullptr && data->Manager() != nullptr);
141 mTxManagerData = data;
145 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
147 bool IsTransformManagerProperty() const override
152 TransformManagerData* mTxManagerData{nullptr};
155 template<TransformManagerProperty PropertyT>
156 struct TransformManagerPropertyVector3 final : public TransformManagerPropertyHandler<Vector3>
159 TransformManagerPropertyVector3() = default;
161 Dali::Property::Type GetType() const override
163 return Dali::PropertyTypes::Get<Vector3>();
166 Vector3& Get( BufferIndex bufferIndex ) override
168 return mTxManagerData->Manager()->GetVector3PropertyValue( mTxManagerData->Id(), PropertyT );
171 const Vector3& Get( BufferIndex bufferIndex ) const override
173 return mTxManagerData->Manager()->GetVector3PropertyValue( mTxManagerData->Id(), PropertyT );
176 const Vector3& GetVector3( BufferIndex bufferIndex ) const override
178 return Get(bufferIndex);
181 const float& GetFloatComponent( uint32_t component ) const override
183 return mTxManagerData->Manager()->GetVector3PropertyComponentValue( mTxManagerData->Id(), PropertyT, component );
186 void Set(BufferIndex bufferIndex, const Vector3& value) override
188 mTxManagerData->Manager()->SetVector3PropertyValue( mTxManagerData->Id(), PropertyT, value );
191 void SetComponent(BufferIndex bufferIndex, float value, uint32_t component)
193 mTxManagerData->Manager()->SetVector3PropertyComponentValue( mTxManagerData->Id(), PropertyT, value, component);
196 void BakeComponent(BufferIndex bufferIndex, float value, uint32_t component)
198 mTxManagerData->Manager()->BakeVector3PropertyComponentValue( mTxManagerData->Id(), PropertyT, value, component);
201 void Bake(BufferIndex bufferIndex, const Vector3& value) override
203 mTxManagerData->Manager()->BakeVector3PropertyValue(mTxManagerData->Id(), PropertyT, value );
206 void BakeX(BufferIndex bufferIndex, float value) override
208 mTxManagerData->Manager()->BakeXVector3PropertyValue(mTxManagerData->Id(), PropertyT, value );
211 void BakeY(BufferIndex bufferIndex, float value) override
213 mTxManagerData->Manager()->BakeYVector3PropertyValue(mTxManagerData->Id(), PropertyT, value );
216 void BakeZ(BufferIndex bufferIndex, float value) override
218 mTxManagerData->Manager()->BakeZVector3PropertyValue(mTxManagerData->Id(), PropertyT, value );
221 void SetFloatComponent( float value, uint32_t component) override
223 mTxManagerData->Manager()->SetVector3PropertyComponentValue( mTxManagerData->Id(), PropertyT, value, component);
226 void BakeFloatComponent( float value, uint32_t component ) override
228 mTxManagerData->Manager()->BakeVector3PropertyComponentValue( mTxManagerData->Id(), PropertyT, value, component);
231 void BakeRelative(BufferIndex bufferIndex, const Vector3& value) override
233 mTxManagerData->Manager()->BakeRelativeVector3PropertyValue(mTxManagerData->Id(), PropertyT, value );
236 void BakeRelativeMultiply(BufferIndex bufferIndex, const Vector3& value) override
238 mTxManagerData->Manager()->BakeMultiplyVector3PropertyValue(mTxManagerData->Id(), PropertyT, value );
242 class TransformManagerPropertyQuaternion final : public TransformManagerPropertyHandler<Quaternion>
246 TransformManagerPropertyQuaternion() = default;
248 Dali::Property::Type GetType() const override
250 return Dali::PropertyTypes::Get<Quaternion>();
253 Quaternion& Get( BufferIndex bufferIndex ) override
255 return mTxManagerData->Manager()->GetQuaternionPropertyValue( mTxManagerData->Id() );
258 const Quaternion& Get( BufferIndex bufferIndex ) const override
260 return mTxManagerData->Manager()->GetQuaternionPropertyValue( mTxManagerData->Id() );
263 void Set(BufferIndex bufferIndex, const Quaternion& value) override
265 return mTxManagerData->Manager()->SetQuaternionPropertyValue( mTxManagerData->Id(), value );
268 void Bake(BufferIndex bufferIndex, const Quaternion& value) override
270 return mTxManagerData->Manager()->BakeQuaternionPropertyValue( mTxManagerData->Id(), value );
273 void BakeRelative(BufferIndex bufferIndex, const Quaternion& value) override
275 return mTxManagerData->Manager()->BakeRelativeQuaternionPropertyValue( mTxManagerData->Id(), value );
278 const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const override
280 return Get(bufferIndex);
286 * A Vector3 property used as input.
288 class TransformManagerVector3Input : public PropertyInputImpl
293 * Create an TransformManagerVector3Input
295 TransformManagerVector3Input( TransformManagerProperty property, const Vector3& initialValue )
296 :mProperty(property),
301 * Virtual destructor.
303 ~TransformManagerVector3Input() override = default;
306 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
308 Dali::Property::Type GetType() const override
310 return Dali::PropertyTypes::Get<Vector3>();
314 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
316 virtual bool IsClean() const
322 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
324 bool InputInitialized() const override
330 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
331 * @note A constraint can only receive the inherited property from the previous frame.
333 bool InputChanged() const override
339 * Helper function to get the transform components out of the world matrix.
340 * It stores the value in the mValue member variable
342 void ComputeTransformComponent() const
346 const Matrix& worldMatrix = mTxManagerData->Manager()->GetWorldMatrix(mTxManagerData->Id());
348 if( mProperty == TRANSFORM_PROPERTY_WORLD_POSITION )
350 mValue = worldMatrix.GetTranslation3();
352 else if( mProperty == TRANSFORM_PROPERTY_WORLD_SCALE )
355 Quaternion orientation;
356 worldMatrix.GetTransformComponents(position, orientation, mValue);
362 * @copydoc Dali::PropertyInput::GetVector3()
364 const Vector3& GetVector3( BufferIndex bufferIndex ) const override
366 ComputeTransformComponent();
371 * @copydoc Dali::PropertyInput::GetConstraintInputVector3()
373 const Vector3& GetConstraintInputVector3( BufferIndex bufferIndex ) const override
375 ComputeTransformComponent();
380 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
382 Vector3& Get( BufferIndex bufferIndex )
384 ComputeTransformComponent();
389 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
391 const Vector3& Get( BufferIndex bufferIndex ) const
393 ComputeTransformComponent();
398 * Retrieve the property value.
399 * @param[in] bufferIndex The buffer to read.
400 * @return The property value.
402 const Vector3& operator[]( BufferIndex bufferIndex ) const
404 ComputeTransformComponent();
409 * Initializes the property
410 * @param[in] transformManager Pointer to the transform manager
411 * @param[in] Id of the transformation the property is associated with
413 void Initialize( TransformManagerData* data)
415 DALI_ASSERT_ALWAYS( data != nullptr && data->Manager() != nullptr);
416 mTxManagerData = data;
420 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
422 bool IsTransformManagerProperty() const override
430 TransformManagerVector3Input(const TransformManagerVector3Input& property);
433 TransformManagerVector3Input& operator=(const TransformManagerVector3Input& rhs);
437 TransformManagerData* mTxManagerData{nullptr};
438 TransformManagerProperty mProperty;
439 mutable Vector3 mValue;
443 * A Quaternion property used as input.
445 class TransformManagerQuaternionInput final : public PropertyInputImpl
452 TransformManagerQuaternionInput() = default;
455 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
457 Dali::Property::Type GetType() const override
459 return Dali::PropertyTypes::Get<Quaternion>();
463 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
465 virtual bool IsClean() const
471 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
473 bool InputInitialized() const override
479 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
480 * @note A constraint can only receive the inherited property from the previous frame.
482 bool InputChanged() const override
488 * Helper function to get the orientation out of the world matrix.
489 * It stores the result in the mValue member variable
491 void ComputeTransformComponent() const
495 const Matrix& worldMatrix = mTxManagerData->Manager()->GetWorldMatrix(mTxManagerData->Id());
496 Vector3 position, scale;
497 worldMatrix.GetTransformComponents(position, mValue, scale);
502 * @copydoc Dali::PropertyInput::GetQuaternion()
504 const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const override
506 ComputeTransformComponent();
511 * @copydoc Dali::PropertyInput::GetConstraintInputQuaternion()
513 const Quaternion& GetConstraintInputQuaternion( BufferIndex bufferIndex ) const override
515 ComputeTransformComponent();
520 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
522 Quaternion& Get( BufferIndex bufferIndex )
524 ComputeTransformComponent();
529 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
531 const Quaternion& Get( BufferIndex bufferIndex ) const
533 ComputeTransformComponent();
538 * Retrieve the property value.
539 * @param[in] bufferIndex The buffer to read.
540 * @return The property value.
542 const Quaternion& operator[]( BufferIndex bufferIndex) const
544 ComputeTransformComponent();
549 * Initializes the property
550 * @param[in] transformManager Pointer to the transform manager
551 * @param[in] Id of the transformation the property is associated with
553 void Initialize( TransformManagerData* data)
555 DALI_ASSERT_ALWAYS( data != nullptr && data->Manager() != nullptr);
556 mTxManagerData = data;
560 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
562 bool IsTransformManagerProperty() const override
570 TransformManagerQuaternionInput(const TransformManagerQuaternionInput& property);
573 TransformManagerQuaternionInput& operator=(const TransformManagerQuaternionInput& rhs);
577 TransformManagerData* mTxManagerData{nullptr};
578 mutable Quaternion mValue;
582 * A Matrix property used as input.
584 class TransformManagerMatrixInput final: public PropertyInputImpl
591 TransformManagerMatrixInput() = default;
595 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
597 Dali::Property::Type GetType() const override
599 return Dali::PropertyTypes::Get<Matrix>();
603 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
605 virtual bool IsClean() const
611 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
613 bool InputInitialized() const override
619 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
620 * @note A constraint can only receive the inherited property from the previous frame.
622 bool InputChanged() const override
628 * @copydoc Dali::PropertyInput::GetMatrix()
630 const Matrix& GetMatrix( BufferIndex bufferIndex ) const override
634 return mTxManagerData->Manager()->GetWorldMatrix(mTxManagerData->Id());
637 return Matrix::IDENTITY;
641 * @copydoc Dali::PropertyInput::GetConstraintInputMatrix()
643 const Matrix& GetConstraintInputMatrix( BufferIndex bufferIndex ) const override
647 return mTxManagerData->Manager()->GetWorldMatrix(mTxManagerData->Id());
650 return Matrix::IDENTITY;
654 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
656 Matrix& Get( BufferIndex bufferIndex )
658 DALI_ASSERT_ALWAYS( mTxManagerData != nullptr );
659 return mTxManagerData->Manager()->GetWorldMatrix(mTxManagerData->Id());
663 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
665 const Matrix& Get( BufferIndex bufferIndex ) const
667 return GetMatrix( bufferIndex );
671 * Retrieve the property value.
672 * @param[in] bufferIndex The buffer to read.
673 * @return The property value.
675 const Matrix& operator[]( BufferIndex bufferIndex ) const
677 return GetMatrix( bufferIndex );
680 void Initialize( TransformManagerData* data)
682 DALI_ASSERT_ALWAYS( data != nullptr && data->Manager() != nullptr);
683 mTxManagerData = data;
687 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
689 bool IsTransformManagerProperty() const override
697 TransformManagerMatrixInput(const TransformManagerMatrixInput& property);
700 TransformManagerMatrixInput& operator=(const TransformManagerMatrixInput& rhs);
704 TransformManagerData* mTxManagerData{nullptr};
708 } //namespace SceneGraph
709 } //namespace Internal
712 #endif // TRANSFORM_MANAGER_PROPERTY_H_