Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_volume_to_mesh.cc
| Show All 31 Lines | |||||
| #include "DNA_mesh_types.h" | #include "DNA_mesh_types.h" | ||||
| #include "DNA_meshdata_types.h" | #include "DNA_meshdata_types.h" | ||||
| #include "UI_interface.h" | #include "UI_interface.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| namespace blender::nodes::node_geo_volume_to_mesh_cc { | namespace blender::nodes::node_geo_volume_to_mesh_cc { | ||||
| static void geo_node_volume_to_mesh_declare(NodeDeclarationBuilder &b) | static void node_declare(NodeDeclarationBuilder &b) | ||||
| { | { | ||||
| b.add_input<decl::Geometry>(N_("Volume")).supported_type(GEO_COMPONENT_TYPE_VOLUME); | b.add_input<decl::Geometry>(N_("Volume")).supported_type(GEO_COMPONENT_TYPE_VOLUME); | ||||
| 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_("Threshold")).default_value(0.1f).min(0.0f); | b.add_input<decl::Float>(N_("Threshold")).default_value(0.1f).min(0.0f); | ||||
| b.add_input<decl::Float>(N_("Adaptivity")).min(0.0f).max(1.0f).subtype(PROP_FACTOR); | b.add_input<decl::Float>(N_("Adaptivity")).min(0.0f).max(1.0f).subtype(PROP_FACTOR); | ||||
| b.add_output<decl::Geometry>(N_("Mesh")); | b.add_output<decl::Geometry>(N_("Mesh")); | ||||
| } | } | ||||
| static void geo_node_volume_to_mesh_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) | static void node_layout(uiLayout *layout, 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_volume_to_mesh_init(bNodeTree *UNUSED(ntree), bNode *node) | static void node_init(bNodeTree *UNUSED(ntree), bNode *node) | ||||
| { | { | ||||
| NodeGeometryVolumeToMesh *data = (NodeGeometryVolumeToMesh *)MEM_callocN( | NodeGeometryVolumeToMesh *data = (NodeGeometryVolumeToMesh *)MEM_callocN( | ||||
| sizeof(NodeGeometryVolumeToMesh), __func__); | sizeof(NodeGeometryVolumeToMesh), __func__); | ||||
| data->resolution_mode = VOLUME_TO_MESH_RESOLUTION_MODE_GRID; | data->resolution_mode = VOLUME_TO_MESH_RESOLUTION_MODE_GRID; | ||||
| node->storage = data; | node->storage = data; | ||||
| } | } | ||||
| static void geo_node_volume_to_mesh_update(bNodeTree *ntree, bNode *node) | static void node_update(bNodeTree *ntree, bNode *node) | ||||
| { | { | ||||
| NodeGeometryVolumeToMesh *data = (NodeGeometryVolumeToMesh *)node->storage; | NodeGeometryVolumeToMesh *data = (NodeGeometryVolumeToMesh *)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 == VOLUME_TO_MESH_RESOLUTION_MODE_VOXEL_AMOUNT); | data->resolution_mode == VOLUME_TO_MESH_RESOLUTION_MODE_VOXEL_AMOUNT); | ||||
| ▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | static Mesh *create_mesh_from_volume(GeometrySet &geometry_set, GeoNodeExecParams ¶ms) | ||||
| return create_mesh_from_volume_grids(grids, | return create_mesh_from_volume_grids(grids, | ||||
| params.get_input<float>("Threshold"), | params.get_input<float>("Threshold"), | ||||
| params.get_input<float>("Adaptivity"), | params.get_input<float>("Adaptivity"), | ||||
| resolution); | resolution); | ||||
| } | } | ||||
| #endif /* WITH_OPENVDB */ | #endif /* WITH_OPENVDB */ | ||||
| static void geo_node_volume_to_mesh_exec(GeoNodeExecParams params) | static void node_geo_exec(GeoNodeExecParams params) | ||||
| { | { | ||||
| GeometrySet geometry_set = params.extract_input<GeometrySet>("Volume"); | GeometrySet geometry_set = params.extract_input<GeometrySet>("Volume"); | ||||
| #ifdef WITH_OPENVDB | #ifdef WITH_OPENVDB | ||||
| geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) { | geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) { | ||||
| Mesh *mesh = create_mesh_from_volume(geometry_set, params); | Mesh *mesh = create_mesh_from_volume(geometry_set, params); | ||||
| geometry_set.replace_mesh(mesh); | geometry_set.replace_mesh(mesh); | ||||
| geometry_set.keep_only({GEO_COMPONENT_TYPE_MESH, GEO_COMPONENT_TYPE_INSTANCES}); | geometry_set.keep_only({GEO_COMPONENT_TYPE_MESH, GEO_COMPONENT_TYPE_INSTANCES}); | ||||
| Show All 10 Lines | |||||
| void register_node_type_geo_volume_to_mesh() | void register_node_type_geo_volume_to_mesh() | ||||
| { | { | ||||
| namespace file_ns = blender::nodes::node_geo_volume_to_mesh_cc; | namespace file_ns = blender::nodes::node_geo_volume_to_mesh_cc; | ||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| geo_node_type_base(&ntype, GEO_NODE_VOLUME_TO_MESH, "Volume to Mesh", NODE_CLASS_GEOMETRY, 0); | geo_node_type_base(&ntype, GEO_NODE_VOLUME_TO_MESH, "Volume to Mesh", NODE_CLASS_GEOMETRY, 0); | ||||
| ntype.declare = file_ns::geo_node_volume_to_mesh_declare; | ntype.declare = file_ns::node_declare; | ||||
| node_type_storage( | node_type_storage( | ||||
| &ntype, "NodeGeometryVolumeToMesh", node_free_standard_storage, node_copy_standard_storage); | &ntype, "NodeGeometryVolumeToMesh", node_free_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_volume_to_mesh_init); | node_type_init(&ntype, file_ns::node_init); | ||||
| node_type_update(&ntype, file_ns::geo_node_volume_to_mesh_update); | node_type_update(&ntype, file_ns::node_update); | ||||
| ntype.geometry_node_execute = file_ns::geo_node_volume_to_mesh_exec; | ntype.geometry_node_execute = file_ns::node_geo_exec; | ||||
| ntype.draw_buttons = file_ns::geo_node_volume_to_mesh_layout; | ntype.draw_buttons = file_ns::node_layout; | ||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||