Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc
| Show First 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | static Set<std::string> find_all_attribute_names(Span<const GeometryComponent *> components) | ||||
| return attribute_names; | return attribute_names; | ||||
| } | } | ||||
| static void determine_final_data_type_and_domain(Span<const GeometryComponent *> components, | static void determine_final_data_type_and_domain(Span<const GeometryComponent *> components, | ||||
| StringRef attribute_name, | StringRef attribute_name, | ||||
| CustomDataType *r_type, | CustomDataType *r_type, | ||||
| AttributeDomain *r_domain) | AttributeDomain *r_domain) | ||||
| { | { | ||||
| Vector<CustomDataType> data_types; | |||||
| for (const GeometryComponent *component : components) { | for (const GeometryComponent *component : components) { | ||||
| ReadAttributePtr attribute = component->attribute_try_get_for_read(attribute_name); | ReadAttributePtr attribute = component->attribute_try_get_for_read(attribute_name); | ||||
| if (attribute) { | if (attribute) { | ||||
| /* TODO: Use data type with most information. */ | data_types.append(attribute->custom_data_type()); | ||||
| *r_type = bke::cpp_type_to_custom_data_type(attribute->cpp_type()); | |||||
| /* TODO: Use highest priority domain. */ | /* TODO: Use highest priority domain. */ | ||||
| *r_domain = attribute->domain(); | *r_domain = attribute->domain(); | ||||
| return; | |||||
| } | } | ||||
| } | } | ||||
| BLI_assert(false); | |||||
| *r_type = attribute_data_type_highest_complexity(data_types); | |||||
| } | } | ||||
| static void fill_new_attribute(Span<const GeometryComponent *> src_components, | static void fill_new_attribute(Span<const GeometryComponent *> src_components, | ||||
| StringRef attribute_name, | StringRef attribute_name, | ||||
| const CustomDataType data_type, | const CustomDataType data_type, | ||||
| const AttributeDomain domain, | const AttributeDomain domain, | ||||
| fn::GMutableSpan dst_span) | fn::GMutableSpan dst_span) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | for (const InstancesComponent *component : src_components) { | ||||
| Span<InstancedData> instanced_data = component->instanced_data(); | Span<InstancedData> instanced_data = component->instanced_data(); | ||||
| Span<float4x4> transforms = component->transforms(); | Span<float4x4> transforms = component->transforms(); | ||||
| for (const int i : IndexRange(size)) { | for (const int i : IndexRange(size)) { | ||||
| dst_component.add_instance(instanced_data[i], transforms[i]); | dst_component.add_instance(instanced_data[i], transforms[i]); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void join_components(Span<const VolumeComponent *> src_components, GeometrySet &result) | |||||
| { | |||||
| /* Not yet supported. Joining volume grids with the same name requires resampling of at least one | |||||
| * of the grids. The cell size of the resulting volume has to be determined somehow. */ | |||||
| VolumeComponent &dst_component = result.get_component_for_write<VolumeComponent>(); | |||||
| UNUSED_VARS(src_components, dst_component); | |||||
| } | |||||
| template<typename Component> | template<typename Component> | ||||
| static void join_component_type(Span<const GeometrySet *> src_geometry_sets, GeometrySet &result) | static void join_component_type(Span<const GeometrySet *> src_geometry_sets, GeometrySet &result) | ||||
| { | { | ||||
| Vector<const Component *> components; | Vector<const Component *> components; | ||||
| for (const GeometrySet *geometry_set : src_geometry_sets) { | for (const GeometrySet *geometry_set : src_geometry_sets) { | ||||
| const Component *component = geometry_set->get_component_for_read<Component>(); | const Component *component = geometry_set->get_component_for_read<Component>(); | ||||
| if (component != nullptr && !component->is_empty()) { | if (component != nullptr && !component->is_empty()) { | ||||
| components.append(component); | components.append(component); | ||||
| Show All 16 Lines | static void geo_node_join_geometry_exec(GeoNodeExecParams params) | ||||
| GeometrySet geometry_set_b = params.extract_input<GeometrySet>("Geometry_001"); | GeometrySet geometry_set_b = params.extract_input<GeometrySet>("Geometry_001"); | ||||
| GeometrySet geometry_set_result; | GeometrySet geometry_set_result; | ||||
| std::array<const GeometrySet *, 2> src_geometry_sets = {&geometry_set_a, &geometry_set_b}; | std::array<const GeometrySet *, 2> src_geometry_sets = {&geometry_set_a, &geometry_set_b}; | ||||
| join_component_type<MeshComponent>(src_geometry_sets, geometry_set_result); | join_component_type<MeshComponent>(src_geometry_sets, geometry_set_result); | ||||
| join_component_type<PointCloudComponent>(src_geometry_sets, geometry_set_result); | join_component_type<PointCloudComponent>(src_geometry_sets, geometry_set_result); | ||||
| join_component_type<InstancesComponent>(src_geometry_sets, geometry_set_result); | join_component_type<InstancesComponent>(src_geometry_sets, geometry_set_result); | ||||
| join_component_type<VolumeComponent>(src_geometry_sets, geometry_set_result); | |||||
| params.set_output("Geometry", std::move(geometry_set_result)); | params.set_output("Geometry", std::move(geometry_set_result)); | ||||
| } | } | ||||
| } // namespace blender::nodes | } // namespace blender::nodes | ||||
| void register_node_type_geo_join_geometry() | void register_node_type_geo_join_geometry() | ||||
| { | { | ||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| geo_node_type_base(&ntype, GEO_NODE_JOIN_GEOMETRY, "Join Geometry", NODE_CLASS_GEOMETRY, 0); | geo_node_type_base(&ntype, GEO_NODE_JOIN_GEOMETRY, "Join Geometry", NODE_CLASS_GEOMETRY, 0); | ||||
| node_type_socket_templates(&ntype, geo_node_join_geometry_in, geo_node_join_geometry_out); | node_type_socket_templates(&ntype, geo_node_join_geometry_in, geo_node_join_geometry_out); | ||||
| ntype.geometry_node_execute = blender::nodes::geo_node_join_geometry_exec; | ntype.geometry_node_execute = blender::nodes::geo_node_join_geometry_exec; | ||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||