Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc
| Show All 24 Lines | |||||
| #include "BKE_lib_id.h" | #include "BKE_lib_id.h" | ||||
| #include "BKE_volume.h" | #include "BKE_volume.h" | ||||
| #include "UI_interface.h" | #include "UI_interface.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| namespace blender::nodes::node_geo_points_to_volume_cc { | namespace blender::nodes::node_geo_points_to_volume_cc { | ||||
| static void geo_node_points_to_volume_declare(NodeDeclarationBuilder &b) | static void node_declare(NodeDeclarationBuilder &b) | ||||
| { | { | ||||
| b.add_input<decl::Geometry>(N_("Points")); | b.add_input<decl::Geometry>(N_("Points")); | ||||
| b.add_input<decl::Float>(N_("Density")).default_value(1.0f).min(0.0f); | b.add_input<decl::Float>(N_("Density")).default_value(1.0f).min(0.0f); | ||||
| b.add_input<decl::Float>(N_("Voxel Size")).default_value(0.3f).min(0.01f).subtype(PROP_DISTANCE); | b.add_input<decl::Float>(N_("Voxel Size")).default_value(0.3f).min(0.01f).subtype(PROP_DISTANCE); | ||||
| b.add_input<decl::Float>(N_("Voxel Amount")).default_value(64.0f).min(0.0f); | b.add_input<decl::Float>(N_("Voxel Amount")).default_value(64.0f).min(0.0f); | ||||
| b.add_input<decl::Float>(N_("Radius")) | b.add_input<decl::Float>(N_("Radius")) | ||||
| .default_value(0.5f) | .default_value(0.5f) | ||||
| .min(0.0f) | .min(0.0f) | ||||
| .subtype(PROP_DISTANCE) | .subtype(PROP_DISTANCE) | ||||
| .supports_field(); | .supports_field(); | ||||
| b.add_output<decl::Geometry>(N_("Volume")); | b.add_output<decl::Geometry>(N_("Volume")); | ||||
| } | } | ||||
| static void geo_node_points_to_volume_layout(uiLayout *layout, | static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) | ||||
| bContext *UNUSED(C), | |||||
| PointerRNA *ptr) | |||||
| { | { | ||||
| uiLayoutSetPropSep(layout, true); | uiLayoutSetPropSep(layout, true); | ||||
| uiLayoutSetPropDecorate(layout, false); | uiLayoutSetPropDecorate(layout, false); | ||||
| uiItemR(layout, ptr, "resolution_mode", 0, IFACE_("Resolution"), ICON_NONE); | uiItemR(layout, ptr, "resolution_mode", 0, IFACE_("Resolution"), ICON_NONE); | ||||
| } | } | ||||
| static void geo_node_points_to_volume_init(bNodeTree *UNUSED(ntree), bNode *node) | static void node_init(bNodeTree *UNUSED(ntree), bNode *node) | ||||
| { | { | ||||
| NodeGeometryPointsToVolume *data = (NodeGeometryPointsToVolume *)MEM_callocN( | NodeGeometryPointsToVolume *data = (NodeGeometryPointsToVolume *)MEM_callocN( | ||||
| sizeof(NodeGeometryPointsToVolume), __func__); | sizeof(NodeGeometryPointsToVolume), __func__); | ||||
| data->resolution_mode = GEO_NODE_POINTS_TO_VOLUME_RESOLUTION_MODE_AMOUNT; | data->resolution_mode = GEO_NODE_POINTS_TO_VOLUME_RESOLUTION_MODE_AMOUNT; | ||||
| node->storage = data; | node->storage = data; | ||||
| } | } | ||||
| static void geo_node_points_to_volume_update(bNodeTree *ntree, bNode *node) | static void node_update(bNodeTree *ntree, bNode *node) | ||||
| { | { | ||||
| NodeGeometryPointsToVolume *data = (NodeGeometryPointsToVolume *)node->storage; | NodeGeometryPointsToVolume *data = (NodeGeometryPointsToVolume *)node->storage; | ||||
| bNodeSocket *voxel_size_socket = nodeFindSocket(node, SOCK_IN, "Voxel Size"); | bNodeSocket *voxel_size_socket = nodeFindSocket(node, SOCK_IN, "Voxel Size"); | ||||
| bNodeSocket *voxel_amount_socket = nodeFindSocket(node, SOCK_IN, "Voxel Amount"); | bNodeSocket *voxel_amount_socket = nodeFindSocket(node, SOCK_IN, "Voxel Amount"); | ||||
| nodeSetSocketAvailability(ntree, | nodeSetSocketAvailability(ntree, | ||||
| voxel_amount_socket, | voxel_amount_socket, | ||||
| data->resolution_mode == | data->resolution_mode == | ||||
| GEO_NODE_POINTS_TO_VOLUME_RESOLUTION_MODE_AMOUNT); | GEO_NODE_POINTS_TO_VOLUME_RESOLUTION_MODE_AMOUNT); | ||||
| ▲ Show 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | static void initialize_volume_component_from_points(GeoNodeExecParams ¶ms, | ||||
| new_grid->transform().postScale(voxel_size); | new_grid->transform().postScale(voxel_size); | ||||
| BKE_volume_grid_add_vdb(*volume, "density", std::move(new_grid)); | BKE_volume_grid_add_vdb(*volume, "density", std::move(new_grid)); | ||||
| r_geometry_set.keep_only({GEO_COMPONENT_TYPE_VOLUME, GEO_COMPONENT_TYPE_INSTANCES}); | r_geometry_set.keep_only({GEO_COMPONENT_TYPE_VOLUME, GEO_COMPONENT_TYPE_INSTANCES}); | ||||
| r_geometry_set.replace_volume(volume); | r_geometry_set.replace_volume(volume); | ||||
| } | } | ||||
| #endif | #endif | ||||
| static void geo_node_points_to_volume_exec(GeoNodeExecParams params) | static void node_exec(GeoNodeExecParams params) | ||||
| { | { | ||||
| GeometrySet geometry_set = params.extract_input<GeometrySet>("Points"); | GeometrySet geometry_set = params.extract_input<GeometrySet>("Points"); | ||||
| #ifdef WITH_OPENVDB | #ifdef WITH_OPENVDB | ||||
| geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) { | geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) { | ||||
| initialize_volume_component_from_points(params, geometry_set); | initialize_volume_component_from_points(params, geometry_set); | ||||
| }); | }); | ||||
| params.set_output("Volume", std::move(geometry_set)); | params.set_output("Volume", std::move(geometry_set)); | ||||
| Show All 14 Lines | void register_node_type_geo_points_to_volume() | ||||
| geo_node_type_base( | geo_node_type_base( | ||||
| &ntype, GEO_NODE_POINTS_TO_VOLUME, "Points to Volume", NODE_CLASS_GEOMETRY, 0); | &ntype, GEO_NODE_POINTS_TO_VOLUME, "Points to Volume", NODE_CLASS_GEOMETRY, 0); | ||||
| node_type_storage(&ntype, | node_type_storage(&ntype, | ||||
| "NodeGeometryPointsToVolume", | "NodeGeometryPointsToVolume", | ||||
| node_free_standard_storage, | node_free_standard_storage, | ||||
| node_copy_standard_storage); | node_copy_standard_storage); | ||||
| node_type_size(&ntype, 170, 120, 700); | node_type_size(&ntype, 170, 120, 700); | ||||
| node_type_init(&ntype, file_ns::geo_node_points_to_volume_init); | node_type_init(&ntype, file_ns::node_init); | ||||
| node_type_update(&ntype, file_ns::geo_node_points_to_volume_update); | node_type_update(&ntype, file_ns::node_update); | ||||
| ntype.declare = file_ns::geo_node_points_to_volume_declare; | ntype.declare = file_ns::node_declare; | ||||
| ntype.geometry_node_execute = file_ns::geo_node_points_to_volume_exec; | ntype.geometry_node_execute = file_ns::node_exec; | ||||
| ntype.draw_buttons = file_ns::geo_node_points_to_volume_layout; | ntype.draw_buttons = file_ns::node_layout; | ||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||