Blender V5.3
stl_import_mesh.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include <cstdint>
12
14#include "BLI_vector.hh"
15#include "BLI_vector_set.hh"
16#include "stl_data.hh"
17
18namespace blender {
19
20struct Mesh;
21
22namespace io::stl {
23class Triangle {
24 public:
25 int v1, v2, v3;
26 /* Based on an old version of Python's frozen-set hash
27 * https://web.archive.org/web/20220520211017/https://stackoverflow.com/questions/20832279/python-frozenset-hashing-algorithm-implementation
28 */
29 uint64_t hash() const
30 {
31 uint64_t res = 1927868237UL;
32 res *= 4;
33 res ^= (v1 ^ (v1 << 16) ^ 89869747UL) * 3644798167UL;
34 res ^= (v2 ^ (v2 << 16) ^ 89869747UL) * 3644798167UL;
35 res ^= (v3 ^ (v3 << 16) ^ 89869747UL) * 3644798167UL;
36 return res * 69069U + 907133923UL;
37 }
38 friend bool operator==(const Triangle &a, const Triangle &b)
39 {
40 bool i = (a.v1 == b.v1) && (a.v2 == b.v2) && (a.v3 == b.v3);
41 bool j = (a.v1 == b.v1) && (a.v3 == b.v2) && (a.v2 == b.v3);
42 bool k = (a.v2 == b.v1) && (a.v1 == b.v2) && (a.v3 == b.v3);
43
44 bool l = (a.v2 == b.v1) && (a.v3 == b.v2) && (a.v1 == b.v3);
45 bool m = (a.v3 == b.v1) && (a.v1 == b.v2) && (a.v2 == b.v3);
46 bool n = (a.v3 == b.v1) && (a.v2 == b.v2) && (a.v1 == b.v3);
47
48 return i || j || k || l || m || n;
49 }
50};
51
53 private:
54 VectorSet<float3> verts_;
56 Vector<float3> loop_normals_;
57 int degenerate_tris_num_;
58 int duplicate_tris_num_;
59 const bool use_custom_normals_;
60
61 public:
62 STLMeshHelper(int tris_num, bool use_custom_normals);
63
64 /* Creates a new triangle from specified vertex locations,
65 * duplicate vertices and triangles are merged.
66 */
67 bool add_triangle(const PackedTriangle &data);
68
69 Mesh *to_mesh();
70};
71
72} // namespace io::stl
73} // namespace blender
bool add_triangle(const PackedTriangle &data)
STLMeshHelper(int tris_num, bool use_custom_normals)
friend bool operator==(const Triangle &a, const Triangle &b)
BMesh Iterators.
unsigned __int64 uint64_t
Definition BKE_text.h:91
ATTR_WARN_UNUSED_RESULT const BMLoop * l
BMesh const char void * data