Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_set_material.cc
| Show All 21 Lines | |||||
| #include "DNA_mesh_types.h" | #include "DNA_mesh_types.h" | ||||
| #include "DNA_meshdata_types.h" | #include "DNA_meshdata_types.h" | ||||
| #include "DNA_volume_types.h" | #include "DNA_volume_types.h" | ||||
| #include "BKE_material.h" | #include "BKE_material.h" | ||||
| namespace blender::nodes::node_geo_set_material_cc { | namespace blender::nodes::node_geo_set_material_cc { | ||||
| static void geo_node_set_material_declare(NodeDeclarationBuilder &b) | static void node_declare(NodeDeclarationBuilder &b) | ||||
| { | { | ||||
| b.add_input<decl::Geometry>(N_("Geometry")) | b.add_input<decl::Geometry>(N_("Geometry")) | ||||
| .supported_type({GEO_COMPONENT_TYPE_MESH, GEO_COMPONENT_TYPE_VOLUME}); | .supported_type({GEO_COMPONENT_TYPE_MESH, GEO_COMPONENT_TYPE_VOLUME}); | ||||
| b.add_input<decl::Bool>(N_("Selection")).default_value(true).hide_value().supports_field(); | b.add_input<decl::Bool>(N_("Selection")).default_value(true).hide_value().supports_field(); | ||||
| b.add_input<decl::Material>(N_("Material")).hide_label(); | b.add_input<decl::Material>(N_("Material")).hide_label(); | ||||
| b.add_output<decl::Geometry>(N_("Geometry")); | b.add_output<decl::Geometry>(N_("Geometry")); | ||||
| } | } | ||||
| Show All 15 Lines | static void assign_material_to_faces(Mesh &mesh, const IndexMask selection, Material *material) | ||||
| mesh.mpoly = (MPoly *)CustomData_duplicate_referenced_layer(&mesh.pdata, CD_MPOLY, mesh.totpoly); | mesh.mpoly = (MPoly *)CustomData_duplicate_referenced_layer(&mesh.pdata, CD_MPOLY, mesh.totpoly); | ||||
| for (const int i : selection) { | for (const int i : selection) { | ||||
| MPoly &poly = mesh.mpoly[i]; | MPoly &poly = mesh.mpoly[i]; | ||||
| poly.mat_nr = new_material_index; | poly.mat_nr = new_material_index; | ||||
| } | } | ||||
| } | } | ||||
| static void geo_node_set_material_exec(GeoNodeExecParams params) | static void node_geo_exec(GeoNodeExecParams params) | ||||
| { | { | ||||
| Material *material = params.extract_input<Material *>("Material"); | Material *material = params.extract_input<Material *>("Material"); | ||||
| const Field<bool> selection_field = params.extract_input<Field<bool>>("Selection"); | const Field<bool> selection_field = params.extract_input<Field<bool>>("Selection"); | ||||
| GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"); | GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"); | ||||
| bool volume_selection_warning = false; | bool volume_selection_warning = false; | ||||
| geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) { | geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) { | ||||
| Show All 36 Lines | |||||
| void register_node_type_geo_set_material() | void register_node_type_geo_set_material() | ||||
| { | { | ||||
| namespace file_ns = blender::nodes::node_geo_set_material_cc; | namespace file_ns = blender::nodes::node_geo_set_material_cc; | ||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| geo_node_type_base(&ntype, GEO_NODE_SET_MATERIAL, "Set Material", NODE_CLASS_GEOMETRY, 0); | geo_node_type_base(&ntype, GEO_NODE_SET_MATERIAL, "Set Material", NODE_CLASS_GEOMETRY, 0); | ||||
| ntype.declare = file_ns::geo_node_set_material_declare; | ntype.declare = file_ns::node_declare; | ||||
| ntype.geometry_node_execute = file_ns::geo_node_set_material_exec; | ntype.geometry_node_execute = file_ns::node_geo_exec; | ||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||