Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/manifold/src/mesh_fixes.h
9905 views
1
// Copyright 2024 The Manifold 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
#pragma once
15
#include "shared.h"
16
17
namespace {
18
using namespace manifold;
19
20
inline int FlipHalfedge(int halfedge) {
21
const int tri = halfedge / 3;
22
const int vert = 2 - (halfedge - 3 * tri);
23
return 3 * tri + vert;
24
}
25
26
struct TransformNormals {
27
mat3 transform;
28
29
vec3 operator()(vec3 normal) const {
30
normal = la::normalize(transform * normal);
31
if (std::isnan(normal.x)) normal = vec3(0.0);
32
return normal;
33
}
34
};
35
36
struct TransformTangents {
37
VecView<vec4> tangent;
38
const int edgeOffset;
39
const mat3 transform;
40
const bool invert;
41
VecView<const vec4> oldTangents;
42
VecView<const Halfedge> halfedge;
43
44
void operator()(const int edgeOut) {
45
const int edgeIn =
46
invert ? halfedge[FlipHalfedge(edgeOut)].pairedHalfedge : edgeOut;
47
tangent[edgeOut + edgeOffset] =
48
vec4(transform * vec3(oldTangents[edgeIn]), oldTangents[edgeIn].w);
49
}
50
};
51
52
struct FlipTris {
53
VecView<Halfedge> halfedge;
54
55
void operator()(const int tri) {
56
std::swap(halfedge[3 * tri], halfedge[3 * tri + 2]);
57
58
for (const int i : {0, 1, 2}) {
59
std::swap(halfedge[3 * tri + i].startVert, halfedge[3 * tri + i].endVert);
60
halfedge[3 * tri + i].pairedHalfedge =
61
FlipHalfedge(halfedge[3 * tri + i].pairedHalfedge);
62
}
63
}
64
};
65
} // namespace
66
67