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->Manager()->GetVector3PropertyValue(mTxManagerData->Id(), PropertyT);
192 const Vector3& GetVector3(BufferIndex bufferIndex) const override
194 return Get(bufferIndex);
197 const float& GetFloatComponent(uint32_t component) const override
199 return mTxManagerData->Manager()->GetVector3PropertyComponentValue(mTxManagerData->Id(), PropertyT, component);
202 void Set(BufferIndex bufferIndex, const Vector3& value) override
204 mTxManagerData->Manager()->SetVector3PropertyValue(mTxManagerData->Id(), PropertyT, value);
207 void SetComponent(BufferIndex bufferIndex, float value, uint32_t component)
209 mTxManagerData->Manager()->SetVector3PropertyComponentValue(mTxManagerData->Id(), PropertyT, value, component);
212 void BakeComponent(BufferIndex bufferIndex, float value, uint32_t component)
214 mTxManagerData->Manager()->BakeVector3PropertyComponentValue(mTxManagerData->Id(), PropertyT, value, component);
217 void Bake(BufferIndex bufferIndex, const Vector3& value) override
219 mTxManagerData->Manager()->BakeVector3PropertyValue(mTxManagerData->Id(), PropertyT, value);
222 void BakeX(BufferIndex bufferIndex, float value) override
224 mTxManagerData->Manager()->BakeXVector3PropertyValue(mTxManagerData->Id(), PropertyT, value);
227 void BakeY(BufferIndex bufferIndex, float value) override
229 mTxManagerData->Manager()->BakeYVector3PropertyValue(mTxManagerData->Id(), PropertyT, value);
232 void BakeZ(BufferIndex bufferIndex, float value) override
234 mTxManagerData->Manager()->BakeZVector3PropertyValue(mTxManagerData->Id(), PropertyT, value);
237 void SetFloatComponent(float value, uint32_t component) override
239 mTxManagerData->Manager()->SetVector3PropertyComponentValue(mTxManagerData->Id(), PropertyT, value, component);
242 void BakeFloatComponent(float value, uint32_t component) override
244 mTxManagerData->Manager()->BakeVector3PropertyComponentValue(mTxManagerData->Id(), PropertyT, value, component);
247 void BakeRelative(BufferIndex bufferIndex, const Vector3& value) override
249 mTxManagerData->Manager()->BakeRelativeVector3PropertyValue(mTxManagerData->Id(), PropertyT, value);
252 void BakeRelativeMultiply(BufferIndex bufferIndex, const Vector3& value) override
254 mTxManagerData->Manager()->BakeMultiplyVector3PropertyValue(mTxManagerData->Id(), PropertyT, value);
258 class TransformManagerPropertyQuaternion final : public TransformManagerPropertyHandler<Quaternion>
261 TransformManagerPropertyQuaternion() = default;
263 Dali::Property::Type GetType() const override
265 return Dali::PropertyTypes::Get<Quaternion>();
268 Quaternion& Get(BufferIndex bufferIndex) override
270 return mTxManagerData->Manager()->GetQuaternionPropertyValue(mTxManagerData->Id());
273 const Quaternion& Get(BufferIndex bufferIndex) const override
275 return mTxManagerData->Manager()->GetQuaternionPropertyValue(mTxManagerData->Id());
278 void Set(BufferIndex bufferIndex, const Quaternion& value) override
280 return mTxManagerData->Manager()->SetQuaternionPropertyValue(mTxManagerData->Id(), value);
283 void Bake(BufferIndex bufferIndex, const Quaternion& value) override
285 return mTxManagerData->Manager()->BakeQuaternionPropertyValue(mTxManagerData->Id(), value);
288 void BakeRelative(BufferIndex bufferIndex, const Quaternion& value) override
290 return mTxManagerData->Manager()->BakeRelativeQuaternionPropertyValue(mTxManagerData->Id(), value);
293 const Quaternion& GetQuaternion(BufferIndex bufferIndex) const override
295 return Get(bufferIndex);
300 * A Vector3 property used as input.
302 class TransformManagerVector3Input : public PropertyInputImpl
306 * Create an TransformManagerVector3Input
308 TransformManagerVector3Input(TransformManagerProperty property, const Vector3& initialValue)
309 : mProperty(property),
315 * Virtual destructor.
317 ~TransformManagerVector3Input() override = default;
320 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
322 Dali::Property::Type GetType() const override
324 return Dali::PropertyTypes::Get<Vector3>();
328 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
330 virtual bool IsClean() const
336 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
338 bool InputInitialized() const override
344 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
345 * @note A constraint can only receive the inherited property from the previous frame.
347 bool InputChanged() const override
353 * Helper function to get the transform components out of the world matrix.
354 * It stores the value in the mValue member variable
356 void ComputeTransformComponent() const
360 const Matrix& worldMatrix = mTxManagerData->Manager()->GetWorldMatrix(mTxManagerData->Id());
362 if(mProperty == TRANSFORM_PROPERTY_WORLD_POSITION)
364 mValue = worldMatrix.GetTranslation3();
366 else if(mProperty == TRANSFORM_PROPERTY_WORLD_SCALE)
369 Quaternion orientation;
370 worldMatrix.GetTransformComponents(position, orientation, mValue);
376 * @copydoc Dali::PropertyInput::GetVector3()
378 const Vector3& GetVector3(BufferIndex bufferIndex) const override
380 ComputeTransformComponent();
385 * @copydoc Dali::PropertyInput::GetConstraintInputVector3()
387 const Vector3& GetConstraintInputVector3(BufferIndex bufferIndex) const override
389 ComputeTransformComponent();
394 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
396 Vector3& Get(BufferIndex bufferIndex)
398 ComputeTransformComponent();
403 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
405 const Vector3& Get(BufferIndex bufferIndex) const
407 ComputeTransformComponent();
412 * Retrieve the property value.
413 * @param[in] bufferIndex The buffer to read.
414 * @return The property value.
416 const Vector3& operator[](BufferIndex bufferIndex) const
418 ComputeTransformComponent();
423 * Initializes the property
424 * @param[in] transformManager Pointer to the transform manager
425 * @param[in] Id of the transformation the property is associated with
427 void Initialize(TransformManagerData* data)
429 DALI_ASSERT_ALWAYS(data != nullptr && data->Manager() != nullptr);
430 mTxManagerData = data;
434 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
436 bool IsTransformManagerProperty() const override
443 TransformManagerVector3Input(const TransformManagerVector3Input& property);
446 TransformManagerVector3Input& operator=(const TransformManagerVector3Input& rhs);
449 TransformManagerData* mTxManagerData{nullptr};
450 TransformManagerProperty mProperty;
451 mutable Vector3 mValue;
455 * A Quaternion property used as input.
457 class TransformManagerQuaternionInput final : public PropertyInputImpl
463 TransformManagerQuaternionInput() = default;
466 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
468 Dali::Property::Type GetType() const override
470 return Dali::PropertyTypes::Get<Quaternion>();
474 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
476 virtual bool IsClean() const
482 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
484 bool InputInitialized() const override
490 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
491 * @note A constraint can only receive the inherited property from the previous frame.
493 bool InputChanged() const override
499 * Helper function to get the orientation out of the world matrix.
500 * It stores the result in the mValue member variable
502 void ComputeTransformComponent() const
506 const Matrix& worldMatrix = mTxManagerData->Manager()->GetWorldMatrix(mTxManagerData->Id());
507 Vector3 position, scale;
508 worldMatrix.GetTransformComponents(position, mValue, scale);
513 * @copydoc Dali::PropertyInput::GetQuaternion()
515 const Quaternion& GetQuaternion(BufferIndex bufferIndex) const override
517 ComputeTransformComponent();
522 * @copydoc Dali::PropertyInput::GetConstraintInputQuaternion()
524 const Quaternion& GetConstraintInputQuaternion(BufferIndex bufferIndex) const override
526 ComputeTransformComponent();
531 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
533 Quaternion& Get(BufferIndex bufferIndex)
535 ComputeTransformComponent();
540 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
542 const Quaternion& Get(BufferIndex bufferIndex) const
544 ComputeTransformComponent();
549 * Retrieve the property value.
550 * @param[in] bufferIndex The buffer to read.
551 * @return The property value.
553 const Quaternion& operator[](BufferIndex bufferIndex) const
555 ComputeTransformComponent();
560 * Initializes the property
561 * @param[in] transformManager Pointer to the transform manager
562 * @param[in] Id of the transformation the property is associated with
564 void Initialize(TransformManagerData* data)
566 DALI_ASSERT_ALWAYS(data != nullptr && data->Manager() != nullptr);
567 mTxManagerData = data;
571 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
573 bool IsTransformManagerProperty() const override
580 TransformManagerQuaternionInput(const TransformManagerQuaternionInput& property);
583 TransformManagerQuaternionInput& operator=(const TransformManagerQuaternionInput& rhs);
586 TransformManagerData* mTxManagerData{nullptr};
587 mutable Quaternion mValue;
591 * A Matrix property used as input.
593 class TransformManagerMatrixInput final : public PropertyInputImpl
599 TransformManagerMatrixInput() = default;
602 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
604 Dali::Property::Type GetType() const override
606 return Dali::PropertyTypes::Get<Matrix>();
610 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
612 virtual bool IsClean() const
618 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
620 bool InputInitialized() const override
626 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
627 * @note A constraint can only receive the inherited property from the previous frame.
629 bool InputChanged() const override
635 * @copydoc Dali::PropertyInput::GetMatrix()
637 const Matrix& GetMatrix(BufferIndex bufferIndex) const override
641 return mTxManagerData->Manager()->GetWorldMatrix(mTxManagerData->Id());
644 return Matrix::IDENTITY;
648 * @copydoc Dali::PropertyInput::GetConstraintInputMatrix()
650 const Matrix& GetConstraintInputMatrix(BufferIndex bufferIndex) const override
654 return mTxManagerData->Manager()->GetWorldMatrix(mTxManagerData->Id());
657 return Matrix::IDENTITY;
661 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
663 Matrix& Get(BufferIndex bufferIndex)
665 DALI_ASSERT_ALWAYS(mTxManagerData != nullptr);
666 return mTxManagerData->Manager()->GetWorldMatrix(mTxManagerData->Id());
670 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
672 const Matrix& Get(BufferIndex bufferIndex) const
674 return GetMatrix(bufferIndex);
678 * Retrieve the property value.
679 * @param[in] bufferIndex The buffer to read.
680 * @return The property value.
682 const Matrix& operator[](BufferIndex bufferIndex) const
684 return GetMatrix(bufferIndex);
687 void Initialize(TransformManagerData* data)
689 DALI_ASSERT_ALWAYS(data != nullptr && data->Manager() != nullptr);
690 mTxManagerData = data;
694 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
696 bool IsTransformManagerProperty() const override
703 TransformManagerMatrixInput(const TransformManagerMatrixInput& property);
706 TransformManagerMatrixInput& operator=(const TransformManagerMatrixInput& rhs);
709 TransformManagerData* mTxManagerData{nullptr};
712 } //namespace SceneGraph
713 } //namespace Internal
716 #endif // TRANSFORM_MANAGER_PROPERTY_H_