X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-scene3d%2Finternal%2Fcontrols%2Fmodel%2Fmodel-impl.h;h=d82fa8fcddeea76a4f50a907d54f2261af7046d4;hb=7892a19ca3a420eb54bcafa007d82bb5fe44c55c;hp=7bb4889b14f7760b3d09c5d14ceb0c609652c180;hpb=3a1d7305364d142dfc50aea1c4ba36cb4a1e78bb;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-scene3d/internal/controls/model/model-impl.h b/dali-scene3d/internal/controls/model/model-impl.h index 7bb4889..d82fa8f 100644 --- a/dali-scene3d/internal/controls/model/model-impl.h +++ b/dali-scene3d/internal/controls/model/model-impl.h @@ -2,7 +2,7 @@ #define DALI_SCENE3D_INTERNAL_MODEL_H /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,15 +20,25 @@ // EXTERNAL INCLUDES #include +#include +#include #include #include +#include #include #include +#include // INTERNAL INCLUDES -#include +#include +#include +#include +#include #include #include +#include +#include +#include namespace Dali { @@ -41,22 +51,37 @@ namespace Internal /** * @brief Impl class for Model. */ -class Model : public Dali::Toolkit::Internal::Control, public ImageBasedLightObserver +class Model : public Dali::Toolkit::Internal::Control, public LightObserver { public: - using AnimationData = std::pair; + using AnimationData = std::pair; + using CameraData = Loader::CameraParameters; + using BlendShapeModelNodeMap = std::map>; + + // ColliderMeshContainer doesn't hold actual collider meshes + // but pairs unique ModelNode id with ModelNode for lookup purposes. + // All model nodes in the container have collider mesh attached. + using ColliderMeshContainer = std::unordered_map; /** - * @brief Creates a new Model. - * - * @return A public handle to the newly allocated Model. + * @copydoc Model::New() */ static Dali::Scene3D::Model New(const std::string& modelUrl, const std::string& resourceDirectoryUrl); /** * @copydoc Model::GetModelRoot() */ - const Actor GetModelRoot() const; + const Scene3D::ModelNode GetModelRoot() const; + + /** + * @copydoc Model::AddModelNode() + */ + void AddModelNode(Scene3D::ModelNode modelNode); + + /** + * @copydoc Model::RemoveModelNode() + */ + void RemoveModelNode(Scene3D::ModelNode modelNode); /** * @copydoc Model::SetChildrenSensitive() @@ -84,11 +109,6 @@ public: void SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor); /** - * @copydoc Model::SetImageBasedLightTexture() - */ - void SetImageBasedLightTexture(Dali::Texture diffuseTexture, Dali::Texture specularTexture, float scaleFactor); - - /** * @copydoc Model::SetImageBasedLightScaleFactor() */ void SetImageBasedLightScaleFactor(float scaleFactor); @@ -113,9 +133,117 @@ public: */ Dali::Animation GetAnimation(const std::string& name) const; + /** + * @copydoc Model::GetCameraCount() + */ + uint32_t GetCameraCount() const; + + /** + * @copydoc Model::GenerateCamera() + */ + Dali::CameraActor GenerateCamera(uint32_t index) const; + + /** + * @copydoc Model::ApplyCamera() + */ + bool ApplyCamera(uint32_t index, Dali::CameraActor camera) const; + + /** + * @copydoc Model::FindChildModelNodeByName() + */ + Scene3D::ModelNode FindChildModelNodeByName(std::string_view nodeName); + + /** + * @copydoc Model::RetrieveBlendShapeNames() + */ + void RetrieveBlendShapeNames(std::vector& blendShapeNames) const; + + /** + * @copydoc Model::RetrieveModelNodesByBlendShapeName() + */ + void RetrieveModelNodesByBlendShapeName(std::string_view blendShapeName, std::vector& modelNodes) const; + + /** + * @copydoc Model::GenerateMotionDataAnimation() + */ + Dali::Animation GenerateMotionDataAnimation(Scene3D::MotionData motionData); + + /** + * @copydoc Model::SetMotionData() + */ + void SetMotionData(Scene3D::MotionData motionData); + + /** + * @copydoc Model::CastShadow() + */ + void CastShadow(bool castShadow); + + /** + * @copydoc Model::IsShadowCasting() + */ + bool IsShadowCasting() const; + + /** + * @copydoc Model::ReceiveShadow() + */ + void ReceiveShadow(bool receiveShadow); + + /** + * @copydoc Model::IsShadowReceiving() + */ + bool IsShadowReceiving() const; + + /** + * @copydoc Scene3D::Model::MeshHitSignal() + */ + Scene3D::Model::MeshHitSignalType& MeshHitSignal() + { + return mMeshHitSignal; + } + + /** + * @brief Emits MeshHitSignal + * @param[in] modelNode ModelNode that has been hit + * @return Result of hit handling. + */ + bool EmitMeshHitSignal(Scene3D::ModelNode modelNode) + { + bool retVal = false; + if(!mMeshHitSignal.Empty()) + { + Scene3D::Model handle(GetOwner()); + retVal = mMeshHitSignal.Emit(handle, modelNode); + } + return retVal; + } + + /** + * @brief Returns collider mesh container + * @return Returns valid container + */ + const ColliderMeshContainer& GetNodeColliderMeshContainer() const + { + return mColliderMeshes; + } + + /** + * @brief Registers child node with collidier mesh + * + * @param[in] node ModelNode to register + */ + void RegisterColliderMesh(Scene3D::ModelNode& node); + + /** + * @brief Removes node/collider mesh from the register + * @param[in] node Child node to remove from the register + */ + void RemoveColliderMesh(Scene3D::ModelNode& node); + protected: /** * @brief Constructs a new Model. + * @param[in] modelUrl model file path.(e.g., glTF, and DLI). + * @param[in] resourceDirectoryUrl resource file path that includes binary, image etc. */ Model(const std::string& modelUrl, const std::string& resourceDirectoryUrl); @@ -141,6 +269,11 @@ private: void OnSceneDisconnection() override; /** + * @copydoc CustomActorImpl::OnSizeSet( const Vector3& size ) + */ + void OnSizeSet(const Vector3& size) override; + + /** * @copydoc Toolkit::Control::GetNaturalSize */ Vector3 GetNaturalSize() override; @@ -165,15 +298,16 @@ private: */ bool IsResourceReady() const override; +private: /** - * @brief Loads a model from file + * @brief Create Model Root of this Model class. */ - void LoadModel(); + void CreateModelRoot(); /** * @brief Scales the model to fit the control or to return to original size. */ - void ScaleModel(); + void ScaleModel(bool useCurrentSize); /** * @brief Changes model anchor point to set the model at center or returns to the original model pivot. @@ -181,9 +315,24 @@ private: void FitModelPosition(); /** + * @brief Makes the input node cast shadow or not. + */ + void UpdateCastShadowRecursively(Scene3D::ModelNode node, bool castShadow); + + /** + * @brief Makes the input node receive shadow or not. + */ + void UpdateReceiveShadowRecursively(Scene3D::ModelNode node, bool receiveShadow); + + /** * @brief Changes IBL information of the input node. */ - void CollectRenderableActor(Actor actor); + void UpdateImageBasedLightTextureRecursively(Scene3D::ModelNode node, Dali::Texture diffuseTexture, Dali::Texture specularTexture, float iblScaleFactor, uint32_t specularMipmapLevels); + + /** + * @brief Changes IBL factor of the input node. + */ + void UpdateImageBasedLightScaleFactorRecursively(Scene3D::ModelNode node, float iblScaleFactor); /** * @brief Changes IBL textures of the input node. @@ -195,26 +344,117 @@ private: */ void UpdateImageBasedLightScaleFactor(); -public: // Overrides ImageBasedLightObserver Methods. /** - * @copydoc Dali::Scene3D::Internal::ImageBasedLightObserver::NotifyImageBasedLightTexture() + * @brief Apply self transform into inputed camera. + * Inputed camera must be configured by CameraParameter. Mean, inputed camera coordinate depend on Model. + * After this API finished, CameraActor coordinate system converted as DALi coordinate system. + * + * @param[in,out] camera CameraActor who need to apply model itself's transform */ - void NotifyImageBasedLightTexture(Dali::Texture diffuseTexture, Dali::Texture specularTexture, float scaleFactor) override; + void ApplyCameraTransform(Dali::CameraActor camera) const; +public: // Overrides LightObserver Methods. /** - * @copydoc Dali::Scene3D::Internal::ImageBasedLightObserver::NotifyImageBasedLightScaleFactor() + * @copydoc Dali::Scene3D::Internal::LightObserver::NotifyShadowMapTexture() + */ + void NotifyShadowMapTexture(Dali::Texture shadowMapTexture) override; + + /** + * @copydoc Dali::Scene3D::Internal::LightObserver::NotifyImageBasedLightTexture() + */ + void NotifyImageBasedLightTexture(Dali::Texture diffuseTexture, Dali::Texture specularTexture, float scaleFactor, uint32_t specularMipmapLevels) override; + + /** + * @copydoc Dali::Scene3D::Internal::LightObserver::NotifyImageBasedLightScaleFactor() */ void NotifyImageBasedLightScaleFactor(float scaleFactor) override; private: + /** + * @brief Asynchronously model loading finished. + */ + void OnModelLoadComplete(); + + /** + * @brief Asynchronously ibl diffusel image loading finished. + */ + void OnIblDiffuseLoadComplete(); + + /** + * @brief Asynchronously ibl specular image loading finished. + */ + void OnIblSpecularLoadComplete(); + + /** + * @brief Asynchronously ibl loading finished. + */ + void OnIblLoadComplete(); + + /** + * @brief Update model root scale when Model size property is updated. + */ + void OnSizeNotification(Dali::PropertyNotification& source); + + /** + * @brief Reset Resource loading tasks. + */ + void ResetResourceTasks(); + + /** + * @brief Notify Resource Ready signal. + */ + void NotifyResourceReady(); + + /** + * @brief Create Model from loaded SceneDefinition. + */ + void CreateModel(); + + /** + * @brief Create Dali::Animation from loaded AnimationDefinitions. + */ + void CreateAnimations(Dali::Scene3D::Loader::SceneDefinition& scene); + + /** + * @brief Reset CameraData from loaded CameraParameters. + */ + void ResetCameraParameters(); + + /** + * @brief Collect ModelNode list by blendshape name + */ + void UpdateBlendShapeNodeMap(); + +private: std::string mModelUrl; std::string mResourceDirectoryUrl; - Dali::Actor mModelRoot; + Scene3D::ModelNode mModelRoot; std::vector mAnimations; - std::vector> mRenderableActors; + std::vector mCameraParameters; WeakHandle mParentSceneView; + Dali::PropertyNotification mSizeNotification; + + // Signals + Scene3D::Model::MeshHitSignalType mMeshHitSignal; + + Dali::Scene3D::Loader::ShaderManagerPtr mShaderManager; + + ColliderMeshContainer mColliderMeshes; + + // List of ModelNode for name of blend shape. + BlendShapeModelNodeMap mBlendShapeModelNodeMap; + + // Asynchronous loading variable + ModelLoadTaskPtr mModelLoadTask; + EnvironmentMapLoadTaskPtr mIblDiffuseLoadTask; + EnvironmentMapLoadTaskPtr mIblSpecularLoadTask; + + // Shadow + Dali::Texture mShadowMapTexture; + + std::string mDiffuseIblUrl; + std::string mSpecularIblUrl; - // TODO: This default texture can be removed after 3D Resource Cache is added. Dali::Texture mDefaultSpecularTexture; Dali::Texture mDefaultDiffuseTexture; Dali::Texture mSceneSpecularTexture; @@ -225,10 +465,17 @@ private: Vector3 mModelPivot; float mSceneIblScaleFactor; float mIblScaleFactor; + uint32_t mSceneSpecularMipmapLevels; + uint32_t mSpecularMipmapLevels; bool mModelChildrenSensitive; bool mModelChildrenFocusable; bool mModelResourceReady; - bool mIBLResourceReady; + bool mIblDiffuseResourceReady; + bool mIblSpecularResourceReady; + bool mIblDiffuseDirty; + bool mIblSpecularDirty; + bool mIsShadowCasting; + bool mIsShadowReceiving; }; } // namespace Internal