GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
mesh_utils.h
Go to the documentation of this file.
1// Copyright 2019 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_UTILS_H_
16#define DRACO_MESH_MESH_UTILS_H_
17
19
20#ifdef DRACO_TRANSCODER_SUPPORTED
21#include "Eigen/Geometry"
23#include "draco/mesh/mesh.h"
24
25namespace draco {
26
27// Helper class containing various utilities operating on draco::Mesh.
28// TODO(ostava): Move scattered functions in this folder here (e.g. corner table
29// construction).
30class MeshUtils {
31 public:
32 // Transforms |mesh| using the |transform| matrix. The mesh is transformed
33 // in-place.
34 static void TransformMesh(const Eigen::Matrix4d &transform, Mesh *mesh);
35
36 // Merges metadata from |src_mesh| to |dst_mesh|. Any metadata with the same
37 // names are left unchanged.
38 static void MergeMetadata(const Mesh &src_mesh, Mesh *dst_mesh);
39
40 // Removes unused MeshFeatures from |mesh|. If the |mesh| contains any mesh
41 // feature textures, the textures must be owned by the |mesh| otherwise an
42 // error is returned.
43 static Status RemoveUnusedMeshFeatures(Mesh *mesh);
44
45 // Flips the UV values of |att|.
46 static bool FlipTextureUvValues(bool flip_u, bool flip_v,
47 PointAttribute *att);
48
49 // Counts the number of degenerate faces in |mesh| for attribute |att_id|.
50 // Returns < 0 if counting of degenerate faces is not supported for |att_id|.
51 static int CountDegenerateFaces(const Mesh &mesh, int att_id);
52
53 // Searches for the lowest texture quantization bits for |tex_att| that does
54 // not introduce any new texture coordinate degenerate faces. The range for
55 // the search is |tex_target_quantization_bits| - 29, inclusive. The function
56 // does not count texture coordinate degenerate faces already in the source.
57 // Nor does it count any new texture coordinate degenerate faces that are a
58 // subset of new position degenerate faces created from the quantization of
59 // |pos_att| using |pos_quantization_bits|. Returns the lowest quantization
60 // bits within the specified range or zero signifying that it could not find a
61 // quantization that did not cause any new degenerate faces.
62 static StatusOr<int> FindLowestTextureQuantization(
63 const Mesh &mesh, const PointAttribute &pos_att,
64 int pos_quantization_bits, const PointAttribute &tex_att,
65 int tex_target_quantization_bits);
66
67 // Helper function that checks whether a mesh has auto-generated tangents.
68 // See go/tangents_and_draco_simplifier.
69 static bool HasAutoGeneratedTangents(const Mesh &mesh);
70
71 private:
72 static void TransformNormalizedAttribute(const Eigen::Matrix3d &transform,
73 PointAttribute *att);
74
75 template <typename att_components_t>
76 static int CountDegenerateFaces(const Mesh &mesh, const PointAttribute &att);
77
78 // Returns a sorted list of degenerate faces for |att|. |att| must use |mesh|
79 // for its connectivity. |range| and |max_quantized_value| are the values
80 // passed into the quantizer. |quantized_degenerate_only|, is true will only
81 // include degenerate faces caused by the quantization. Otherwise all
82 // degenerate faces will be included, those made by the quantization and those
83 // already in the source.
84 static std::vector<FaceIndex> ListDegenerateQuantizedFaces(
85 const Mesh &mesh, const PointAttribute &att, float range,
86 uint32_t max_quantized_value, bool quantized_degenerate_only);
87
88 // Returns a sorted list of degenerate faces for |att|. |att_components_t| is
89 // the component count for |att| as a VectorD. E.g. Vector2f, Vector3f, or
90 // Vector4f. |quantized_components_t| is the quantized component count for
91 // |att| as a VectorD. E.g. VectorD<int32_t, 2>, VectorD<int32_t, 3>, or
92 // VectorD<int32_t, 4>.
93 template <typename att_components_t, typename quantized_components_t>
94 static std::vector<FaceIndex> ListDegenerateQuantizedFaces(
95 const Mesh &mesh, const PointAttribute &att, float range,
96 uint32_t max_quantized_value, bool quantized_degenerate_only);
97};
98
99} // namespace draco
100
101#endif // DRACO_TRANSCODER_SUPPORTED
102#endif // DRACO_MESH_MESH_UTILS_H_
Definition attribute_octahedron_transform.cc:21