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_MESH_ARRAYS_H 16 #define SCENEPLUGIN_MESH_ARRAYS_H 17 18 SCENE_BEGIN_NAMESPACE() 19 template<typename IndexType> 20 struct MeshGeometry { 21 using Ptr = BASE_NS::shared_ptr<MeshGeometry<IndexType>>; 22 using WeakPtr = BASE_NS::weak_ptr<MeshGeometry<IndexType>>; 23 BASE_NS::vector<BASE_NS::Math::Vec3> vertices; 24 BASE_NS::vector<BASE_NS::Math::Vec3> normals; // optional, will be generated if empty 25 BASE_NS::vector<BASE_NS::Math::Vec2> uvs; // optional, will be generated if empty 26 BASE_NS::vector<BASE_NS::Math::Vec2> uv2s; // optional 27 BASE_NS::vector<BASE_NS::Math::Vec4> tangents; // optional, will be created if createTangents is set true 28 BASE_NS::vector<BASE_NS::Math::Vec4> colors; // optional 29 BASE_NS::vector<IndexType> indices; 30 bool generateTangents { false }; 31 CreateMeshGeometry32 static Ptr Create() 33 { 34 return Ptr { new MeshGeometry<IndexType>() }; 35 } 36 }; 37 38 template<typename IndexType> 39 using MeshGeometryPtr = BASE_NS::shared_ptr<MeshGeometry<IndexType>>; 40 41 template<typename IndexType> 42 using MeshGeometryArray = BASE_NS::vector<MeshGeometryPtr<IndexType>>; 43 44 template<typename IndexType> 45 using MeshGeometryArrayPtr = BASE_NS::shared_ptr<MeshGeometryArray<IndexType>>; 46 47 template<typename IndexType> 48 using MeshGeometryArrayWeakPtr = BASE_NS::shared_ptr<MeshGeometryArray<IndexType>>; 49 50 template<typename IndexType> CreateMeshContainer(size_t reserve)51MeshGeometryArrayPtr<IndexType> CreateMeshContainer(size_t reserve) 52 { 53 auto ret = MeshGeometryArrayPtr<IndexType> { new MeshGeometryArray<IndexType>() }; 54 ret->reserve(reserve); 55 return ret; 56 } 57 58 SCENE_END_NAMESPACE() 59 60 #endif // SCENEPLUGIN_MESH_ARRAYS_H 61