1 #ifndef TRANSFORM_MANAGER_PROPERTY_H_
2 #define TRANSFORM_MANAGER_PROPERTY_H_
5 * Copyright (c) 2018 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)=0;
69 * Set the property value. This will only persist for the current frame; the property
70 * will be reset with the base value, at the beginning of the next frame.
71 * @param[in] bufferIndex Not used
72 * @param[in] value The new property value.
74 virtual void Set(BufferIndex bufferIndex, const T& value) = 0;
77 * Change a component of property
78 * @param[in] value The new value of the component
79 * @param[in] component The component of the property
81 virtual void SetFloatComponent( float value, uint32_t component){}
84 * @copydoc Dali::AnimatableProperty::Bake()
86 virtual void Bake(BufferIndex bufferIndex, const T& value) = 0;
89 * Bake a component of a property
90 * @param[in] value The new value of the component
91 * @param[in] component The component of the property
93 virtual void BakeFloatComponent( float value, uint32_t component){}
96 * @copydoc Dali::AnimatableProperty::BakeX()
98 virtual void BakeX(BufferIndex bufferIndex, float value){}
101 * @copydoc Dali::AnimatableProperty::BakeY()
103 virtual void BakeY(BufferIndex bufferIndex, float value){}
106 * @copydoc Dali::AnimatableProperty::BakeZ()
108 virtual void BakeZ(BufferIndex bufferIndex, float value){}
111 * @copydoc Dali::AnimatableProperty::BakeRelative()
113 virtual void BakeRelative(BufferIndex bufferIndex, const T& value) = 0;
116 * @copydoc Dali::AnimatableProperty::BakeRelativeMultiply()
118 virtual void BakeRelativeMultiply(BufferIndex bufferIndex, const T& value){};
121 * @copydoc Dali::AnimatableProperty::ResetToBaseValue()
123 void ResetToBaseValue(BufferIndex updateBufferIndex) override{}
126 * @copydoc Dali::AnimatableProperty::IsClean()
128 bool IsClean() const override{ return false; }
131 * Initializes the property
132 * @param[in] transformManager Pointer to the transform manager
133 * @param[in] Id of the transformation the property is associated with
135 void Initialize( TransformManager* transformManager, TransformId id )
137 mTxManager = transformManager;
142 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
144 bool IsTransformManagerProperty() const override
149 TransformManager* mTxManager;
153 struct TransformManagerPropertyVector3 : public TransformManagerPropertyHandler<Vector3>
156 TransformManagerPropertyVector3(TransformManagerProperty property)
157 :TransformManagerPropertyHandler(),
158 mProperty( property )
161 Dali::Property::Type GetType() const override
163 return Dali::PropertyTypes::Get<Vector3>();
166 Vector3& Get( BufferIndex bufferIndex ) override
168 return mTxManager->GetVector3PropertyValue( mId, mProperty );
171 const Vector3& Get( BufferIndex bufferIndex ) const override
173 return mTxManager->GetVector3PropertyValue( mId, mProperty );
176 const Vector3& GetVector3( BufferIndex bufferIndex ) const override
178 return Get(bufferIndex);
181 const float& GetFloatComponent( uint32_t component ) override
183 return mTxManager->GetVector3PropertyComponentValue( mId, mProperty, component );
186 void Set(BufferIndex bufferIndex, const Vector3& value) override
188 mTxManager->SetVector3PropertyValue( mId, mProperty, value );
191 void SetComponent(BufferIndex bufferIndex, float value, uint32_t component)
193 mTxManager->SetVector3PropertyComponentValue( mId, mProperty, value, component);
196 void BakeComponent(BufferIndex bufferIndex, float value, uint32_t component)
198 mTxManager->BakeVector3PropertyComponentValue( mId, mProperty, value, component);
201 void Bake(BufferIndex bufferIndex, const Vector3& value) override
203 mTxManager->BakeVector3PropertyValue(mId, mProperty, value );
206 void BakeX(BufferIndex bufferIndex, float value) override
208 mTxManager->BakeXVector3PropertyValue(mId, mProperty, value );
211 void BakeY(BufferIndex bufferIndex, float value) override
213 mTxManager->BakeYVector3PropertyValue(mId, mProperty, value );
216 void BakeZ(BufferIndex bufferIndex, float value) override
218 mTxManager->BakeZVector3PropertyValue(mId, mProperty, value );
221 void SetFloatComponent( float value, uint32_t component) override
223 mTxManager->SetVector3PropertyComponentValue( mId, mProperty, value, component);
226 void BakeFloatComponent( float value, uint32_t component ) override
228 mTxManager->BakeVector3PropertyComponentValue( mId, mProperty, value, component);
231 void BakeRelative(BufferIndex bufferIndex, const Vector3& value) override
233 mTxManager->BakeRelativeVector3PropertyValue(mId, mProperty, value );
236 void BakeRelativeMultiply(BufferIndex bufferIndex, const Vector3& value) override
238 mTxManager->BakeMultiplyVector3PropertyValue(mId, mProperty, value );
241 TransformManagerProperty mProperty;
244 class TransformManagerPropertyQuaternion : public TransformManagerPropertyHandler<Quaternion>
248 TransformManagerPropertyQuaternion()
249 :TransformManagerPropertyHandler()
252 Dali::Property::Type GetType() const override
254 return Dali::PropertyTypes::Get<Quaternion>();
257 Quaternion& Get( BufferIndex bufferIndex ) override
259 return mTxManager->GetQuaternionPropertyValue( mId );
262 const Quaternion& Get( BufferIndex bufferIndex ) const override
264 return mTxManager->GetQuaternionPropertyValue( mId );
267 const float& GetFloatComponent( uint32_t component) override
269 return mTxManager->GetQuaternionPropertyValue( mId ).mVector[component];
272 void Set(BufferIndex bufferIndex, const Quaternion& value) override
274 return mTxManager->SetQuaternionPropertyValue( mId, value );
277 void Bake(BufferIndex bufferIndex, const Quaternion& value) override
279 return mTxManager->BakeQuaternionPropertyValue( mId, value );
282 void BakeRelative(BufferIndex bufferIndex, const Quaternion& value) override
284 return mTxManager->BakeRelativeQuaternionPropertyValue( mId, value );
287 const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const override
289 return Get(bufferIndex);
295 * A Vector3 property used as input.
297 class TransformManagerVector3Input : public PropertyInputImpl
302 * Create an TransformManagerVector3Input
304 TransformManagerVector3Input( TransformManagerProperty property, const Vector3& initialValue )
305 :mTxManager(nullptr),
306 mId(INVALID_TRANSFORM_ID),
312 * Virtual destructor.
314 ~TransformManagerVector3Input() override = default;
317 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
319 Dali::Property::Type GetType() const override
321 return Dali::PropertyTypes::Get<Vector3>();
325 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
327 virtual bool IsClean() const
333 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
335 bool InputInitialized() const override
341 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
342 * @note A constraint can only receive the inherited property from the previous frame.
344 bool InputChanged() const override
350 * Helper function to get the transform components out of the world matrix.
351 * It stores the value in the mValue member variable
353 void ComputeTransformComponent() const
357 const Matrix& worldMatrix = mTxManager->GetWorldMatrix(mId);
359 if( mProperty == TRANSFORM_PROPERTY_WORLD_POSITION )
361 mValue = worldMatrix.GetTranslation3();
363 else if( mProperty == TRANSFORM_PROPERTY_WORLD_SCALE )
366 Quaternion orientation;
367 worldMatrix.GetTransformComponents(position, orientation, mValue);
373 * @copydoc Dali::PropertyInput::GetVector3()
375 const Vector3& GetVector3( BufferIndex bufferIndex ) const override
377 ComputeTransformComponent();
382 * @copydoc Dali::PropertyInput::GetConstraintInputVector3()
384 const Vector3& GetConstraintInputVector3( BufferIndex bufferIndex ) const override
386 ComputeTransformComponent();
391 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
393 Vector3& Get( BufferIndex bufferIndex )
395 ComputeTransformComponent();
400 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
402 const Vector3& Get( BufferIndex bufferIndex ) const
404 ComputeTransformComponent();
409 * Retrieve the property value.
410 * @param[in] bufferIndex The buffer to read.
411 * @return The property value.
413 const Vector3& operator[]( BufferIndex bufferIndex ) const
415 ComputeTransformComponent();
420 * Initializes the property
421 * @param[in] transformManager Pointer to the transform manager
422 * @param[in] Id of the transformation the property is associated with
424 void Initialize( TransformManager* transformManager, TransformId id )
426 mTxManager = transformManager;
431 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
433 bool IsTransformManagerProperty() const override
441 TransformManagerVector3Input(const TransformManagerVector3Input& property);
444 TransformManagerVector3Input& operator=(const TransformManagerVector3Input& rhs);
448 TransformManager* mTxManager;
450 TransformManagerProperty mProperty;
451 mutable Vector3 mValue;
455 * A Quaternion property used as input.
457 class TransformManagerQuaternionInput : public PropertyInputImpl
464 TransformManagerQuaternionInput()
465 :mTxManager(nullptr),
466 mId(INVALID_TRANSFORM_ID),
467 mValue(1.0f,0.0f,0.0f,0.0f)
472 * Virtual destructor.
474 ~TransformManagerQuaternionInput() override = default;
477 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
479 Dali::Property::Type GetType() const override
481 return Dali::PropertyTypes::Get<Quaternion>();
485 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
487 virtual bool IsClean() const
493 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
495 bool InputInitialized() const override
501 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
502 * @note A constraint can only receive the inherited property from the previous frame.
504 bool InputChanged() const override
510 * Helper function to get the orientation out of the world matrix.
511 * It stores the result in the mValue member variable
513 void ComputeTransformComponent() const
517 const Matrix& worldMatrix = mTxManager->GetWorldMatrix(mId);
518 Vector3 position, scale;
519 worldMatrix.GetTransformComponents(position, mValue, scale);
524 * @copydoc Dali::PropertyInput::GetQuaternion()
526 const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const override
528 ComputeTransformComponent();
533 * @copydoc Dali::PropertyInput::GetConstraintInputQuaternion()
535 const Quaternion& GetConstraintInputQuaternion( BufferIndex bufferIndex ) const override
537 ComputeTransformComponent();
542 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
544 Quaternion& Get( BufferIndex bufferIndex )
546 ComputeTransformComponent();
551 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
553 const Quaternion& Get( BufferIndex bufferIndex ) const
555 ComputeTransformComponent();
560 * Retrieve the property value.
561 * @param[in] bufferIndex The buffer to read.
562 * @return The property value.
564 const Quaternion& operator[]( BufferIndex bufferIndex) const
566 ComputeTransformComponent();
571 * Initializes the property
572 * @param[in] transformManager Pointer to the transform manager
573 * @param[in] Id of the transformation the property is associated with
575 void Initialize( TransformManager* transformManager, TransformId id )
577 mTxManager = transformManager;
582 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
584 bool IsTransformManagerProperty() const override
592 TransformManagerQuaternionInput(const TransformManagerQuaternionInput& property);
595 TransformManagerQuaternionInput& operator=(const TransformManagerQuaternionInput& rhs);
599 TransformManager* mTxManager;
601 mutable Quaternion mValue;
605 * A Matrix property used as input.
607 class TransformManagerMatrixInput : public PropertyInputImpl
614 TransformManagerMatrixInput()
615 :mTxManager(nullptr),
616 mId(INVALID_TRANSFORM_ID)
621 * Virtual destructor.
623 ~TransformManagerMatrixInput() override = default;
626 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
628 Dali::Property::Type GetType() const override
630 return Dali::PropertyTypes::Get<Matrix>();
634 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
636 virtual bool IsClean() const
642 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
644 bool InputInitialized() const override
650 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
651 * @note A constraint can only receive the inherited property from the previous frame.
653 bool InputChanged() const override
659 * @copydoc Dali::PropertyInput::GetMatrix()
661 const Matrix& GetMatrix( BufferIndex bufferIndex ) const override
665 return mTxManager->GetWorldMatrix(mId);
668 return Matrix::IDENTITY;
672 * @copydoc Dali::PropertyInput::GetConstraintInputMatrix()
674 const Matrix& GetConstraintInputMatrix( BufferIndex bufferIndex ) const override
678 return mTxManager->GetWorldMatrix(mId);
681 return Matrix::IDENTITY;
685 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
687 Matrix& Get( BufferIndex bufferIndex )
689 DALI_ASSERT_ALWAYS( mTxManager != nullptr );
690 return mTxManager->GetWorldMatrix(mId);
694 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
696 const Matrix& Get( BufferIndex bufferIndex ) const
698 return GetMatrix( bufferIndex );
702 * Retrieve the property value.
703 * @param[in] bufferIndex The buffer to read.
704 * @return The property value.
706 const Matrix& operator[]( BufferIndex bufferIndex ) const
708 return GetMatrix( bufferIndex );
711 void Initialize( TransformManager* transformManager, TransformId id )
713 mTxManager = transformManager;
718 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
720 bool IsTransformManagerProperty() const override
728 TransformManagerMatrixInput(const TransformManagerMatrixInput& property);
731 TransformManagerMatrixInput& operator=(const TransformManagerMatrixInput& rhs);
735 TransformManager* mTxManager;
740 } //namespace SceneGraph
741 } //namespace Internal
744 #endif // TRANSFORM_MANAGER_PROPERTY_H_