• 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_INTERFACE_IMESH_H
17 #define SCENE_INTERFACE_IMESH_H
18 
19 #include <scene/base/namespace.h>
20 #include <scene/base/types.h>
21 #include <scene/interface/intf_material.h>
22 
23 #include <meta/base/interface_macros.h>
24 
SCENE_BEGIN_NAMESPACE()25 SCENE_BEGIN_NAMESPACE()
26 
27 /**
28  * @brief The IMorpher interface defines the properties of morph targets.
29  */
30 class IMorpher : public CORE_NS::IInterface {
31     META_INTERFACE(CORE_NS::IInterface, IMorpher, "a76d0ce9-4d20-4d0d-9c55-32fb703d4766")
32 public:
33     /**
34      * @brief Morph target names.
35      */
36     META_ARRAY_PROPERTY(BASE_NS::string, MorphNames)
37     /**
38      * @brief Morph target weights.
39      */
40     META_ARRAY_PROPERTY(float, MorphWeights)
41 };
42 
43 /**
44  * @brief The ISubMesh interface defines the properties of a SubMesh.
45  */
46 class ISubMesh : public CORE_NS::IInterface {
47     META_INTERFACE(CORE_NS::IInterface, ISubMesh, "89060424-5034-43e2-af6c-a7554b90c107")
48 public:
49     /**
50      * @brief Material of the object.
51      */
52     META_PROPERTY(IMaterial::Ptr, Material)
53     /**
54      * @brief Axis aligned bounding box min of the object.
55      */
56     META_PROPERTY(BASE_NS::Math::Vec3, AABBMin)
57     /**
58      * @brief Axis aligned bounding box max of the object.
59      */
60     META_PROPERTY(BASE_NS::Math::Vec3, AABBMax)
61 };
62 
63 /**
64  * @brief The IMesh interface defines the properties of a Mesh.
65  */
66 class IMesh : public CORE_NS::IInterface {
67     META_INTERFACE(CORE_NS::IInterface, IMesh, "aab724a6-312d-4872-9ff2-b7bed8571b44")
68 public:
69     /**
70      * @brief Axis aligned bounding box min. Calculated using all submeshes.
71      */
72     META_READONLY_PROPERTY(BASE_NS::Math::Vec3, AABBMin)
73     /**
74      * @brief Axis aligned bounding box max. Calculated using all submeshes.
75      */
76     META_READONLY_PROPERTY(BASE_NS::Math::Vec3, AABBMax)
77     /**
78      * @brief Array of submeshes.
79      */
80     META_READONLY_ARRAY_PROPERTY(ISubMesh::Ptr, SubMeshes)
81 };
82 
83 /**
84  * @brief Set material for all submeshes
85  */
SetMaterialForAllSubMeshes(const IMesh::Ptr & mesh,const IMaterial::Ptr & material)86 inline bool SetMaterialForAllSubMeshes(const IMesh::Ptr& mesh, const IMaterial::Ptr& material)
87 {
88     if (mesh) {
89         for (auto&& s : mesh->SubMeshes()->GetValue()) {
90             META_NS::SetValue(s->Material(), material);
91         }
92         return true;
93     }
94     return false;
95 }
96 
97 /**
98  * @brief The IMeshAccess interface defines the methods that can be used to access the Mesh of an object.
99  */
100 class IMeshAccess : public CORE_NS::IInterface {
101     META_INTERFACE(CORE_NS::IInterface, IMeshAccess, "63703b44-c1f5-437e-9d57-4248d1b69311")
102 public:
103     /**
104      * @brief Sets the mesh of the implementing object.
105      */
106     virtual Future<bool> SetMesh(const IMesh::Ptr&) = 0;
107     /**
108      * @brief Returns the mesh of the implementing object.
109      */
110     virtual Future<IMesh::Ptr> GetMesh() const = 0;
111 };
112 
113 /**
114  * @brief The IMorphAccess interface defines the methods that can be used to access the morph targets of an object.
115  */
116 class IMorphAccess : public CORE_NS::IInterface {
117     META_INTERFACE(CORE_NS::IInterface, IMorphAccess, "df64abcf-fd39-48b9-af1b-74abad800d0c")
118 public:
119     /**
120      * @brief IMorpher::Ptr object containing the the morph target information, or null if there are no morph targets.
121      */
122     META_READONLY_PROPERTY(IMorpher::Ptr, Morpher)
123 };
124 
125 META_REGISTER_CLASS(MeshNode, "e0ad59e3-ef66-4b74-8a40-59b1584f14dd", META_NS::ObjectCategoryBits::NO_CATEGORY)
126 META_REGISTER_CLASS(SubMesh, "7f48b697-9fba-43da-8b15-f61fbbf2a925", META_NS::ObjectCategoryBits::NO_CATEGORY)
127 META_REGISTER_CLASS(Mesh, "8478fc2b-13fe-4b59-963a-370c04a94d15", META_NS::ObjectCategoryBits::NO_CATEGORY)
128 
129 SCENE_END_NAMESPACE()
130 
131 META_INTERFACE_TYPE(SCENE_NS::IMorpher)
132 META_INTERFACE_TYPE(SCENE_NS::ISubMesh)
133 META_INTERFACE_TYPE(SCENE_NS::IMesh)
134 
135 #endif
136