Blender V5.0
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 const int edges_num = count - 1;
20 Mesh *mesh = BKE_mesh_new_nomain(count, edges_num, 0, 0);
21 MutableSpan<float3> positions = mesh->vert_positions_for_write();
22 MutableSpan<int2> edges = mesh->edges_for_write();
23
25 threading::parallel_invoke(
26 1024 < count,
27 [&]() {
28 threading::parallel_for(positions.index_range(), 4096, [&](IndexRange range) {
29 for (const int i : range) {
30 positions[i] = start + delta * i;
31 }
32 });
33 },
34 [&]() {
35 threading::parallel_for(edges.index_range(), 4096, [&](IndexRange range) {
36 for (const int i : range) {
37 edges[i][0] = i;
38 edges[i][1] = i + 1;
39 }
40 });
41 });
42 });
43
44 mesh->tag_loose_verts_none();
45 mesh->tag_overlapping_none();
46 mesh->bounds_set_eager(*bounds::min_max<float3>({start, start + delta * edges_num}));
47
48 return mesh;
49}
50
51} // namespace blender::geometry
Mesh * BKE_mesh_new_nomain(int verts_num, int edges_num, int faces_num, int corners_num)
constexpr int64_t size_in_bytes() const
Definition BLI_span.hh:501
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:265
VecBase< float, 3 > float3