Changeset View
Changeset View
Standalone View
Standalone View
source/blender/geometry/intern/curve_to_mesh_convert.cc
- This file was copied from source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc.
| Show All 9 Lines | |||||
| * GNU General Public License for more details. | * GNU General Public License for more details. | ||||
| * | * | ||||
| * You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
| * along with this program; if not, write to the Free Software Foundation, | * along with this program; if not, write to the Free Software Foundation, | ||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
| */ | */ | ||||
| #include "BLI_array.hh" | #include "BLI_array.hh" | ||||
| #include "BLI_float4x4.hh" | #include "BLI_set.hh" | ||||
| #include "BLI_task.hh" | #include "BLI_task.hh" | ||||
| #include "DNA_mesh_types.h" | #include "DNA_mesh_types.h" | ||||
| #include "DNA_meshdata_types.h" | #include "DNA_meshdata_types.h" | ||||
| #include "BKE_attribute_access.hh" | |||||
| #include "BKE_attribute_math.hh" | |||||
| #include "BKE_geometry_set.hh" | |||||
| #include "BKE_material.h" | #include "BKE_material.h" | ||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| #include "BKE_spline.hh" | #include "BKE_spline.hh" | ||||
| #include "UI_interface.h" | #include "GEO_curve_to_mesh.hh" | ||||
| #include "UI_resources.h" | |||||
| #include "node_geometry_util.hh" | using blender::bke::AttributeIDRef; | ||||
| using blender::bke::OutputAttribute; | |||||
| using blender::fn::GMutableSpan; | |||||
| using blender::fn::GSpan; | |||||
| using blender::fn::GVArray_Typed; | |||||
| using blender::fn::GVArrayPtr; | |||||
| namespace blender::nodes { | namespace blender::geometry { | ||||
| static void geo_node_curve_to_mesh_declare(NodeDeclarationBuilder &b) | |||||
| { | |||||
| b.add_input<decl::Geometry>("Curve"); | |||||
| b.add_input<decl::Geometry>("Profile Curve"); | |||||
| b.add_output<decl::Geometry>("Mesh"); | |||||
| } | |||||
| /** Information about the creation of one curve spline and profile spline combination. */ | /** Information about the creation of one curve spline and profile spline combination. */ | ||||
| struct ResultInfo { | struct ResultInfo { | ||||
| const Spline &spline; | const Spline &spline; | ||||
| const Spline &profile; | const Spline &profile; | ||||
| int vert_offset; | int vert_offset; | ||||
| int edge_offset; | int edge_offset; | ||||
| int loop_offset; | int loop_offset; | ||||
| ▲ Show 20 Lines • Show All 597 Lines • ▼ Show 20 Lines | |||||
| /** | /** | ||||
| * \note Normal calculation is by far the slowest part of calculations relating to the result mesh. | * \note Normal calculation is by far the slowest part of calculations relating to the result mesh. | ||||
| * Although it would be a sensible decision to use the better topology information available while | * Although it would be a sensible decision to use the better topology information available while | ||||
| * generating the mesh to also generate the normals, that work may wasted if the output mesh is | * generating the mesh to also generate the normals, that work may wasted if the output mesh is | ||||
| * changed anyway in a way that affects the normals. So currently this code uses the safer / | * changed anyway in a way that affects the normals. So currently this code uses the safer / | ||||
| * simpler solution of deferring normal calculation to the rest of Blender. | * simpler solution of deferring normal calculation to the rest of Blender. | ||||
| */ | */ | ||||
| static Mesh *curve_to_mesh_calculate(const CurveEval &curve, const CurveEval &profile) | Mesh *curve_to_mesh_sweep(const CurveEval &curve, const CurveEval &profile) | ||||
| { | { | ||||
| Span<SplinePtr> profiles = profile.splines(); | Span<SplinePtr> profiles = profile.splines(); | ||||
| Span<SplinePtr> curves = curve.splines(); | Span<SplinePtr> curves = curve.splines(); | ||||
| const ResultOffsets offsets = calculate_result_offsets(profiles, curves); | const ResultOffsets offsets = calculate_result_offsets(profiles, curves); | ||||
| if (offsets.vert.last() == 0) { | if (offsets.vert.last() == 0) { | ||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | static CurveEval get_curve_single_vert() | ||||
| CurveEval curve; | CurveEval curve; | ||||
| std::unique_ptr<PolySpline> spline = std::make_unique<PolySpline>(); | std::unique_ptr<PolySpline> spline = std::make_unique<PolySpline>(); | ||||
| spline->add_point(float3(0), 0, 0.0f); | spline->add_point(float3(0), 0, 0.0f); | ||||
| curve.add_spline(std::move(spline)); | curve.add_spline(std::move(spline)); | ||||
| return curve; | return curve; | ||||
| } | } | ||||
| static void geo_node_curve_to_mesh_exec(GeoNodeExecParams params) | Mesh *curve_to_wire_mesh(const CurveEval &curve) | ||||
| { | { | ||||
| GeometrySet curve_set = params.extract_input<GeometrySet>("Curve"); | |||||
| GeometrySet profile_set = params.extract_input<GeometrySet>("Profile Curve"); | |||||
| curve_set = bke::geometry_set_realize_instances(curve_set); | |||||
| profile_set = bke::geometry_set_realize_instances(profile_set); | |||||
| /* NOTE: Theoretically an "is empty" check would be more correct for errors. */ | |||||
| if (profile_set.has_mesh() && !profile_set.has_curve()) { | |||||
| params.error_message_add(NodeWarningType::Warning, | |||||
| TIP_("No curve data available in profile input")); | |||||
| } | |||||
| if (!curve_set.has_curve()) { | |||||
| if (curve_set.has_mesh()) { | |||||
| params.error_message_add(NodeWarningType::Warning, | |||||
| TIP_("No curve data available in curve input")); | |||||
| } | |||||
| params.set_output("Mesh", GeometrySet()); | |||||
| return; | |||||
| } | |||||
| const CurveEval *profile_curve = profile_set.get_curve_for_read(); | |||||
| static const CurveEval vert_curve = get_curve_single_vert(); | static const CurveEval vert_curve = get_curve_single_vert(); | ||||
| return curve_to_mesh_sweep(curve, vert_curve); | |||||
| Mesh *mesh = curve_to_mesh_calculate(*curve_set.get_curve_for_read(), | |||||
| (profile_curve == nullptr) ? vert_curve : *profile_curve); | |||||
| params.set_output("Mesh", GeometrySet::create_with_mesh(mesh)); | |||||
| } | } | ||||
| } // namespace blender::nodes | } // namespace blender::geometry | ||||
| void register_node_type_geo_curve_to_mesh() | |||||
| { | |||||
| static bNodeType ntype; | |||||
| geo_node_type_base(&ntype, GEO_NODE_CURVE_TO_MESH, "Curve to Mesh", NODE_CLASS_GEOMETRY, 0); | |||||
| ntype.declare = blender::nodes::geo_node_curve_to_mesh_declare; | |||||
| ntype.geometry_node_execute = blender::nodes::geo_node_curve_to_mesh_exec; | |||||
| nodeRegisterType(&ntype); | |||||
| } | |||||