GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
mesh_misc_functions.h
Go to the documentation of this file.
1// Copyright 2016 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// This file contains misc functions that are needed by several mesh related
16// algorithms.
17
18#ifndef DRACO_MESH_MESH_MISC_FUNCTIONS_H_
19#define DRACO_MESH_MESH_MISC_FUNCTIONS_H_
20
22#include "draco/mesh/mesh.h"
23
24// The file contains functions that use both Mesh and CornerTable as inputs.
25namespace draco {
26
27// Creates a CornerTable from the position attribute of |mesh|. Returns nullptr
28// on error.
29std::unique_ptr<CornerTable> CreateCornerTableFromPositionAttribute(
30 const Mesh *mesh);
31
32// Creates a CornerTable from the first named attribute of |mesh| with a given
33// type. Returns nullptr on error.
34std::unique_ptr<CornerTable> CreateCornerTableFromAttribute(
35 const Mesh *mesh, GeometryAttribute::Type type);
36
37// Creates a CornerTable from all attributes of |mesh|. Boundaries are
38// automatically introduced on all attribute seams. Returns nullptr on error.
39std::unique_ptr<CornerTable> CreateCornerTableFromAllAttributes(
40 const Mesh *mesh);
41
42// Returns true when the given corner lies opposite to an attribute seam.
44 const PointAttribute &att,
45 const Mesh &mesh,
46 const CornerTable &ct) {
47 const CornerIndex opp_ci = ct.Opposite(ci);
48 if (opp_ci == kInvalidCornerIndex) {
49 return false; // No opposite corner == no attribute seam.
50 }
51 // Compare attribute value indices on both ends of the opposite edge.
52 CornerIndex c0 = ct.Next(ci);
53 CornerIndex c1 = ct.Previous(opp_ci);
54 if (att.mapped_index(mesh.CornerToPointId(c0)) !=
55 att.mapped_index(mesh.CornerToPointId(c1))) {
56 return true;
57 }
58 c0 = ct.Previous(ci);
59 c1 = ct.Next(opp_ci);
60 if (att.mapped_index(mesh.CornerToPointId(c0)) !=
61 att.mapped_index(mesh.CornerToPointId(c1))) {
62 return true;
63 }
64 return false;
65}
66
67// Interpolates an attribute value on a face using given barycentric
68// coordinates. InterpolatedVectorT should be a VectorD that corresponds to the
69// values stored in the attribute.
70template <typename InterpolatedVectorT>
72 const Mesh &mesh, const PointAttribute &attribute, FaceIndex fi,
73 const std::array<float, 3> &barycentric_coord) {
74 const Mesh::Face &face = mesh.face(fi);
75 // Get values for all three corners of the face.
76 InterpolatedVectorT val[3];
77 for (int c = 0; c < 3; ++c) {
78 attribute.GetMappedValue(face[c], &(val[c][0]));
79 }
80 // Return an interpolated value.
81 InterpolatedVectorT res;
82 for (int d = 0; d < InterpolatedVectorT::dimension; ++d) {
83 const float interpolated_component = barycentric_coord[0] * val[0][d] +
84 barycentric_coord[1] * val[1][d] +
85 barycentric_coord[2] * val[2][d];
86 if (std::is_integral<typename InterpolatedVectorT::Scalar>::value) {
87 res[d] = std::floor(interpolated_component + 0.5f);
88 } else {
89 res[d] = interpolated_component;
90 }
91 }
92 return res;
93}
94
95} // namespace draco
96
97#endif // DRACO_MESH_MESH_MISC_FUNCTIONS_H_
Definition corner_table.h:53
CornerIndex Opposite(CornerIndex corner) const
Definition corner_table.h:83
CornerIndex Next(CornerIndex corner) const
Definition corner_table.h:89
CornerIndex Previous(CornerIndex corner) const
Definition corner_table.h:95
Type
Definition geometry_attribute.h:46
Definition mesh.h:52
PointIndex CornerToPointId(int ci) const
Definition mesh.h:140
const Face & face(FaceIndex face_id) const
Definition mesh.h:79
std::array< PointIndex, 3 > Face
Definition mesh.h:54
Definition point_attribute.h:33
AttributeValueIndex mapped_index(PointIndex point_index) const
Definition point_attribute.h:56
void GetMappedValue(PointIndex point_index, void *out_data) const
Definition point_attribute.h:108
d
Definition meshpage.php:3895
Definition attribute_octahedron_transform.cc:21
InterpolatedVectorT ComputeInterpolatedAttributeValueOnMeshFace(const Mesh &mesh, const PointAttribute &attribute, FaceIndex fi, const std::array< float, 3 > &barycentric_coord)
Definition mesh_misc_functions.h:71
std::unique_ptr< CornerTable > CreateCornerTableFromAttribute(const Mesh *mesh, GeometryAttribute::Type type)
Definition mesh_misc_functions.cc:24
std::unique_ptr< CornerTable > CreateCornerTableFromAllAttributes(const Mesh *mesh)
Definition mesh_misc_functions.cc:46
bool IsCornerOppositeToAttributeSeam(CornerIndex ci, const PointAttribute &att, const Mesh &mesh, const CornerTable &ct)
Definition mesh_misc_functions.h:43
CornerIndex CornerIndex
Definition mesh_edgebreaker_encoder_impl.cc:35
FaceIndex FaceIndex
Definition mesh_edgebreaker_encoder_impl.cc:36
std::unique_ptr< CornerTable > CreateCornerTableFromPositionAttribute(const Mesh *mesh)
Definition mesh_misc_functions.cc:19