35 "An index used to group curves together. Filling is done separately for each group");
56 for (const int i : range) {
57 faces[i].resize(offsets[i].size());
58 array_utils::fill_index_range<int>(faces[i], offsets[i].start());
66 const OffsetIndices points_by_curve = curves.evaluated_points_by_curve();
67 const Span<float3> positions = curves.evaluated_positions();
70 threading::parallel_for(positions.index_range(), 2048, [&](
const IndexRange range) {
71 for (const int i : range) {
72 positions_2d[i] = double2(positions[i].x, positions[i].y);
77 fill_curve_vert_indices(points_by_curve, faces);
81 input.vert = std::move(positions_2d);
82 input.face = std::move(faces);
91 const OffsetIndices points_by_curve = curves.evaluated_points_by_curve();
92 const Span<float3> positions = curves.evaluated_positions();
95 const OffsetIndices points_by_curve_masked = offset_indices::gather_selected_offsets(
96 points_by_curve, mask, offsets_data);
99 mask.foreach_index(
GrainSize(1024), [&](
const int src_curve,
const int dst_curve) {
100 const IndexRange src_points = points_by_curve[src_curve];
101 const IndexRange dst_points = points_by_curve_masked[dst_curve];
103 const int src = src_points[i];
104 const int dst = dst_points[i];
105 positions_2d[dst] =
double2(positions[src].x, positions[src].y);
114 input.vert = std::move(positions_2d);
115 input.face = std::move(faces);
127 data_evaluator.
add(group_index_field);
128 data_evaluator.evaluate();
129 const VArray<int> curve_group_ids = data_evaluator.get_evaluated<
int>(0);
132 return {
do_cdt(curves, output_type)};
138 curve_group_ids, mask_memory, group_indexing);
139 const int groups_num = group_masks.
size();
144 const int domain_size = curve_group_ids.
size();
145 const int avg_group_size = domain_size / groups_num;
146 const int grain_size = std::max(8192 / avg_group_size, 1);
148 for (
const int group_index :
range) {
149 const IndexMask &mask = group_masks[group_index];
170 Array<int> vert_groups_data(results.size() + 1);
171 Array<int> edge_groups_data(results.size() + 1);
172 Array<int> face_groups_data(results.size() + 1);
173 Array<int> loop_groups_data(results.size() + 1);
174 threading::parallel_for(results.index_range(), 1024, [&](
const IndexRange results_range) {
175 for (const int i_result : results_range) {
176 const meshintersect::CDT_result<double> &result = results[i_result];
177 vert_groups_data[i_result] = result.vert.size();
178 edge_groups_data[i_result] = result.edge.size();
179 face_groups_data[i_result] = result.face.size();
181 for (const Vector<int> &face : result.face) {
182 loop_len += face.size();
184 loop_groups_data[i_result] = loop_len;
188 const OffsetIndices vert_groups = offset_indices::accumulate_counts_to_offsets(vert_groups_data);
189 const OffsetIndices edge_groups = offset_indices::accumulate_counts_to_offsets(edge_groups_data);
190 const OffsetIndices face_groups = offset_indices::accumulate_counts_to_offsets(face_groups_data);
191 const OffsetIndices loop_groups = offset_indices::accumulate_counts_to_offsets(loop_groups_data);
203 threading::parallel_for(results.index_range(), 1024, [&](
const IndexRange results_range) {
204 for (const int i_result : results_range) {
205 const meshintersect::CDT_result<double> &result = results[i_result];
206 const IndexRange verts_range = vert_groups[i_result];
207 const IndexRange edges_range = edge_groups[i_result];
208 const IndexRange faces_range = face_groups[i_result];
209 const IndexRange loops_range = loop_groups[i_result];
211 MutableSpan<float3> positions = all_positions.slice(verts_range);
212 for (const int i : result.vert.index_range()) {
213 positions[i] = float3(float(result.vert[i].x), float(result.vert[i].y), 0.0f);
216 MutableSpan<int2> edges = all_edges.slice(edges_range);
217 for (const int i : result.edge.index_range()) {
218 edges[i] = int2(result.edge[i].first + verts_range.start(),
219 result.edge[i].second + verts_range.start());
222 MutableSpan<int> face_offsets = all_face_offsets.slice(faces_range);
223 MutableSpan<int> corner_verts = all_corner_verts.slice(loops_range);
224 int i_face_corner = 0;
225 for (const int i_face : result.face.index_range()) {
226 face_offsets[i_face] = i_face_corner + loops_range.start();
227 for (const int i_corner : result.face[i_face].index_range()) {
228 corner_verts[i_face_corner] = result.face[i_face][i_corner] + verts_range.start();
237 bke::mesh_calc_edges(*mesh,
true,
false);
238 bke::mesh_smooth_set(*mesh,
false);
240 mesh->tag_overlapping_none();
255 if (curves.curves_num() > 0) {
257 curves, output_type, group_index);
267 Vector<Mesh *> mesh_by_layer(grease_pencil.layers().size(),
nullptr);
268 for (
const int layer_index : grease_pencil.layers().index_range()) {
269 const Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
270 if (drawing ==
nullptr) {
278 src_curves, output_type, group_index);
285 if (instances ==
nullptr) {
287 instances_component.
replace(instances);
289 for (
Mesh *mesh : mesh_by_layer) {
295 instances->add_instance(handle, float4x4::identity());
298 GeometrySet temp_set = GeometrySet::from_mesh(mesh);
300 instances->add_instance(handle, float4x4::identity());
318 params.set_output(
"Mesh", std::move(geometry_set));
326 {0,
nullptr, 0,
nullptr,
nullptr},
Low-level operations for curves.
Low-level operations for grease pencil.
Mesh * BKE_mesh_new_nomain(int verts_num, int edges_num, int faces_num, int corners_num)
#define NODE_STORAGE_FUNCS(StorageT)
#define NODE_CLASS_GEOMETRY
@ CDT_CONSTRAINTS_VALID_BMESH_WITH_HOLES
GeometryNodeCurveFillMode
@ GEO_NODE_CURVE_FILL_MODE_TRIANGULATED
@ GEO_NODE_CURVE_FILL_MODE_NGONS
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
constexpr IndexRange index_range() const
Instances * get_for_write()
void replace(Instances *instances, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
const bke::CurvesGeometry & strokes() const
int add(GField field, GVArray *varray_ptr)
local_group_size(16, 16) .push_constant(Type b
blender::meshintersect::CDT_result< double > delaunay_2d_calc(const CDT_input< double > &input, CDT_output_type output_type)
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
void node_register_type(bNodeType *ntype)
static void node_init(bNodeTree *, bNode *node)
static void node_register()
static void node_geo_exec(GeoNodeExecParams params)
static void node_rna(StructRNA *srna)
static void node_declare(NodeDeclarationBuilder &b)
static Array< meshintersect::CDT_result< double > > do_group_aware_cdt(const bke::CurvesGeometry &curves, const CDT_output_type output_type, const Field< int > &group_index_field)
static void curve_fill_calculate(GeometrySet &geometry_set, const GeometryNodeCurveFillMode mode, const Field< int > &group_index)
static void fill_curve_vert_indices(const OffsetIndices< int > offsets, MutableSpan< Vector< int > > faces)
static meshintersect::CDT_result< double > do_cdt_with_mask(const bke::CurvesGeometry &curves, const CDT_output_type output_type, const IndexMask &mask)
static Mesh * cdts_to_mesh(const Span< meshintersect::CDT_result< double > > results)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static meshintersect::CDT_result< double > do_cdt(const bke::CurvesGeometry &curves, const CDT_output_type output_type)
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void node_free_standard_storage(bNode *node)
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
GeometryComponent & get_component_for_write(GeometryComponent::Type component_type)
const GreasePencil * get_grease_pencil() const
const Curves * get_curves() const
bool has_grease_pencil() const
void replace_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
void modify_geometry_sets(ForeachSubGeometryCallback callback)
void replace_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
void replace_grease_pencil(GreasePencil *grease_pencil, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
void(* initfunc)(bNodeTree *ntree, bNode *node)
NodeGeometryExecFunction geometry_node_execute
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
NodeDeclareFunction declare