• 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_ICREATE_MESH_H
17 #define SCENE_INTERFACE_ICREATE_MESH_H
18 
19 #include <scene/base/namespace.h>
20 #include <scene/base/types.h>
21 #include <scene/interface/intf_mesh.h>
22 
23 #include <meta/base/interface_macros.h>
24 
25 SCENE_BEGIN_NAMESPACE()
26 
27 /// Configuration for creating mesh
28 struct MeshConfig {
29     BASE_NS::string name;
30     IMaterial::Ptr material;
31 };
32 
33 /// Mesh primitive topology
34 enum class PrimitiveTopology {
35     TRIANGLE_LIST = 3,
36     TRIANGLE_STRIP = 4,
37 };
38 
39 /// Custom data to create mesh. Normals, uvs and colors are optional.
40 struct CustomMeshData {
41     PrimitiveTopology topology { PrimitiveTopology::TRIANGLE_LIST };
42     BASE_NS::vector<BASE_NS::Math::Vec3> vertices;
43     BASE_NS::vector<uint32_t> indices;
44     BASE_NS::vector<BASE_NS::Math::Vec3> normals;
45     BASE_NS::vector<BASE_NS::Math::Vec2> uvs;
46     BASE_NS::vector<BASE_NS::Color> colors;
47 };
48 
49 /// Interface to create meshes
50 class ICreateMesh : public CORE_NS::IInterface {
51     META_INTERFACE(CORE_NS::IInterface, ICreateMesh, "727c676f-e20b-403a-93b1-a6116b3b36d9")
52 public:
53     /// Create custom mesh from given data
54     virtual Future<IMesh::Ptr> Create(const MeshConfig&, CustomMeshData data) = 0;
55 
56     /// Create cube mesh from given data
57     virtual Future<IMesh::Ptr> CreateCube(const MeshConfig&, float width, float height, float depth) = 0;
58     /// Create plane mesh from given data
59     virtual Future<IMesh::Ptr> CreatePlane(const MeshConfig&, float width, float depth) = 0;
60     /// Create sphere mesh from given data
61     virtual Future<IMesh::Ptr> CreateSphere(const MeshConfig&, float radius, uint32_t rings, uint32_t sectors) = 0;
62     /// Create cone mesh from given data
63     virtual Future<IMesh::Ptr> CreateCone(const MeshConfig&, float radius, float length, uint32_t sectors) = 0;
64 };
65 
66 META_REGISTER_CLASS(MeshCreator, "e920536a-8b5b-4503-a299-7e7f3fc2f603", META_NS::ObjectCategoryBits::NO_CATEGORY)
67 
68 SCENE_END_NAMESPACE()
69 
70 META_INTERFACE_TYPE(SCENE_NS::ICreateMesh)
71 META_TYPE(SCENE_NS::MeshConfig)
72 META_TYPE(SCENE_NS::PrimitiveTopology)
73 META_TYPE(SCENE_NS::CustomMeshData)
74 
75 #endif
76