1 #ifndef TRANSFORM_MANAGER_PROPERTY_H_
2 #define TRANSFORM_MANAGER_PROPERTY_H_
5 * Copyright (c) 2021 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/common/animatable-property.h>
22 #include <dali/internal/update/manager/transform-manager.h>
31 struct TransformManagerPropertyHandler : public AnimatablePropertyBase
36 TransformManagerPropertyHandler() = default;
39 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
41 Dali::Property::Type GetType() const override = 0;
44 * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
46 virtual T& Get(BufferIndex bufferIndex) = 0;
49 * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
51 virtual const T& Get(BufferIndex bufferIndex) const = 0;
54 * @copydoc Dali::PropertyInput::GetVector3()
56 const Vector3& GetVector3(BufferIndex bufferIndex) const override
62 * Retrieve a component of property
63 * @param[in] component The component of the property
65 virtual const float& GetFloatComponent(uint32_t component) const
67 DALI_ASSERT_DEBUG(0 && "Invalid call");
69 static const float value = 0.0f;
74 * Set the property value. This will only persist for the current frame; the property
75 * will be reset with the base value, at the beginning of the next frame.
76 * @param[in] bufferIndex Not used
77 * @param[in] value The new property value.
79 virtual void Set(BufferIndex bufferIndex, const T& value) = 0;
82 * Change a component of property
83 * @param[in] value The new value of the component
84 * @param[in] component The component of the property
86 virtual void SetFloatComponent(float value, uint32_t component)
91 * @copydoc Dali::AnimatableProperty::Bake()
93 virtual void Bake(BufferIndex bufferIndex, const T& value) = 0;
96 * Bake a component of a property
97 * @param[in] value The new value of the component
98 * @param[in] component The component of the property
100 virtual void BakeFloatComponent(float value, uint32_t component)
105 * @copydoc Dali::AnimatableProperty::BakeX()
107 virtual void BakeX(BufferIndex bufferIndex, float value)
112 * @copydoc Dali::AnimatableProperty::BakeY()
114 virtual void BakeY(BufferIndex bufferIndex, float value)
119 * @copydoc Dali::AnimatableProperty::BakeZ()
121 virtual void BakeZ(BufferIndex bufferIndex, float value)
126 * @copydoc Dali::AnimatableProperty::BakeRelative()
128 virtual void BakeRelative(BufferIndex bufferIndex, const T& value) = 0;
131 * @copydoc Dali::AnimatableProperty::BakeRelativeMultiply()
133 virtual void BakeRelativeMultiply(BufferIndex bufferIndex, const T& value){};
136 * @copydoc Dali::AnimatableProperty::ResetToBaseValue()
138 void ResetToBaseValue(BufferIndex updateBufferIndex) override
143 * @copydoc Dali::AnimatableProperty::IsClean()
145 bool IsClean() const override
151 * Initializes the property
152 * @param[in] transformManager Pointer to the transform manager
153 * @param[in] Id of the transformation the property is associated with
155 void Initialize(TransformManagerData* data)
157 DALI_ASSERT_ALWAYS(data != nullptr && data->Manager() != nullptr);
158 mTxManagerData = data;
162 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
164 bool IsTransformManagerProperty() const override
169 TransformManagerData* mTxManagerData{nullptr};
172 template<TransformManagerProperty PropertyT>
173 struct TransformManagerPropertyVector3 final : public TransformManagerPropertyHandler<Vector3>
175 TransformManagerPropertyVector3() = default;
177 Dali::Property::Type GetType() const override
179 return Dali::PropertyTypes::Get<Vector3>();
182 Vector3& Get(BufferIndex bufferIndex) override
184 return mTxManagerData->Manager()->GetVector3PropertyValue(mTxManagerData->Id(), PropertyT);
187 const Vector3& Get(BufferIndex bufferIndex) const override
189 return mTxManagerData->
191 GetVector3PropertyValue(
192 mTxManagerData->Id(),
196 const Vector3& GetVector3(BufferIndex bufferIndex) const override
198 return Get(bufferIndex);
201 const float& GetFloatComponent(uint32_t component) const override
203 return mTxManagerData->Manager()->GetVector3PropertyComponentValue(mTxManagerData->Id(), PropertyT, component);
206 void Set(BufferIndex bufferIndex, const Vector3& value) override
208 mTxManagerData->Manager()->SetVector3PropertyValue(mTxManagerData->Id(), PropertyT, value);
211 void SetComponent(BufferIndex bufferIndex, float value, uint32_t component)
213 mTxManagerData->Manager()->SetVector3PropertyComponentValue(mTxManagerData->Id(), PropertyT, value, component);
216 void BakeComponent(BufferIndex bufferIndex, float value, uint32_t component)
218 mTxManagerData->Manager()->BakeVector3PropertyComponentValue(mTxManagerData->Id(), PropertyT, value, component);
221 void Bake(BufferIndex bufferIndex, const Vector3& value) override
223 mTxManagerData->Manager()->BakeVector3PropertyValue(mTxManagerData->Id(), PropertyT, value);
226 void BakeX(BufferIndex bufferIndex, float value) override
228 mTxManagerData->Manager()->BakeXVector3PropertyValue(mTxManagerData->Id(), PropertyT, value);
231 void BakeY(BufferIndex bufferIndex, float value) override
233 mTxManagerData->Manager()->BakeYVector3PropertyValue(mTxManagerData->Id(), PropertyT, value);
236 void BakeZ(BufferIndex bufferIndex, float value) override
238 mTxManagerData->Manager()->BakeZVector3PropertyValue(mTxManagerData->Id(), PropertyT, value);
241 void SetFloatComponent(float value, uint32_t component) override
243 mTxManagerData->Manager()->SetVector3PropertyComponentValue(mTxManagerData->Id(), PropertyT, value, component);
246 void BakeFloatComponent(float value, uint32_t component) override
248 mTxManagerData->Manager()->BakeVector3PropertyComponentValue(mTxManagerData->Id(), PropertyT, value, component);
251 void BakeRelative(BufferIndex bufferIndex, const Vector3& value) override
253 mTxManagerData->Manager()->BakeRelativeVector3PropertyValue(mTxManagerData->Id(), PropertyT, value);
256 void BakeRelativeMultiply(BufferIndex bufferIndex, const Vector3& value) override
258 mTxManagerData->Manager()->BakeMultiplyVector3PropertyValue(mTxManagerData->Id(), PropertyT, value);
262 class TransformManagerPropertyQuaternion final : public TransformManagerPropertyHandler<Quaternion>
265 TransformManagerPropertyQuaternion() = default;
267 Dali::Property::Type GetType() const override
269 return Dali::PropertyTypes::Get<Quaternion>();
272 Quaternion& Get(BufferIndex bufferIndex) override
274 return mTxManagerData->Manager()->GetQuaternionPropertyValue(mTxManagerData->Id());
277 const Quaternion& Get(BufferIndex bufferIndex) const override
279 return mTxManagerData->Manager()->GetQuaternionPropertyValue(mTxManagerData->Id());
282 void Set(BufferIndex bufferIndex, const Quaternion& value) override
284 return mTxManagerData->Manager()->SetQuaternionPropertyValue(mTxManagerData->Id(), value);
287 void Bake(BufferIndex bufferIndex, const Quaternion& value) override
289 return mTxManagerData->Manager()->BakeQuaternionPropertyValue(mTxManagerData->Id(), value);
292 void BakeRelative(BufferIndex bufferIndex, const Quaternion& value) override
294 return mTxManagerData->Manager()->BakeRelativeQuaternionPropertyValue(mTxManagerData->Id(), value);
297 const Quaternion& GetQuaternion(BufferIndex bufferIndex) const override
299 return Get(bufferIndex);
304 * A Vector3 property used as input.
306 class TransformManagerVector3Input : public PropertyInputImpl
310 * Create an TransformManagerVector3Input
312 TransformManagerVector3Input(TransformManagerProperty property, const Vector3& initialValue)
313 : mProperty(property),
319 * Virtual destructor.
321 ~TransformManagerVector3Input() override = default;
324 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
326 Dali::Property::Type GetType() const override
328 return Dali::PropertyTypes::Get<Vector3>();
332 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
334 virtual bool IsClean() const
340 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
342 bool InputInitialized() const override
348 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
349 * @note A constraint can only receive the inherited property from the previous frame.
351 bool InputChanged() const override
357 * Helper function to get the transform components out of the world matrix.
358 * It stores the value in the mValue member variable
360 void ComputeTransformComponent() const
364 const Matrix& worldMatrix = mTxManagerData->Manager()->GetWorldMatrix(mTxManagerData->Id());
366 if(mProperty == TRANSFORM_PROPERTY_WORLD_POSITION)
368 mValue = worldMatrix.GetTranslation3();
370 else if(mProperty == TRANSFORM_PROPERTY_WORLD_SCALE)
373 Quaternion orientation;
374 worldMatrix.GetTransformComponents(position, orientation, mValue);
380 * @copydoc Dali::PropertyInput::GetVector3()
382 const Vector3& GetVector3(BufferIndex bufferIndex) const override
384 ComputeTransformComponent();
389 * @copydoc Dali::PropertyInput::GetConstraintInputVector3()
391 const Vector3& GetConstraintInputVector3(BufferIndex bufferIndex) const override
393 ComputeTransformComponent();
398 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
400 Vector3& Get(BufferIndex bufferIndex)
402 ComputeTransformComponent();
407 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
409 const Vector3& Get(BufferIndex bufferIndex) const
411 ComputeTransformComponent();
416 * Retrieve the property value.
417 * @param[in] bufferIndex The buffer to read.
418 * @return The property value.
420 const Vector3& operator[](BufferIndex bufferIndex) const
422 ComputeTransformComponent();
427 * Initializes the property
428 * @param[in] transformManager Pointer to the transform manager
429 * @param[in] Id of the transformation the property is associated with
431 void Initialize(TransformManagerData* data)
433 DALI_ASSERT_ALWAYS(data != nullptr && data->Manager() != nullptr);
434 mTxManagerData = data;
438 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
440 bool IsTransformManagerProperty() const override
447 TransformManagerVector3Input(const TransformManagerVector3Input& property);
450 TransformManagerVector3Input& operator=(const TransformManagerVector3Input& rhs);
453 TransformManagerData* mTxManagerData{nullptr};
454 TransformManagerProperty mProperty;
455 mutable Vector3 mValue;
459 * A Quaternion property used as input.
461 class TransformManagerQuaternionInput final : public PropertyInputImpl
467 TransformManagerQuaternionInput() = default;
470 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
472 Dali::Property::Type GetType() const override
474 return Dali::PropertyTypes::Get<Quaternion>();
478 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
480 virtual bool IsClean() const
486 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
488 bool InputInitialized() const override
494 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
495 * @note A constraint can only receive the inherited property from the previous frame.
497 bool InputChanged() const override
503 * Helper function to get the orientation out of the world matrix.
504 * It stores the result in the mValue member variable
506 void ComputeTransformComponent() const
510 const Matrix& worldMatrix = mTxManagerData->Manager()->GetWorldMatrix(mTxManagerData->Id());
511 Vector3 position, scale;
512 worldMatrix.GetTransformComponents(position, mValue, scale);
517 * @copydoc Dali::PropertyInput::GetQuaternion()
519 const Quaternion& GetQuaternion(BufferIndex bufferIndex) const override
521 ComputeTransformComponent();
526 * @copydoc Dali::PropertyInput::GetConstraintInputQuaternion()
528 const Quaternion& GetConstraintInputQuaternion(BufferIndex bufferIndex) const override
530 ComputeTransformComponent();
535 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
537 Quaternion& Get(BufferIndex bufferIndex)
539 ComputeTransformComponent();
544 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
546 const Quaternion& Get(BufferIndex bufferIndex) const
548 ComputeTransformComponent();
553 * Retrieve the property value.
554 * @param[in] bufferIndex The buffer to read.
555 * @return The property value.
557 const Quaternion& operator[](BufferIndex bufferIndex) const
559 ComputeTransformComponent();
564 * Initializes the property
565 * @param[in] transformManager Pointer to the transform manager
566 * @param[in] Id of the transformation the property is associated with
568 void Initialize(TransformManagerData* data)
570 DALI_ASSERT_ALWAYS(data != nullptr && data->Manager() != nullptr);
571 mTxManagerData = data;
575 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
577 bool IsTransformManagerProperty() const override
584 TransformManagerQuaternionInput(const TransformManagerQuaternionInput& property);
587 TransformManagerQuaternionInput& operator=(const TransformManagerQuaternionInput& rhs);
590 TransformManagerData* mTxManagerData{nullptr};
591 mutable Quaternion mValue;
595 * A Matrix property used as input.
597 class TransformManagerMatrixInput final : public PropertyInputImpl
603 TransformManagerMatrixInput() = default;
606 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
608 Dali::Property::Type GetType() const override
610 return Dali::PropertyTypes::Get<Matrix>();
614 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
616 virtual bool IsClean() const
622 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
624 bool InputInitialized() const override
630 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
631 * @note A constraint can only receive the inherited property from the previous frame.
633 bool InputChanged() const override
639 * @copydoc Dali::PropertyInput::GetMatrix()
641 const Matrix& GetMatrix(BufferIndex bufferIndex) const override
645 return mTxManagerData->Manager()->GetWorldMatrix(mTxManagerData->Id());
648 return Matrix::IDENTITY;
652 * @copydoc Dali::PropertyInput::GetConstraintInputMatrix()
654 const Matrix& GetConstraintInputMatrix(BufferIndex bufferIndex) const override
658 return mTxManagerData->Manager()->GetWorldMatrix(mTxManagerData->Id());
661 return Matrix::IDENTITY;
665 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
667 Matrix& Get(BufferIndex bufferIndex)
669 DALI_ASSERT_ALWAYS(mTxManagerData != nullptr);
670 return mTxManagerData->Manager()->GetWorldMatrix(mTxManagerData->Id());
674 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
676 const Matrix& Get(BufferIndex bufferIndex) const
678 return GetMatrix(bufferIndex);
682 * Retrieve the property value.
683 * @param[in] bufferIndex The buffer to read.
684 * @return The property value.
686 const Matrix& operator[](BufferIndex bufferIndex) const
688 return GetMatrix(bufferIndex);
691 void Initialize(TransformManagerData* data)
693 DALI_ASSERT_ALWAYS(data != nullptr && data->Manager() != nullptr);
694 mTxManagerData = data;
698 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
700 bool IsTransformManagerProperty() const override
707 TransformManagerMatrixInput(const TransformManagerMatrixInput& property);
710 TransformManagerMatrixInput& operator=(const TransformManagerMatrixInput& rhs);
713 TransformManagerData* mTxManagerData{nullptr};
716 } //namespace SceneGraph
717 } //namespace Internal
720 #endif // TRANSFORM_MANAGER_PROPERTY_H_