• 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_MESH_MESH_H
17 #define SCENE_SRC_MESH_MESH_H
18 
19 #include <mutex>
20 #include <scene/ext/ecs_lazy_property.h>
21 #include <scene/ext/intf_create_entity.h>
22 #include <scene/interface/intf_mesh.h>
23 
24 #include <meta/api/event_handler.h>
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_owner.h>
29 
30 #include "component/mesh_component.h"
31 
SCENE_BEGIN_NAMESPACE()32 SCENE_BEGIN_NAMESPACE()
33 
34 class Mesh : public META_NS::IntroduceInterfaces<NamedSceneObject, IMesh, ICreateEntity, CORE_NS::IResource> {
35     META_OBJECT(Mesh, ClassId::Mesh, IntroduceInterfaces)
36 public:
37     void Destroy() override;
38 
39     META_BEGIN_STATIC_DATA()
40     META_STATIC_FORWARDED_PROPERTY_DATA(IMesh, BASE_NS::Math::Vec3, AABBMin)
41     META_STATIC_FORWARDED_PROPERTY_DATA(IMesh, BASE_NS::Math::Vec3, AABBMax)
42     SCENE_STATIC_DYNINIT_ARRAY_PROPERTY_DATA(IMesh, ISubMesh::Ptr, SubMeshes, "")
43     META_END_STATIC_DATA()
44 
45     META_FORWARD_READONLY_PROPERTY(BASE_NS::Math::Vec3, AABBMin, mesh_->AABBMin())
46     META_FORWARD_READONLY_PROPERTY(BASE_NS::Math::Vec3, AABBMax, mesh_->AABBMax())
47     META_IMPLEMENT_READONLY_ARRAY_PROPERTY(ISubMesh::Ptr, SubMeshes)
48 
49 public:
50     bool SetEcsObject(const IEcsObject::Ptr&) override;
51     CORE_NS::Entity CreateEntity(const IInternalScene::Ptr& scene) override;
52     bool InitDynamicProperty(const META_NS::IProperty::Ptr& p, BASE_NS::string_view path) override;
53 
54 public: // IResource (empty implementation as placeholder, needed to initialize API Mesh resource with IMesh::Ptr
55     CORE_NS::ResourceType GetResourceType() const override
56     {
57         return {};
58     }
59     CORE_NS::ResourceId GetResourceId() const override
60     {
61         return {};
62     }
63 
64 private:
65     void SetInternalMesh(IInternalMesh::Ptr m);
66     BASE_NS::vector<CORE3D_NS::MeshComponent::Submesh> ConstructComponentSubmeshes(
67         const BASE_NS::vector<ISubMesh::Ptr>& submeshes) const;
68 
69     IEcsObject::Ptr GetMeshEcsObject() const;
70     void RecalculateAABB();
71     bool UpdateSubmeshes(META_NS::ArrayProperty<ISubMesh::Ptr> prop);
72     void RefreshSubmeshes(const BASE_NS::vector<ISubMesh::Ptr>& subs);
73 
74 protected:
75     mutable std::mutex mutex_;
76     CORE_NS::EntityReference meshEntity_;
77     IInternalMesh::Ptr mesh_;
78     META_NS::EventHandler submeshEvent_;
79 };
80 
81 SCENE_END_NAMESPACE()
82 
83 #endif
84