Differential D13430 Diff 45517 source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_point_instance.cc
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_point_instance.cc
| Show First 20 Lines • Show All 180 Lines • ▼ Show 20 Lines | static void add_instances_from_component(InstancesComponent &instances, | ||||
| VArray<float3> scales = src_geometry.attribute_get_for_read<float3>("scale", domain, {1, 1, 1}); | VArray<float3> scales = src_geometry.attribute_get_for_read<float3>("scale", domain, {1, 1, 1}); | ||||
| VArray<int> id_attribute = src_geometry.attribute_get_for_read<int>("id", domain, -1); | VArray<int> id_attribute = src_geometry.attribute_get_for_read<int>("id", domain, -1); | ||||
| /* The initial size of the component might be non-zero if there are two component types. */ | /* The initial size of the component might be non-zero if there are two component types. */ | ||||
| const int start_len = instances.instances_amount(); | const int start_len = instances.instances_amount(); | ||||
| instances.resize(start_len + domain_size); | instances.resize(start_len + domain_size); | ||||
| MutableSpan<int> handles = instances.instance_reference_handles().slice(start_len, domain_size); | MutableSpan<int> handles = instances.instance_reference_handles().slice(start_len, domain_size); | ||||
| MutableSpan<float4x4> transforms = instances.instance_transforms().slice(start_len, domain_size); | MutableSpan<float4x4> transforms = instances.instance_transforms().slice(start_len, domain_size); | ||||
| MutableSpan<int> instance_ids = instances.instance_ids_ensure().slice(start_len, domain_size); | OutputAttribute_Typed<int> instance_id_attribute = | ||||
| instances.attribute_try_get_for_output_only<int>("id", ATTR_DOMAIN_INSTANCE); | |||||
| MutableSpan<int> instance_ids = instance_id_attribute.as_span(); | |||||
| /* Skip all of the randomness handling if there is only a single possible instance | /* Skip all of the randomness handling if there is only a single possible instance | ||||
| * (anything except for collection mode with "Whole Collection" turned off). */ | * (anything except for collection mode with "Whole Collection" turned off). */ | ||||
| if (possible_handles.size() == 1) { | if (possible_handles.size() == 1) { | ||||
| const int handle = possible_handles.first(); | const int handle = possible_handles.first(); | ||||
| threading::parallel_for(IndexRange(domain_size), 1024, [&](IndexRange range) { | threading::parallel_for(IndexRange(domain_size), 1024, [&](IndexRange range) { | ||||
| for (const int i : range) { | for (const int i : range) { | ||||
| handles[i] = handle; | handles[i] = handle; | ||||
| Show All 10 Lines | threading::parallel_for(IndexRange(domain_size), 1024, [&](IndexRange range) { | ||||
| const int index = BLI_hash_int_2d(ids[i], seed) % possible_handles.size(); | const int index = BLI_hash_int_2d(ids[i], seed) % possible_handles.size(); | ||||
| const int handle = possible_handles[index]; | const int handle = possible_handles[index]; | ||||
| handles[i] = handle; | handles[i] = handle; | ||||
| transforms[i] = float4x4::from_loc_eul_scale(positions[i], rotations[i], scales[i]); | transforms[i] = float4x4::from_loc_eul_scale(positions[i], rotations[i], scales[i]); | ||||
| instance_ids[i] = id_attribute[i]; | instance_ids[i] = id_attribute[i]; | ||||
| } | } | ||||
| }); | }); | ||||
| } | } | ||||
| instance_id_attribute.save(); | |||||
| } | } | ||||
| static void node_geo_exec(GeoNodeExecParams params) | static void node_geo_exec(GeoNodeExecParams params) | ||||
| { | { | ||||
| GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"); | GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"); | ||||
| GeometrySet geometry_set_out; | GeometrySet geometry_set_out; | ||||
| /* TODO: This node should be able to instance on the input instances component | /* TODO: This node should be able to instance on the input instances component | ||||
| ▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines | |||||