1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef SCENE_INTERFACE_ISCENE_H 17 #define SCENE_INTERFACE_ISCENE_H 18 19 #include <scene/base/types.h> 20 #include <scene/ext/intf_component.h> 21 #include <scene/interface/intf_camera.h> 22 #include <scene/interface/intf_node.h> 23 #include <scene/interface/intf_render_configuration.h> 24 25 #include <render/intf_render_context.h> 26 27 #include <meta/base/interface_macros.h> 28 #include <meta/interface/animation/intf_animation.h> 29 30 SCENE_BEGIN_NAMESPACE() 31 32 class IInternalScene; 33 34 class IScene : public CORE_NS::IInterface { 35 META_INTERFACE(CORE_NS::IInterface, IScene, "b61d5521-bfa9-4465-9e4d-65d4358ede26") 36 public: 37 META_READONLY_PROPERTY(IRenderConfiguration::Ptr, RenderConfiguration) 38 39 public: 40 /** 41 * @brief Get root node for the scene 42 * @return Root node 43 */ 44 virtual Future<INode::Ptr> GetRootNode() const = 0; 45 46 /** 47 * @brief Add new node to the scene 48 * @param path Path of the node 49 * @param id Type of the node, defaults to generic node 50 * @return Newly created node 51 */ 52 virtual Future<INode::Ptr> CreateNode(BASE_NS::string_view path, META_NS::ObjectId id = {}) = 0; 53 54 /** 55 * @brief Find node in scene. This will find node with given type in scene and constructs node object for it 56 * @notice Nodes are cached, the existing node object is returned if there is such 57 * @param path Path of the node 58 * @param id Type of the node, if not given, the system tries to deduce the node type and falls back to generic 59 * node 60 * @return Found node or null if no such node exists or doesn't match the type 61 */ 62 virtual Future<INode::Ptr> FindNode(BASE_NS::string_view path, META_NS::ObjectId id = {}) const = 0; 63 64 /** 65 * @brief Remove the node (and possibly its children) from caches if it is the only instance and stop listening 66 * notifications related to it. This does not affect ECS side. 67 * @notice You have to move the last user instance of node to this function for it to have any effect. 68 * @param node Node to release 69 * @param recursive Should we check all child nodes recursive and try to release them 70 * @return True is the given node was released, otherwise false 71 */ 72 virtual Future<bool> ReleaseNode(INode::Ptr&& node, bool recursive) = 0; 73 74 /** 75 * @brief Remove the node (and its children) from the scene (the underlying ecs) 76 * @notice Do not use the node after this! 77 */ 78 virtual Future<bool> RemoveNode(const INode::Ptr& node) = 0; 79 80 template<class T> 81 Future<typename T::Ptr> CreateNode(BASE_NS::string_view path, META_NS::ObjectId id = {}) 82 { 83 return CreateNode(path, id).Then([](INode::Ptr d) { return interface_pointer_cast<T>(d); }, nullptr); 84 } 85 86 template<class T> 87 Future<typename T::Ptr> FindNode(BASE_NS::string_view path, META_NS::ObjectId id = {}) const 88 { 89 return FindNode(path, id).Then([](INode::Ptr d) { return interface_pointer_cast<T>(d); }, nullptr); 90 } 91 92 virtual Future<META_NS::IObject::Ptr> CreateObject(META_NS::ObjectId id) = 0; 93 94 template<class T> CreateObject(META_NS::ObjectId id)95 Future<typename T::Ptr> CreateObject(META_NS::ObjectId id) 96 { 97 return CreateObject(id).Then([](META_NS::IObject::Ptr d) { return interface_pointer_cast<T>(d); }, nullptr); 98 } 99 100 virtual Future<BASE_NS::vector<ICamera::Ptr>> GetCameras() const = 0; 101 virtual Future<BASE_NS::vector<META_NS::IAnimation::Ptr>> GetAnimations() const = 0; 102 103 virtual BASE_NS::shared_ptr<IInternalScene> GetInternalScene() const = 0; 104 105 virtual void StartAutoUpdate(META_NS::TimeSpan interval) = 0; 106 107 virtual Future<bool> SetRenderMode(RenderMode) = 0; 108 virtual Future<RenderMode> GetRenderMode() const = 0; 109 110 /** 111 * @brief Returns a component from given node. 112 * @param node Node to query the component from. 113 * @param componentName Name of the component manager to query. 114 * @return The component or nullptr if not found from the node. 115 */ 116 virtual IComponent::Ptr GetComponent(const INode::Ptr& node, BASE_NS::string_view componentName) const = 0; 117 /** 118 * @brief Create a new component with given component manager name and attaches it to given node. 119 * @param node The node for which the component should be created. 120 * @param componentName Name of the component manager for the component. 121 * @return If the name is valid, returns a component attached to node with given name. 122 * If the name is invalid, returns nullptr. 123 */ 124 virtual Future<IComponent::Ptr> CreateComponent(const INode::Ptr& node, BASE_NS::string_view componentName) = 0; 125 }; 126 127 META_REGISTER_CLASS(Scene, "ef6321d7-071c-414a-bb3d-55ea6f94688e", META_NS::ObjectCategoryBits::NO_CATEGORY) 128 129 SCENE_END_NAMESPACE() 130 131 META_INTERFACE_TYPE(SCENE_NS::IScene) 132 META_TYPE(BASE_NS::shared_ptr<RENDER_NS::IRenderContext>) 133 134 #endif 135