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 #ifndef SCENEPLUGIN_INTF_MESH_H
16 #define SCENEPLUGIN_INTF_MESH_H
17 
18 #include <scene_plugin/interface/intf_material.h>
19 #include <scene_plugin/interface/intf_node.h>
20 #include <scene_plugin/interface/mesh_arrays.h>
21 
22 #include <base/containers/vector.h>
23 
24 #include <meta/api/animation/animation.h>
25 #include <meta/base/types.h>
26 #include <meta/interface/intf_container.h>
27 
28 SCENE_BEGIN_NAMESPACE()
29 
30 // Implemented by SCENE_NS::ClassId::SubMesh
31 REGISTER_INTERFACE(ISubMesh, "b203cb19-923a-44a1-aa9b-17854721f90e")
32 class ISubMesh : public META_NS::INamed {
33     META_INTERFACE(META_NS::INamed, ISubMesh, InterfaceId::ISubMesh)
34 public:
35     META_PROPERTY(SCENE_NS::IMaterial::Ptr, Material)
36     META_PROPERTY(uint64_t, Handle)
37     META_PROPERTY(BASE_NS::Math::Vec3, AABBMin)
38     META_PROPERTY(BASE_NS::Math::Vec3, AABBMax)
39     META_PROPERTY(uint8_t, RenderSortLayerOrder)
40     META_READONLY_PROPERTY(BASE_NS::string, MaterialUri)
41 
42     virtual void SetRenderSortLayerOrder(uint8_t order) = 0;
43     virtual void SetAABBMin(BASE_NS::Math::Vec3) = 0;
44     virtual void SetAABBMax(BASE_NS::Math::Vec3) = 0;
45     virtual void SetMaterial(SCENE_NS::IMaterial::Ptr) = 0;
46 };
47 
48 SCENE_END_NAMESPACE()
49 
50 META_TYPE(SCENE_NS::ISubMesh::WeakPtr);
51 META_TYPE(SCENE_NS::ISubMesh::Ptr);
52 
53 SCENE_BEGIN_NAMESPACE()
54 
55 // Implemented by SCENE_NS::ClassId::Mesh
56 REGISTER_INTERFACE(IMesh, "d66a1419-a79f-4e80-a133-31aee86da8bd")
57 class IMesh : public CORE_NS::IInterface {
58     META_INTERFACE(CORE_NS::IInterface, IMesh, InterfaceId::IMesh)
59 public:
60     /**
61      * @brief Allows to override all submesh materials with a single material.
62      * @return Material that is used to override all submesh materials, if set.
63      */
64     META_PROPERTY(SCENE_NS::IMaterial::Ptr, MaterialOverride)
65 
66     /**
67      * @brief Allows to read the uri of the override material, if set.
68      * @return Uri of the override material, if iset.
69      */
70     META_READONLY_PROPERTY(BASE_NS::string, MaterialOverrideUri)
71 
72     /**
73      * @brief Get list of all submeshes attached to this mesh.
74      * @return Array of submeshes.
75      */
76     META_READONLY_ARRAY_PROPERTY(ISubMesh::Ptr, SubMeshes)
77 
78     /**
79      * @brief Axis aligned bounding box min. Calculated using all submeshes.
80      * @return vector defining the min point.
81      */
82     META_READONLY_PROPERTY(BASE_NS::Math::Vec3, AABBMin)
83     /**
84      * @brief Axis aligned bounding box max. Calculated using all submeshes.
85      * @return vector defining the max point.
86      */
87     META_READONLY_PROPERTY(BASE_NS::Math::Vec3, AABBMax)
88 
89     /**
90      * @brief Get material handle from submesh, async
91      * @param index The selected submesh index.
92      * @return pointer to material.
93      */
94     virtual IMaterial::Ptr GetMaterial(size_t index) = 0;
95 
96     /**
97      * @brief Set given material for all the submeshes.
98      */
99     virtual void SetMaterial(const IMaterial::Ptr material) = 0;
100 
101     /**
102      * @brief Set material for the selected submesh.
103      * @param index The selected submesh index.
104      * @param material The material to set.
105      */
106     virtual void SetMaterial(size_t index, const IMaterial::Ptr& material) = 0;
107 
108     /**
109      * @brief Get render sort layer order for selected submesh
110      * @return The layer order for selected index, if the index is not present, returns 0u.
111      */
112     virtual uint8_t GetRenderSortLayerOrder(size_t index) const = 0;
113 
114     /**
115      * @brief Within a render slot, a layer can define a sort layer order for a submesh.
116      * There are 0-63 values available. Default id value is 32.
117      * 0 first, 63 last
118      * 1. Typical use case is to set render sort layer to objects which render with depth test without depth write.
119      * 2. Typical use case is to always render character and/or camera object first to cull large parts of the view.
120      * 3. Sort e.g. plane layers.     * @param index The selected submesh index.
121      * @param index The selected submesh index.
122      * @param value The layer order number.
123      */
124     virtual void SetRenderSortLayerOrder(size_t index, uint8_t value) = 0;
125 
126     /**
127      * @brief Update mesh data from the arrays. 16 bit indices.
128      * @param arrays defining the mesh, see MeshGeometryArray.
129      */
130     virtual void UpdateMeshFromArraysI16(MeshGeometryArrayPtr<uint16_t> arrays) = 0;
131 
132     /**
133      * @brief Update mesh data from the arrays. 32 bit indices.
134      * @param arrays defining the mesh, see MeshGeometryArray.
135      */
136     virtual void UpdateMeshFromArraysI32(MeshGeometryArrayPtr<uint32_t> arrays) = 0;
137 
138     /**
139      * @brief Add submesh data from the arrays. 16 bit indices.
140      * @param arrays defining the mesh, see MeshGeometryArray.
141      */
142     virtual void AddSubmeshesFromArrayI16(MeshGeometryArrayPtr<uint16_t> arrays) = 0;
143 
144     /**
145      * @brief Add submesh data from the arrays. 32 bit indices.
146      * @param arrays defining the mesh, see MeshGeometryArray.
147      */
148     virtual void AddSubmeshesFromArraysI32(MeshGeometryArrayPtr<uint32_t> arrays) = 0;
149 
150     virtual void CloneSubmesh(ISubMesh::Ptr submesh) = 0;
151     virtual void RemoveSubMesh(size_t index) = 0;
152     virtual void RemoveAllSubmeshes() = 0;
153 };
154 
155 SCENE_END_NAMESPACE()
156 
157 META_TYPE(SCENE_NS::IMesh::WeakPtr);
158 META_TYPE(SCENE_NS::IMesh::Ptr);
159 
160 SCENE_BEGIN_NAMESPACE()
161 
162 // Implemented by SCENE_NS::ClassId::MultiMeshProxy
163 REGISTER_INTERFACE(IMultiMeshProxy, "3a2f5b77-0778-4a67-a41f-4a54d9a4261d")
164 class IMultiMeshProxy : public CORE_NS::IInterface {
165     META_INTERFACE(CORE_NS::IInterface, IMultiMeshProxy, InterfaceId::IMultiMeshProxy)
166 public:
167     /**
168      * @brief Allows to override all submesh materials with a single material.
169      * @return Material that is used to override all submesh materials, if set.
170      */
171     META_PROPERTY(SCENE_NS::IMaterial::Ptr, MaterialOverride)
172 
173     /**
174      * @brief Allows to read the uri of the override material, if set.
175      * @return Uri of the override material, if iset.
176      */
177     // META_READONLY_PROPERTY(BASE_NS::string, MaterialOverrideUri)
178 
179     /**
180      * @brief The mesh attached to the batch
181      * @return Pointer to property
182      */
183     META_PROPERTY(IMesh::Ptr, Mesh)
184 
185     /**
186      * @brief The amount of visible instances
187      * @return Pointer to property
188      */
189     META_PROPERTY(size_t, VisibleInstanceCount)
190 
191     /**
192      * @brief The custom data for the batch
193      * @return Pointer to property
194      */
195     META_ARRAY_PROPERTY(BASE_NS::Math::Vec4, CustomData)
196 
197     /**
198      * @brief The transformations for batch
199      * @return Pointer to property
200      */
201     META_ARRAY_PROPERTY(BASE_NS::Math::Mat4X4, Transforms)
202 
203     virtual void SetInstanceCount(size_t count) = 0;
204 };
205 
206 SCENE_END_NAMESPACE()
207 
208 META_TYPE(SCENE_NS::IMultiMeshProxy::WeakPtr);
209 META_TYPE(SCENE_NS::IMultiMeshProxy::Ptr);
210 
211 #endif // SCENEPLUGIN_INTF_MESH_H
212