Path: blob/master/thirdparty/manifold/src/mesh_fixes.h
9905 views
// Copyright 2024 The Manifold Authors.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.13#pragma once14#include "shared.h"1516namespace {17using namespace manifold;1819inline int FlipHalfedge(int halfedge) {20const int tri = halfedge / 3;21const int vert = 2 - (halfedge - 3 * tri);22return 3 * tri + vert;23}2425struct TransformNormals {26mat3 transform;2728vec3 operator()(vec3 normal) const {29normal = la::normalize(transform * normal);30if (std::isnan(normal.x)) normal = vec3(0.0);31return normal;32}33};3435struct TransformTangents {36VecView<vec4> tangent;37const int edgeOffset;38const mat3 transform;39const bool invert;40VecView<const vec4> oldTangents;41VecView<const Halfedge> halfedge;4243void operator()(const int edgeOut) {44const int edgeIn =45invert ? halfedge[FlipHalfedge(edgeOut)].pairedHalfedge : edgeOut;46tangent[edgeOut + edgeOffset] =47vec4(transform * vec3(oldTangents[edgeIn]), oldTangents[edgeIn].w);48}49};5051struct FlipTris {52VecView<Halfedge> halfedge;5354void operator()(const int tri) {55std::swap(halfedge[3 * tri], halfedge[3 * tri + 2]);5657for (const int i : {0, 1, 2}) {58std::swap(halfedge[3 * tri + i].startVert, halfedge[3 * tri + i].endVert);59halfedge[3 * tri + i].pairedHalfedge =60FlipHalfedge(halfedge[3 * tri + i].pairedHalfedge);61}62}63};64} // namespace656667