Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
MeshEdges.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
7#pragma once
8
9#include "../core/Types.hpp"
10
11#include <algorithm>
12#include <vector>
13
14namespace esengine {
15
22inline std::vector<u32> distinctMeshEdges(ConstSpan<u32> indices) {
23 std::vector<u64> keys;
24 keys.reserve(indices.size());
25 for (usize t = 0; t + 2 < indices.size(); t += 3) {
26 for (u32 k = 0; k < 3; ++k) {
27 const u32 a = indices[t + k], b = indices[t + (k + 1) % 3];
28 keys.push_back((static_cast<u64>(std::min(a, b)) << 32) | std::max(a, b));
29 }
30 }
31 std::sort(keys.begin(), keys.end());
32 keys.erase(std::unique(keys.begin(), keys.end()), keys.end());
33 std::vector<u32> lines;
34 lines.reserve(keys.size() * 2);
35 for (const u64 key : keys) {
36 lines.push_back(static_cast<u32>(key >> 32));
37 lines.push_back(static_cast<u32>(key & 0xFFFFFFFFu));
38 }
39 return lines;
40}
41
42} // namespace esengine
Core type definitions and utilities for ESEngine.
std::uint64_t u64
Unsigned 64-bit integer.
Definition Types.hpp:47
std::size_t usize
Size type for indexing and sizes.
Definition Types.hpp:64
std::span< const T > ConstSpan
Definition Types.hpp:242
std::uint32_t u32
Unsigned 32-bit integer.
Definition Types.hpp:45
std::vector< u32 > distinctMeshEdges(ConstSpan< u32 > indices)
Index pairs, one per distinct edge, in ascending order of (low, high) vertex.
Definition MeshEdges.hpp:22