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 #include <3d/ecs/components/mesh_component.h>
17 #include <core/ecs/intf_ecs.h>
18 #include <core/plugin/intf_class_factory.h>
19
20 #include "ComponentTools/base_manager.h"
21 #include "ComponentTools/base_manager.inl"
22
23 #define IMPLEMENT_MANAGER
24 #include <core/property_tools/property_macros.h>
25
26 CORE_BEGIN_NAMESPACE()
27 using BASE_NS::vector;
28 using CORE3D_NS::MeshComponent;
29
30 DECLARE_PROPERTY_TYPE(MeshComponent::Submesh);
31 DECLARE_PROPERTY_TYPE(MeshComponent::Submesh::BufferAccess);
32 DECLARE_PROPERTY_TYPE(MeshComponent::Submesh::IndexBufferAccess);
33 DECLARE_PROPERTY_TYPE(vector<MeshComponent::Submesh>);
34 DECLARE_PROPERTY_TYPE(RENDER_NS::GraphicsState::InputAssembly);
35 DECLARE_PROPERTY_TYPE(RENDER_NS::PrimitiveTopology);
36
37 ENUM_TYPE_METADATA(RENDER_NS::PrimitiveTopology, ENUM_VALUE(CORE_PRIMITIVE_TOPOLOGY_POINT_LIST, "Point List"),
38 ENUM_VALUE(CORE_PRIMITIVE_TOPOLOGY_LINE_LIST, "Line List"),
39 ENUM_VALUE(CORE_PRIMITIVE_TOPOLOGY_LINE_STRIP, "Line Strip"),
40 ENUM_VALUE(CORE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, "Triangle Strip"),
41 ENUM_VALUE(CORE_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN, "Triangle Fan"),
42 ENUM_VALUE(CORE_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY, "Line List With Adjacency"),
43 ENUM_VALUE(CORE_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY, "Line Strip With Adjacency"),
44 ENUM_VALUE(CORE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY, "Triangle List With Adjacency"),
45 ENUM_VALUE(CORE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY, "Triangle Strip With Adjacency"),
46 ENUM_VALUE(CORE_PRIMITIVE_TOPOLOGY_PATCH_LIST, "Patch List"),
47 ENUM_VALUE(CORE_PRIMITIVE_TOPOLOGY_MAX_ENUM, "Undefined"))
48
49 DECLARE_PROPERTY_TYPE(RENDER_NS::IndexType);
50
51 ENUM_TYPE_METADATA(
52 RENDER_NS::IndexType, ENUM_VALUE(CORE_INDEX_TYPE_UINT16, "16 Bit"), ENUM_VALUE(CORE_INDEX_TYPE_UINT32, "32 Bit"))
53
54 ENUM_TYPE_METADATA(MeshComponent::Submesh::FlagBits, ENUM_VALUE(TANGENTS_BIT, "Tangents"),
55 ENUM_VALUE(VERTEX_COLORS_BIT, "Vertex Colors"), ENUM_VALUE(SKIN_BIT, "Skin"),
56 ENUM_VALUE(SECOND_TEXCOORD_BIT, "Second Texcoord"))
57
58 DATA_TYPE_METADATA(MeshComponent::Submesh::BufferAccess, MEMBER_PROPERTY(buffer, "Handle", 0),
59 MEMBER_PROPERTY(offset, "Offset", 0), MEMBER_PROPERTY(byteSize, "Size In Bytes", 0))
60
61 DATA_TYPE_METADATA(MeshComponent::Submesh::IndexBufferAccess, MEMBER_PROPERTY(buffer, "Handle", 0),
62 MEMBER_PROPERTY(offset, "Offset", 0), MEMBER_PROPERTY(byteSize, "Size In Bytes", 0),
63 MEMBER_PROPERTY(indexType, "Index Type", 0))
64
65 DATA_TYPE_METADATA(RENDER_NS::GraphicsState::InputAssembly,
66 MEMBER_PROPERTY(enablePrimitiveRestart, "Enable Primitive Restart", 0),
67 MEMBER_PROPERTY(primitiveTopology, "Primitive Topology", 0))
68
69 /* Expose more properties? */
70 DATA_TYPE_METADATA(MeshComponent::Submesh, MEMBER_PROPERTY(instanceCount, "Instance Count", 0),
71 MEMBER_PROPERTY(bufferAccess, "", 0), MEMBER_PROPERTY(indexBuffer, "Index Buffer", 0),
72 MEMBER_PROPERTY(indirectArgsBuffer, "Indirect Buffer", 0),
73 MEMBER_PROPERTY(morphTargetBuffer, "Morph Target Buffer", 0), MEMBER_PROPERTY(vertexCount, "Vertex Count", 0),
74 MEMBER_PROPERTY(indexCount, "Index Count", 0), MEMBER_PROPERTY(morphTargetCount, "Morph Target Count", 0),
75 MEMBER_PROPERTY(aabbMin, "Min AABB", 0), MEMBER_PROPERTY(aabbMax, "Max AABB", 0),
76 MEMBER_PROPERTY(material, "Material", 0), MEMBER_PROPERTY(additionalMaterials, "Additional Materials", 0),
77 BITFIELD_MEMBER_PROPERTY(flags, "Options", PropertyFlags::IS_BITFIELD, MeshComponent::Submesh::FlagBits),
78 MEMBER_PROPERTY(renderSortLayer, "Render Sort Layer", 0),
79 MEMBER_PROPERTY(renderSortLayerOrder, "Render Sort Layer Order", 0),
80 MEMBER_PROPERTY(inputAssembly, "Input Assembly (Optional)", 0))
81
82 CORE_END_NAMESPACE()
83
84 CORE3D_BEGIN_NAMESPACE()
85 using BASE_NS::array_view;
86 using BASE_NS::countof;
87
88 using CORE_NS::BaseManager;
89 using CORE_NS::IComponentManager;
90 using CORE_NS::IEcs;
91 using CORE_NS::Property;
92
93 class MeshComponentManager final : public BaseManager<MeshComponent, IMeshComponentManager> {
94 BEGIN_PROPERTY(MeshComponent, componentMetaData_)
95 #include <3d/ecs/components/mesh_component.h>
96 END_PROPERTY();
97
98 public:
MeshComponentManager(IEcs & ecs)99 explicit MeshComponentManager(IEcs& ecs)
100 : BaseManager<MeshComponent, IMeshComponentManager>(ecs, CORE_NS::GetName<MeshComponent>())
101 {}
102
103 ~MeshComponentManager() = default;
104
PropertyCount() const105 size_t PropertyCount() const override
106 {
107 return BASE_NS::countof(componentMetaData_);
108 }
109
MetaData(size_t index) const110 const Property* MetaData(size_t index) const override
111 {
112 if (index < BASE_NS::countof(componentMetaData_)) {
113 return &componentMetaData_[index];
114 }
115 return nullptr;
116 }
117
MetaData() const118 array_view<const Property> MetaData() const override
119 {
120 return componentMetaData_;
121 }
122 };
123
IMeshComponentManagerInstance(IEcs & ecs)124 IComponentManager* IMeshComponentManagerInstance(IEcs& ecs)
125 {
126 return new MeshComponentManager(ecs);
127 }
128
IMeshComponentManagerDestroy(IComponentManager * instance)129 void IMeshComponentManagerDestroy(IComponentManager* instance)
130 {
131 delete static_cast<MeshComponentManager*>(instance);
132 }
133 CORE_END_NAMESPACE()
134