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 API_3D_UTIL_IMESH_UTIL_H
17 #define API_3D_UTIL_IMESH_UTIL_H
18
19 #include <3d/namespace.h>
20 #include <base/containers/string_view.h>
21 #include <core/ecs/entity.h>
22 #include <render/resource_handle.h>
23
24 CORE_BEGIN_NAMESPACE()
25 class IEcs;
26 CORE_END_NAMESPACE()
27
CORE3D_BEGIN_NAMESPACE()28 CORE3D_BEGIN_NAMESPACE()
29 /** \addtogroup group_util_meshutil
30 * @{
31 */
32
33 class IMeshUtil {
34 public:
35 /** Generate cube mesh.
36 * @param ecs ECS instance where entity will live.
37 * @param name Name of the mesh resource.
38 * @param material Material for mesh resource, if not set will use default glTF material.
39 * @param width Width of the cube (in x dimension).
40 * @param height Height of the cube (in y dimension).
41 * @param depth Depth of the cube (in z dimension).
42 */
43 virtual CORE_NS::Entity GenerateCubeMesh(const CORE_NS::IEcs& ecs, BASE_NS::string_view name,
44 CORE_NS::Entity material, float width, float height, float depth) = 0;
45
46 /** Generate plane mesh.
47 * @param ecs ECS instance where entity will live.
48 * @param name Name of the mesh resource.
49 * @param material Material for mesh resource, if not set will use default glTF material.
50 * @param width Width of the plane (in x dimension).
51 * @param depth Depth of the plane (in z dimension).
52 */
53 virtual CORE_NS::Entity GeneratePlaneMesh(
54 const CORE_NS::IEcs& ecs, BASE_NS::string_view name, CORE_NS::Entity material, float width, float depth) = 0;
55
56 /** Generate sphere mesh.
57 * @param ecs ECS instance where entity will live.
58 * @param name Name of the mesh resource.
59 * @param material Material for mesh resource, if not set will use default glTF material.
60 * @param radius Radius of the sphere.
61 * @param rings Number of rings in sphere.
62 * @param sectors Number of sectors per ring.
63 */
64 virtual CORE_NS::Entity GenerateSphereMesh(const CORE_NS::IEcs& ecs, BASE_NS::string_view name,
65 CORE_NS::Entity material, float radius, uint32_t rings, uint32_t sectors) = 0;
66
67 /** Generate cone mesh.
68 * @param ecs ECS instance where entity will live.
69 * @param name Name of the mesh resource.
70 * @param material Material for mesh resource, if not set will use default glTF material.
71 * @param radius Radius of the cone ring.
72 * @param length Length of cone.
73 * @param sectors Number of sectors in ring.
74 */
75 virtual CORE_NS::Entity GenerateConeMesh(const CORE_NS::IEcs& ecs, BASE_NS::string_view name,
76 CORE_NS::Entity material, float radius, float length, uint32_t sectors) = 0;
77
78 /** Generate torus mesh.
79 * @param ecs ECS instance where entity will live.
80 * @param name Name of the mesh resource.
81 * @param material Material for mesh resource, if not set will use default glTF material.
82 * @param majorRadius Radius of the torus.
83 * @param minorRadius Radius of the torus tube.
84 * @param majorSectors Number of sectors in the ring.
85 * @param minorSectors Number of sectors in the tube of the torus.
86 */
87 virtual CORE_NS::Entity GenerateTorusMesh(const CORE_NS::IEcs& ecs, BASE_NS::string_view name,
88 CORE_NS::Entity material, float majorRadius, float minorRadius, uint32_t majorSectors,
89 uint32_t minorSectors) = 0;
90
91 /** Generate renderable entity
92 * @param ecs ECS instance where entity will live.
93 * @param name Name of the mesh resource and entity.
94 * @param meshEntity CORE_NS::Entity owning a MeshComponent.
95 */
96 virtual CORE_NS::Entity GenerateEntity(
97 const CORE_NS::IEcs& ecs, BASE_NS::string_view name, CORE_NS::Entity meshEntity) = 0;
98
99 /** Generate cube entity.
100 * @param ecs ECS instance where entity will live.
101 * @param name Name of the mesh resource and entity.
102 * @param material Material for mesh resource, if not set will use default glTF material.
103 * @param width Width of the cube (in x dimension).
104 * @param height Height of the cube (in y dimension).
105 * @param depth Depth of the cube (in z dimension).
106 */
107 virtual CORE_NS::Entity GenerateCube(const CORE_NS::IEcs& ecs, BASE_NS::string_view name, CORE_NS::Entity material,
108 float width, float height, float depth) = 0;
109
110 /** Generate plane entity.
111 * @param ecs ECS instance where entity will live.
112 * @param name Name of the mesh resource and entity.
113 * @param material Material for mesh resource, if not set will use default glTF material.
114 * @param width Width of the plane (in x dimension).
115 * @param depth Depth of the plane (in z dimension).
116 */
117 virtual CORE_NS::Entity GeneratePlane(
118 const CORE_NS::IEcs& ecs, BASE_NS::string_view name, CORE_NS::Entity material, float width, float depth) = 0;
119
120 /** Generate sphere entity.
121 * @param ecs ECS instance where entity will live.
122 * @param name Name of the mesh resource and entity.
123 * @param material Material for mesh resource, if not set will use default glTF material.
124 * @param radius Radius of the sphere.
125 * @param rings Number of rings in sphere.
126 * @param sectors Number of sectors per ring.
127 */
128 virtual CORE_NS::Entity GenerateSphere(const CORE_NS::IEcs& ecs, BASE_NS::string_view name,
129 CORE_NS::Entity material, float radius, uint32_t rings, uint32_t sectors) = 0;
130
131 /** Generate cone entity.
132 * @param ecs ECS instance where entity will live.
133 * @param name Name of the mesh resource and entity.
134 * @param material Material for mesh resource, if not set will use default glTF material.
135 * @param radius Radius of the cone ring.
136 * @param length Length of cone.
137 * @param sectors Number of sectors in ring.
138 */
139 virtual CORE_NS::Entity GenerateCone(const CORE_NS::IEcs& ecs, BASE_NS::string_view name, CORE_NS::Entity material,
140 float radius, float length, uint32_t sectors) = 0;
141
142 /** Generate torus entity.
143 * @param ecs ECS instance where entity will live.
144 * @param name Name of the mesh resource and entity.
145 * @param material Material for mesh resource, if not set will use default glTF material.
146 * @param majorRadius Radius of the torus.
147 * @param minorRadius Radius of the torus tube.
148 * @param majorSectors Number of sectors in the ring.
149 * @param minorSectors Number of sectors in the tube of the torus.
150 */
151 virtual CORE_NS::Entity GenerateTorus(const CORE_NS::IEcs& ecs, BASE_NS::string_view name, CORE_NS::Entity material,
152 float majorRadius, float minorRadius, uint32_t majorSectors, uint32_t minorSectors) = 0;
153
154 protected:
155 IMeshUtil() = default;
156 virtual ~IMeshUtil() = default;
157 };
158 /** @} */
159 CORE3D_END_NAMESPACE()
160
161 #endif // API_3D_UTIL_IMESH_UTIL_H
162