• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SRC_SCENE_H
17 #define SCENE_SRC_SCENE_H
18 
19 #include <scene/ext/ecs_lazy_property.h>
20 #include <scene/ext/scene_property.h>
21 #include <scene/interface/intf_raycast.h>
22 #include <scene/interface/intf_scene.h>
23 #include <scene/interface/resource/types.h>
24 
25 #include <meta/ext/implementation_macros.h>
26 #include <meta/ext/object.h>
27 #include <meta/ext/resource/resource.h>
28 #include <meta/interface/intf_task_queue.h>
29 
30 #include "core/internal_scene.h"
31 #include "resource/types/scene_type.h"
32 
SCENE_BEGIN_NAMESPACE()33 SCENE_BEGIN_NAMESPACE()
34 
35 class SceneObject : public META_NS::IntroduceInterfaces<META_NS::MetaObject, META_NS::Resource, META_NS::INamed, IScene,
36                         IEnginePropertyInit, IRayCast> {
37     META_OBJECT(SceneObject, SCENE_NS::ClassId::Scene, IntroduceInterfaces)
38 
39 public:
40     SceneObject() = default;
41     ~SceneObject();
42 
43     META_BEGIN_STATIC_DATA()
44     SCENE_STATIC_DYNINIT_PROPERTY_DATA(IScene, SCENE_NS::IRenderConfiguration::Ptr, RenderConfiguration, "")
45     META_STATIC_PROPERTY_DATA(META_NS::INamed, BASE_NS::string, Name)
46     META_END_STATIC_DATA()
47 
48     META_IMPLEMENT_READONLY_PROPERTY(IRenderConfiguration::Ptr, RenderConfiguration)
49     META_IMPLEMENT_PROPERTY(BASE_NS::string, Name)
50 
51 public:
52     bool Build(const META_NS::IMetadata::Ptr&) override;
53     BASE_NS::string GetName() const override
54     {
55         return META_NS::GetValue(Name());
56     }
57     bool InitDynamicProperty(const META_NS::IProperty::Ptr& p, BASE_NS::string_view path) override;
58     bool AttachEngineProperty(const META_NS::IProperty::Ptr& p, BASE_NS::string_view path) override;
59 
60     Future<BASE_NS::vector<ICamera::Ptr>> GetCameras() const override;
61     Future<BASE_NS::vector<META_NS::IAnimation::Ptr>> GetAnimations() const override;
62 
63     Future<INode::Ptr> GetRootNode() const override;
64     Future<INode::Ptr> CreateNode(const BASE_NS::string_view path, META_NS::ObjectId id) override;
65     Future<INode::Ptr> FindNode(BASE_NS::string_view path, META_NS::ObjectId id) const override;
66     Future<bool> ReleaseNode(INode::Ptr&& node, bool recursive) override;
67     Future<bool> RemoveNode(const INode::Ptr& node) override;
68 
69     IComponent::Ptr GetComponent(const INode::Ptr& node, BASE_NS::string_view componentName) const override;
70     Future<IComponent::Ptr> CreateComponent(const INode::Ptr& node, BASE_NS::string_view componentName) override;
71 
72     using Super::CreateObject;
73     Future<META_NS::IObject::Ptr> CreateObject(META_NS::ObjectId id) override;
74 
75     void StartAutoUpdate(META_NS::TimeSpan interval) override;
76 
77     Future<bool> SetRenderMode(RenderMode) override;
78     Future<RenderMode> GetRenderMode() const override;
79 
80     Future<NodeHits> CastRay(
81         const BASE_NS::Math::Vec3& pos, const BASE_NS::Math::Vec3& dir, const RayCastOptions& options) const override;
82 
83 public:
84     IInternalScene::Ptr GetInternalScene() const override;
85 
86 private:
87     CORE_NS::ResourceType GetResourceType() const override
88     {
89         return ClassId::SceneResource.Id().ToUid();
90     }
91 
92 private:
93     IInternalScene::Ptr internal_;
94     META_NS::ITaskQueue::Token updateTask_ {};
95 };
96 
97 SCENE_END_NAMESPACE()
98 
99 #endif
100