Blender V4.3
mesh_primitive_line.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BLI_bounds.hh"
6
7#include "BKE_mesh.hh"
8
10
11namespace blender::geometry {
12
13Mesh *create_line_mesh(const float3 start, const float3 delta, const int count)
14{
15 if (count < 1) {
16 return nullptr;
17 }
18
19 Mesh *mesh = BKE_mesh_new_nomain(count, count - 1, 0, 0);
20 MutableSpan<float3> positions = mesh->vert_positions_for_write();
21 MutableSpan<int2> edges = mesh->edges_for_write();
22
23 threading::memory_bandwidth_bound_task(positions.size_in_bytes() + edges.size_in_bytes(), [&]() {
24 threading::parallel_invoke(
25 1024 < count,
26 [&]() {
27 threading::parallel_for(positions.index_range(), 4096, [&](IndexRange range) {
28 for (const int i : range) {
29 positions[i] = start + delta * i;
30 }
31 });
32 },
33 [&]() {
34 threading::parallel_for(edges.index_range(), 4096, [&](IndexRange range) {
35 for (const int i : range) {
36 edges[i][0] = i;
37 edges[i][1] = i + 1;
38 }
39 });
40 });
41 });
42
43 mesh->tag_loose_verts_none();
44 mesh->tag_overlapping_none();
45 mesh->bounds_set_eager(*bounds::min_max<float3>({start, start + delta * count}));
46
47 return mesh;
48}
49
50} // namespace blender::geometry
Mesh * BKE_mesh_new_nomain(int verts_num, int edges_num, int faces_num, int corners_num)
int count
Mesh * create_line_mesh(float3 start, float3 delta, int count)
void memory_bandwidth_bound_task(const int64_t approximate_bytes_touched, const Function &function)
Definition BLI_task.hh:243