Blender V4.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
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
18struct Mesh;
19
20namespace blender::io::stl {
21class Triangle {
22 public:
23 int v1, v2, v3;
24 /* Based on an old version of Python's frozen-set hash
25 * https://web.archive.org/web/20220520211017/https://stackoverflow.com/questions/20832279/python-frozenset-hashing-algorithm-implementation
26 */
27 uint64_t hash() const
28 {
29 uint64_t res = 1927868237UL;
30 res *= 4;
31 res ^= (v1 ^ (v1 << 16) ^ 89869747UL) * 3644798167UL;
32 res ^= (v2 ^ (v2 << 16) ^ 89869747UL) * 3644798167UL;
33 res ^= (v3 ^ (v3 << 16) ^ 89869747UL) * 3644798167UL;
34 return res * 69069U + 907133923UL;
35 }
36 friend bool operator==(const Triangle &a, const Triangle &b)
37 {
38 bool i = (a.v1 == b.v1) && (a.v2 == b.v2) && (a.v3 == b.v3);
39 bool j = (a.v1 == b.v1) && (a.v3 == b.v2) && (a.v2 == b.v3);
40 bool k = (a.v2 == b.v1) && (a.v1 == b.v2) && (a.v3 == b.v3);
41
42 bool l = (a.v2 == b.v1) && (a.v3 == b.v2) && (a.v1 == b.v3);
43 bool m = (a.v3 == b.v1) && (a.v1 == b.v2) && (a.v2 == b.v3);
44 bool n = (a.v3 == b.v1) && (a.v2 == b.v2) && (a.v1 == b.v3);
45
46 return i || j || k || l || m || n;
47 }
48};
49
51 private:
52 VectorSet<float3> verts_;
54 Vector<float3> loop_normals_;
55 int degenerate_tris_num_;
56 int duplicate_tris_num_;
57 const bool use_custom_normals_;
58
59 public:
60 STLMeshHelper(int tris_num, bool use_custom_normals);
61
62 /* Creates a new triangle from specified vertex locations,
63 * duplicate vertices and triangles are merged.
64 */
65 bool add_triangle(const PackedTriangle &data);
66
67 Mesh *to_mesh();
68};
69
70} // namespace blender::io::stl
ATTR_WARN_UNUSED_RESULT const BMLoop * l
bool add_triangle(const PackedTriangle &data)
STLMeshHelper(int tris_num, bool use_custom_normals)
friend bool operator==(const Triangle &a, const Triangle &b)
local_group_size(16, 16) .push_constant(Type b
unsigned __int64 uint64_t
Definition stdint.h:90