GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
mesh_splitter.h
Go to the documentation of this file.
1// Copyright 2017 The Draco Authors.
2//
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 DRACO_MESH_MESH_SPLITTER_H_
16#define DRACO_MESH_MESH_SPLITTER_H_
17
18#include <memory>
19#include <vector>
20
22
23#ifdef DRACO_TRANSCODER_SUPPORTED
25#include "draco/mesh/mesh.h"
28
29namespace draco {
30
31// Class that can be used to split a single mesh into multiple sub-meshes
32// according to specified criteria.
33class MeshSplitter {
34 public:
35 typedef std::vector<std::unique_ptr<Mesh>> MeshVector;
36 MeshSplitter();
37
38 // Sets a flag that tells the splitter to preserve all materials on the input
39 // mesh during mesh splitting. When set, the materials used on sub-meshes are
40 // going to be copied over. Any redundant materials on sub-meshes are going to
41 // be deleted but material indices may still be preserved depending on the
42 // SetRemoveUnusedMaterialIndices() flag.
43 // Default = false.
44 void SetPreserveMaterials(bool flag) { preserve_materials_ = flag; }
45
46 // Sets a flag that tells the splitter to delete any unused material indices
47 // on the generated sub-meshes. This option is currently used only when
48 // SetPreserveMaterials() was set to true. If this option is set to false, the
49 // material indices of the MATERIAL attribute will be the same as in the
50 // source mesh. If the flag is true, then the unused material indices will be
51 // removed and they may no longer correspond to the source mesh. Note that
52 // when this flag is false, any unused materials would be replaced with empty
53 // (default) materials.
54 // Default = true.
55 void SetRemoveUnusedMaterialIndices(bool flag) {
56 remove_unused_material_indices_ = flag;
57 }
58
59 // Sets a flag that tells the splitter to preserve all mesh features on the
60 // input mesh during mesh splitting. When set, the mesh features used on
61 // sub-meshes are going to be copied over. Any redundant mesh features on
62 // sub-meshes are going to be deleted.
63 // Default = false.
64 void SetPreserveMeshFeatures(bool flag) { preserve_mesh_features_ = flag; }
65
66 // Splits the input |mesh| according to attribute values stored in the
67 // specified attribute. If the |mesh| contains faces, the attribute values
68 // need to be defined per-face, that is, all points attached to a single face
69 // must share the same attribute value. Meshes without faces are treated as
70 // point clouds and the attribute values can be defined per-point. Each
71 // attribute value (AttributeValueIndex) is mapped to a single output mesh. If
72 // an AttributeValueIndex is unused, no mesh is created for the given value.
73 StatusOr<MeshVector> SplitMesh(const Mesh &mesh, uint32_t split_attribute_id);
74
75 // Splits the input |mesh| into separate components defined in
76 // |connected_components|. That is, all faces associated with a given
77 // component index will be stored in the same mesh. The number of generated
78 // meshes will correspond to |connected_components.NumConnectedComponents()|.
79 StatusOr<MeshVector> SplitMeshToComponents(
80 const Mesh &mesh, const MeshConnectedComponents &connected_components);
81
82 private:
83 struct WorkData {
84 // Map between attribute ids of the input and output meshes.
85 std::vector<int> att_id_map;
86 std::vector<int> num_sub_mesh_elements;
87 bool split_by_materials = false;
88 };
89
90 template <typename BuilderT>
91 StatusOr<MeshVector> SplitMeshInternal(const Mesh &mesh,
92 int split_attribute_id);
93
94 StatusOr<MeshVector> FinalizeMeshes(const Mesh &mesh,
95 const WorkData &work_data,
96 MeshVector out_meshes) const;
97
98 bool preserve_materials_;
99 bool remove_unused_material_indices_;
100 bool preserve_mesh_features_;
101
102 template <typename BuilderT>
103 friend class MeshSplitterInternal;
104};
105
106} // namespace draco
107
108#endif // DRACO_TRANSCODER_SUPPORTED
109#endif // DRACO_MESH_MESH_SPLITTER_H_
Definition attribute_octahedron_transform.cc:21