Blender V5.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
8
9#include "BLI_bounds.hh"
10
11#include "BKE_mesh.hh"
12
14
15namespace blender::geometry {
16
17Mesh *create_line_mesh(const float3 start, const float3 delta, const int count)
18{
19 if (count < 1) {
20 return nullptr;
21 }
22
23 const int edges_num = count - 1;
24 Mesh *mesh = BKE_mesh_new_nomain(count, edges_num, 0, 0);
25 MutableSpan<float3> positions = mesh->vert_positions_for_write();
26 MutableSpan<int2> edges = mesh->edges_for_write();
27
29 threading::parallel_invoke(
30 1024 < count,
31 [&]() {
32 threading::parallel_for(positions.index_range(), 4096, [&](IndexRange range) {
33 for (const int i : range) {
34 positions[i] = start + delta * i;
35 }
36 });
37 },
38 [&]() {
39 threading::parallel_for(edges.index_range(), 4096, [&](IndexRange range) {
40 for (const int i : range) {
41 edges[i][0] = i;
42 edges[i][1] = i + 1;
43 }
44 });
45 });
46 });
47
48 mesh->tag_loose_verts_none();
49 mesh->tag_overlapping_none();
50 mesh->bounds_set_eager(*bounds::min_max<float3>({start, start + delta * edges_num}));
51
52 return mesh;
53}
54
55} // namespace blender::geometry
constexpr int64_t size_in_bytes() const
Definition BLI_span.hh:507
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:251
Mesh * BKE_mesh_new_nomain(int verts_num, int edges_num, int faces_num, int corners_num)
VecBase< float, 3 > float3