Merge branch 'master' into temp-sculpt-colors
This commit is contained in:
commit
3efad90211
Binary file not shown.
|
@ -67,13 +67,20 @@ Mesh *create_grid_mesh(const int verts_x,
|
|||
const float size_x,
|
||||
const float size_y);
|
||||
|
||||
struct ConeAttributeOutputs {
|
||||
StrongAnonymousAttributeID top_id;
|
||||
StrongAnonymousAttributeID bottom_id;
|
||||
StrongAnonymousAttributeID side_id;
|
||||
};
|
||||
|
||||
Mesh *create_cylinder_or_cone_mesh(const float radius_top,
|
||||
const float radius_bottom,
|
||||
const float depth,
|
||||
const int circle_segments,
|
||||
const int side_segments,
|
||||
const int fill_segments,
|
||||
const GeometryNodeMeshCircleFillType fill_type);
|
||||
const GeometryNodeMeshCircleFillType fill_type,
|
||||
ConeAttributeOutputs &attribute_outputs);
|
||||
|
||||
Mesh *create_cuboid_mesh(float3 size, int verts_x, int verts_y, int verts_z);
|
||||
|
||||
|
|
|
@ -24,7 +24,16 @@ namespace blender::nodes {
|
|||
|
||||
static void geo_node_curve_parameter_declare(NodeDeclarationBuilder &b)
|
||||
{
|
||||
b.add_output<decl::Float>(N_("Factor")).field_source();
|
||||
b.add_output<decl::Float>(N_("Factor"))
|
||||
.field_source()
|
||||
.description(
|
||||
N_("For points, the portion of the spline's total length at the control point. For "
|
||||
"Splines, the factor of that spline within the entire curve"));
|
||||
b.add_output<decl::Float>(N_("Length"))
|
||||
.field_source()
|
||||
.description(
|
||||
N_("For points, the distance along the control point's spline, For splines, the "
|
||||
"distance along the entire curve"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,47 +41,42 @@ static void geo_node_curve_parameter_declare(NodeDeclarationBuilder &b)
|
|||
* average parameter for each spline would just be 0.5, or close to it. Instead, the parameter for
|
||||
* each spline is the portion of the total length at the start of the spline.
|
||||
*/
|
||||
static Array<float> curve_parameter_spline_domain(const CurveEval &curve, const IndexMask mask)
|
||||
static Array<float> curve_length_spline_domain(const CurveEval &curve,
|
||||
const IndexMask UNUSED(mask))
|
||||
{
|
||||
Span<SplinePtr> splines = curve.splines();
|
||||
float length = 0.0f;
|
||||
Array<float> parameters(splines.size());
|
||||
Array<float> lengths(splines.size());
|
||||
for (const int i : splines.index_range()) {
|
||||
parameters[i] = length;
|
||||
lengths[i] = length;
|
||||
length += splines[i]->length();
|
||||
}
|
||||
const float total_length_inverse = length == 0.0f ? 0.0f : 1.0f / length;
|
||||
mask.foreach_index([&](const int64_t i) { parameters[i] *= total_length_inverse; });
|
||||
|
||||
return parameters;
|
||||
return lengths;
|
||||
}
|
||||
|
||||
/**
|
||||
* The parameter at each control point is the factor at the corresponding evaluated point.
|
||||
*/
|
||||
static void calculate_bezier_parameters(const BezierSpline &spline, MutableSpan<float> parameters)
|
||||
static void calculate_bezier_lengths(const BezierSpline &spline, MutableSpan<float> lengths)
|
||||
{
|
||||
Span<int> offsets = spline.control_point_offsets();
|
||||
Span<float> lengths = spline.evaluated_lengths();
|
||||
const float total_length = spline.length();
|
||||
const float total_length_inverse = total_length == 0.0f ? 0.0f : 1.0f / total_length;
|
||||
|
||||
Span<float> lengths_eval = spline.evaluated_lengths();
|
||||
for (const int i : IndexRange(1, spline.size() - 1)) {
|
||||
parameters[i] = lengths[offsets[i] - 1] * total_length_inverse;
|
||||
lengths[i] = lengths_eval[offsets[i] - 1];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The parameter for poly splines is simply the evaluated lengths divided by the total length.
|
||||
*/
|
||||
static void calculate_poly_parameters(const PolySpline &spline, MutableSpan<float> parameters)
|
||||
static void calculate_poly_length(const PolySpline &spline, MutableSpan<float> lengths)
|
||||
{
|
||||
Span<float> lengths = spline.evaluated_lengths();
|
||||
const float total_length = spline.length();
|
||||
const float total_length_inverse = total_length == 0.0f ? 0.0f : 1.0f / total_length;
|
||||
|
||||
for (const int i : IndexRange(1, spline.size() - 1)) {
|
||||
parameters[i] = lengths[i - 1] * total_length_inverse;
|
||||
Span<float> lengths_eval = spline.evaluated_lengths();
|
||||
if (spline.is_cyclic()) {
|
||||
lengths.drop_front(1).copy_from(lengths_eval.drop_back(1));
|
||||
}
|
||||
else {
|
||||
lengths.drop_front(1).copy_from(lengths_eval);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,52 +86,47 @@ static void calculate_poly_parameters(const PolySpline &spline, MutableSpan<floa
|
|||
* each point is not well defined. So instead, treat the control points as if they were a poly
|
||||
* spline.
|
||||
*/
|
||||
static void calculate_nurbs_parameters(const NURBSpline &spline, MutableSpan<float> parameters)
|
||||
static void calculate_nurbs_lengths(const NURBSpline &spline, MutableSpan<float> lengths)
|
||||
{
|
||||
Span<float3> positions = spline.positions();
|
||||
Array<float> control_point_lengths(spline.size());
|
||||
|
||||
float length = 0.0f;
|
||||
for (const int i : IndexRange(positions.size() - 1)) {
|
||||
parameters[i] = length;
|
||||
lengths[i] = length;
|
||||
length += float3::distance(positions[i], positions[i + 1]);
|
||||
}
|
||||
|
||||
const float total_length_inverse = length == 0.0f ? 0.0f : 1.0f / length;
|
||||
for (float ¶meter : parameters) {
|
||||
parameter *= total_length_inverse;
|
||||
}
|
||||
lengths.last() = length;
|
||||
}
|
||||
|
||||
static Array<float> curve_parameter_point_domain(const CurveEval &curve)
|
||||
static Array<float> curve_length_point_domain(const CurveEval &curve)
|
||||
{
|
||||
Span<SplinePtr> splines = curve.splines();
|
||||
Array<int> offsets = curve.control_point_offsets();
|
||||
const int total_size = offsets.last();
|
||||
Array<float> parameters(total_size);
|
||||
Array<float> lengths(total_size);
|
||||
|
||||
threading::parallel_for(splines.index_range(), 128, [&](IndexRange range) {
|
||||
for (const int i : range) {
|
||||
const Spline &spline = *splines[i];
|
||||
MutableSpan spline_factors{parameters.as_mutable_span().slice(offsets[i], spline.size())};
|
||||
MutableSpan spline_factors{lengths.as_mutable_span().slice(offsets[i], spline.size())};
|
||||
spline_factors.first() = 0.0f;
|
||||
switch (splines[i]->type()) {
|
||||
case Spline::Type::Bezier: {
|
||||
calculate_bezier_parameters(static_cast<const BezierSpline &>(spline), spline_factors);
|
||||
calculate_bezier_lengths(static_cast<const BezierSpline &>(spline), spline_factors);
|
||||
break;
|
||||
}
|
||||
case Spline::Type::Poly: {
|
||||
calculate_poly_parameters(static_cast<const PolySpline &>(spline), spline_factors);
|
||||
calculate_poly_length(static_cast<const PolySpline &>(spline), spline_factors);
|
||||
break;
|
||||
}
|
||||
case Spline::Type::NURBS: {
|
||||
calculate_nurbs_parameters(static_cast<const NURBSpline &>(spline), spline_factors);
|
||||
calculate_nurbs_lengths(static_cast<const NURBSpline &>(spline), spline_factors);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return parameters;
|
||||
return lengths;
|
||||
}
|
||||
|
||||
static const GVArray *construct_curve_parameter_gvarray(const CurveEval &curve,
|
||||
|
@ -136,13 +135,50 @@ static const GVArray *construct_curve_parameter_gvarray(const CurveEval &curve,
|
|||
ResourceScope &scope)
|
||||
{
|
||||
if (domain == ATTR_DOMAIN_POINT) {
|
||||
Array<float> parameters = curve_parameter_point_domain(curve);
|
||||
return &scope.construct<fn::GVArray_For_ArrayContainer<Array<float>>>(std::move(parameters));
|
||||
Span<SplinePtr> splines = curve.splines();
|
||||
Array<float> values = curve_length_point_domain(curve);
|
||||
|
||||
const Array<int> offsets = curve.control_point_offsets();
|
||||
for (const int i_spline : curve.splines().index_range()) {
|
||||
const Spline &spline = *splines[i_spline];
|
||||
const float spline_length = spline.length();
|
||||
const float spline_length_inv = spline_length == 0.0f ? 0.0f : 1.0f / spline_length;
|
||||
for (const int i : IndexRange(spline.size())) {
|
||||
values[offsets[i_spline] + i] *= spline_length_inv;
|
||||
}
|
||||
}
|
||||
return &scope.construct<fn::GVArray_For_ArrayContainer<Array<float>>>(std::move(values));
|
||||
}
|
||||
|
||||
if (domain == ATTR_DOMAIN_CURVE) {
|
||||
Array<float> parameters = curve_parameter_spline_domain(curve, mask);
|
||||
return &scope.construct<fn::GVArray_For_ArrayContainer<Array<float>>>(std::move(parameters));
|
||||
Array<float> values = curve.accumulated_spline_lengths();
|
||||
const float total_length_inv = values.last() == 0.0f ? 0.0f : 1.0f / values.last();
|
||||
for (const int i : mask) {
|
||||
values[i] *= total_length_inv;
|
||||
}
|
||||
return &scope.construct<fn::GVArray_For_ArrayContainer<Array<float>>>(std::move(values));
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static const GVArray *construct_curve_length_gvarray(const CurveEval &curve,
|
||||
const IndexMask mask,
|
||||
const AttributeDomain domain,
|
||||
ResourceScope &scope)
|
||||
{
|
||||
if (domain == ATTR_DOMAIN_POINT) {
|
||||
Array<float> lengths = curve_length_point_domain(curve);
|
||||
return &scope.construct<fn::GVArray_For_ArrayContainer<Array<float>>>(std::move(lengths));
|
||||
}
|
||||
|
||||
if (domain == ATTR_DOMAIN_CURVE) {
|
||||
if (curve.splines().size() == 1) {
|
||||
Array<float> lengths(1, 0.0f);
|
||||
return &scope.construct<fn::GVArray_For_ArrayContainer<Array<float>>>(std::move(lengths));
|
||||
}
|
||||
|
||||
Array<float> lengths = curve_length_spline_domain(curve, mask);
|
||||
return &scope.construct<fn::GVArray_For_ArrayContainer<Array<float>>>(std::move(lengths));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
@ -188,10 +224,51 @@ class CurveParameterFieldInput final : public fn::FieldInput {
|
|||
}
|
||||
};
|
||||
|
||||
class CurveLengthFieldInput final : public fn::FieldInput {
|
||||
public:
|
||||
CurveLengthFieldInput() : fn::FieldInput(CPPType::get<float>(), "Curve Length node")
|
||||
{
|
||||
category_ = Category::Generated;
|
||||
}
|
||||
|
||||
const GVArray *get_varray_for_context(const fn::FieldContext &context,
|
||||
IndexMask mask,
|
||||
ResourceScope &scope) const final
|
||||
{
|
||||
if (const GeometryComponentFieldContext *geometry_context =
|
||||
dynamic_cast<const GeometryComponentFieldContext *>(&context)) {
|
||||
|
||||
const GeometryComponent &component = geometry_context->geometry_component();
|
||||
const AttributeDomain domain = geometry_context->domain();
|
||||
if (component.type() == GEO_COMPONENT_TYPE_CURVE) {
|
||||
const CurveComponent &curve_component = static_cast<const CurveComponent &>(component);
|
||||
const CurveEval *curve = curve_component.get_for_read();
|
||||
if (curve) {
|
||||
return construct_curve_length_gvarray(*curve, mask, domain, scope);
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint64_t hash() const override
|
||||
{
|
||||
/* Some random constant hash. */
|
||||
return 345634563454;
|
||||
}
|
||||
|
||||
bool is_equal_to(const fn::FieldNode &other) const override
|
||||
{
|
||||
return dynamic_cast<const CurveLengthFieldInput *>(&other) != nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
static void geo_node_curve_parameter_exec(GeoNodeExecParams params)
|
||||
{
|
||||
Field<float> parameter_field{std::make_shared<CurveParameterFieldInput>()};
|
||||
Field<float> length_field{std::make_shared<CurveLengthFieldInput>()};
|
||||
params.set_output("Factor", std::move(parameter_field));
|
||||
params.set_output("Length", std::move(length_field));
|
||||
}
|
||||
|
||||
} // namespace blender::nodes
|
||||
|
@ -199,7 +276,6 @@ static void geo_node_curve_parameter_exec(GeoNodeExecParams params)
|
|||
void register_node_type_geo_curve_parameter()
|
||||
{
|
||||
static bNodeType ntype;
|
||||
|
||||
geo_node_type_base(&ntype, GEO_NODE_CURVE_PARAMETER, "Curve Parameter", NODE_CLASS_INPUT, 0);
|
||||
ntype.geometry_node_execute = blender::nodes::geo_node_curve_parameter_exec;
|
||||
ntype.declare = blender::nodes::geo_node_curve_parameter_declare;
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
|
||||
#include "node_geometry_util.hh"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace blender::nodes {
|
||||
|
||||
static void geo_node_mesh_primitive_cone_declare(NodeDeclarationBuilder &b)
|
||||
|
@ -59,6 +61,9 @@ static void geo_node_mesh_primitive_cone_declare(NodeDeclarationBuilder &b)
|
|||
.subtype(PROP_DISTANCE)
|
||||
.description(N_("Height of the generated cone"));
|
||||
b.add_output<decl::Geometry>(N_("Mesh"));
|
||||
b.add_output<decl::Bool>(N_("Top")).field_source();
|
||||
b.add_output<decl::Bool>(N_("Bottom")).field_source();
|
||||
b.add_output<decl::Bool>(N_("Side")).field_source();
|
||||
}
|
||||
|
||||
static void geo_node_mesh_primitive_cone_init(bNodeTree *UNUSED(ntree), bNode *node)
|
||||
|
@ -114,6 +119,8 @@ struct ConeConfig {
|
|||
int tot_edge_rings;
|
||||
int tot_verts;
|
||||
int tot_edges;
|
||||
int tot_corners;
|
||||
int tot_faces;
|
||||
|
||||
/* Helpful vertex indices. */
|
||||
int first_vert;
|
||||
|
@ -127,6 +134,14 @@ struct ConeConfig {
|
|||
int last_fan_edges_start;
|
||||
int last_edge;
|
||||
|
||||
/* Helpful face indices. */
|
||||
int top_faces_start;
|
||||
int top_faces_len;
|
||||
int side_faces_start;
|
||||
int side_faces_len;
|
||||
int bottom_faces_start;
|
||||
int bottom_faces_len;
|
||||
|
||||
ConeConfig(float radius_top,
|
||||
float radius_bottom,
|
||||
float depth,
|
||||
|
@ -153,6 +168,7 @@ struct ConeConfig {
|
|||
this->tot_edge_rings = this->calculate_total_edge_rings();
|
||||
this->tot_verts = this->calculate_total_verts();
|
||||
this->tot_edges = this->calculate_total_edges();
|
||||
this->tot_corners = this->calculate_total_corners();
|
||||
|
||||
this->first_vert = 0;
|
||||
this->first_ring_verts_start = this->top_has_center_vert ? 1 : first_vert;
|
||||
|
@ -164,6 +180,36 @@ struct ConeConfig {
|
|||
this->tot_quad_rings * this->circle_segments * 2;
|
||||
this->last_fan_edges_start = this->tot_edges - this->circle_segments;
|
||||
this->last_edge = this->tot_edges - 1;
|
||||
|
||||
this->top_faces_start = 0;
|
||||
if (!this->top_is_point) {
|
||||
this->top_faces_len = (fill_segments - 1) * circle_segments;
|
||||
this->top_faces_len += this->top_has_center_vert ? circle_segments : 0;
|
||||
this->top_faces_len += this->fill_type == GEO_NODE_MESH_CIRCLE_FILL_NGON ? 1 : 0;
|
||||
}
|
||||
else {
|
||||
this->top_faces_len = 0;
|
||||
}
|
||||
|
||||
this->side_faces_start = this->top_faces_len;
|
||||
if (this->top_is_point && this->bottom_is_point) {
|
||||
this->side_faces_len = 0;
|
||||
}
|
||||
else {
|
||||
this->side_faces_len = side_segments * circle_segments;
|
||||
}
|
||||
|
||||
if (!this->bottom_is_point) {
|
||||
this->bottom_faces_len = (fill_segments - 1) * circle_segments;
|
||||
this->bottom_faces_len += this->bottom_has_center_vert ? circle_segments : 0;
|
||||
this->bottom_faces_len += this->fill_type == GEO_NODE_MESH_CIRCLE_FILL_NGON ? 1 : 0;
|
||||
}
|
||||
else {
|
||||
this->bottom_faces_len = 0;
|
||||
}
|
||||
this->bottom_faces_start = this->side_faces_start + this->side_faces_len;
|
||||
|
||||
this->tot_faces = this->top_faces_len + this->side_faces_len + this->bottom_faces_len;
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -171,10 +217,7 @@ struct ConeConfig {
|
|||
int calculate_total_edge_rings();
|
||||
int calculate_total_verts();
|
||||
int calculate_total_edges();
|
||||
|
||||
public:
|
||||
int get_tot_corners() const;
|
||||
int get_tot_faces() const;
|
||||
int calculate_total_corners();
|
||||
};
|
||||
|
||||
int ConeConfig::calculate_total_quad_rings()
|
||||
|
@ -268,7 +311,7 @@ int ConeConfig::calculate_total_edges()
|
|||
return edge_total;
|
||||
}
|
||||
|
||||
int ConeConfig::get_tot_corners() const
|
||||
int ConeConfig::calculate_total_corners()
|
||||
{
|
||||
if (top_is_point && bottom_is_point) {
|
||||
return 0;
|
||||
|
@ -295,32 +338,6 @@ int ConeConfig::get_tot_corners() const
|
|||
return corner_total;
|
||||
}
|
||||
|
||||
int ConeConfig::get_tot_faces() const
|
||||
{
|
||||
if (top_is_point && bottom_is_point) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int face_total = 0;
|
||||
if (top_has_center_vert) {
|
||||
face_total += circle_segments;
|
||||
}
|
||||
else if (!top_is_point && fill_type == GEO_NODE_MESH_CIRCLE_FILL_NGON) {
|
||||
face_total++;
|
||||
}
|
||||
|
||||
face_total += tot_quad_rings * circle_segments;
|
||||
|
||||
if (bottom_has_center_vert) {
|
||||
face_total += circle_segments;
|
||||
}
|
||||
else if (!bottom_is_point && fill_type == GEO_NODE_MESH_CIRCLE_FILL_NGON) {
|
||||
face_total++;
|
||||
}
|
||||
|
||||
return face_total;
|
||||
}
|
||||
|
||||
static void calculate_cone_vertices(const MutableSpan<MVert> &verts, const ConeConfig &config)
|
||||
{
|
||||
Array<float2> circle(config.circle_segments);
|
||||
|
@ -542,6 +559,60 @@ static void calculate_cone_faces(const MutableSpan<MLoop> &loops,
|
|||
}
|
||||
}
|
||||
|
||||
static void calculate_selection_outputs(Mesh *mesh,
|
||||
const ConeConfig &config,
|
||||
ConeAttributeOutputs &attribute_outputs)
|
||||
{
|
||||
MeshComponent mesh_component;
|
||||
mesh_component.replace(mesh, GeometryOwnershipType::Editable);
|
||||
|
||||
/* Populate "Top" selection output. */
|
||||
if (attribute_outputs.top_id) {
|
||||
const bool face = !config.top_is_point && config.fill_type != GEO_NODE_MESH_CIRCLE_FILL_NONE;
|
||||
OutputAttribute_Typed<bool> attribute = mesh_component.attribute_try_get_for_output_only<bool>(
|
||||
attribute_outputs.top_id.get(), face ? ATTR_DOMAIN_FACE : ATTR_DOMAIN_POINT);
|
||||
MutableSpan<bool> selection = attribute.as_span();
|
||||
|
||||
if (config.top_is_point) {
|
||||
selection[config.first_vert] = true;
|
||||
}
|
||||
else {
|
||||
selection.slice(0, face ? config.top_faces_len : config.circle_segments).fill(true);
|
||||
}
|
||||
attribute.save();
|
||||
}
|
||||
|
||||
/* Populate "Bottom" selection output. */
|
||||
if (attribute_outputs.bottom_id) {
|
||||
const bool face = !config.bottom_is_point &&
|
||||
config.fill_type != GEO_NODE_MESH_CIRCLE_FILL_NONE;
|
||||
OutputAttribute_Typed<bool> attribute = mesh_component.attribute_try_get_for_output_only<bool>(
|
||||
attribute_outputs.bottom_id.get(), face ? ATTR_DOMAIN_FACE : ATTR_DOMAIN_POINT);
|
||||
MutableSpan<bool> selection = attribute.as_span();
|
||||
|
||||
if (config.bottom_is_point) {
|
||||
selection[config.last_vert] = true;
|
||||
}
|
||||
else {
|
||||
selection
|
||||
.slice(config.bottom_faces_start,
|
||||
face ? config.bottom_faces_len : config.circle_segments)
|
||||
.fill(true);
|
||||
}
|
||||
attribute.save();
|
||||
}
|
||||
|
||||
/* Populate "Side" selection output. */
|
||||
if (attribute_outputs.side_id) {
|
||||
OutputAttribute_Typed<bool> attribute = mesh_component.attribute_try_get_for_output_only<bool>(
|
||||
attribute_outputs.side_id.get(), ATTR_DOMAIN_FACE);
|
||||
MutableSpan<bool> selection = attribute.as_span();
|
||||
|
||||
selection.slice(config.side_faces_start, config.side_faces_len).fill(true);
|
||||
attribute.save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the top is the cone tip or has a fill, it is unwrapped into a circle in the
|
||||
* lower left quadrant of the UV.
|
||||
|
@ -685,7 +756,8 @@ Mesh *create_cylinder_or_cone_mesh(const float radius_top,
|
|||
const int circle_segments,
|
||||
const int side_segments,
|
||||
const int fill_segments,
|
||||
const GeometryNodeMeshCircleFillType fill_type)
|
||||
const GeometryNodeMeshCircleFillType fill_type,
|
||||
ConeAttributeOutputs &attribute_outputs)
|
||||
{
|
||||
const ConeConfig config(
|
||||
radius_top, radius_bottom, depth, circle_segments, side_segments, fill_segments, fill_type);
|
||||
|
@ -703,7 +775,7 @@ Mesh *create_cylinder_or_cone_mesh(const float radius_top,
|
|||
}
|
||||
|
||||
Mesh *mesh = BKE_mesh_new_nomain(
|
||||
config.tot_verts, config.tot_edges, 0, config.get_tot_corners(), config.get_tot_faces());
|
||||
config.tot_verts, config.tot_edges, 0, config.tot_corners, config.tot_faces);
|
||||
BKE_id_material_eval_ensure_default_slot(&mesh->id);
|
||||
|
||||
MutableSpan<MVert> verts{mesh->mvert, mesh->totvert};
|
||||
|
@ -715,6 +787,7 @@ Mesh *create_cylinder_or_cone_mesh(const float radius_top,
|
|||
calculate_cone_edges(edges, config);
|
||||
calculate_cone_faces(loops, polys, config);
|
||||
calculate_cone_uvs(mesh, config);
|
||||
calculate_selection_outputs(mesh, config, attribute_outputs);
|
||||
|
||||
BKE_mesh_normals_tag_dirty(mesh);
|
||||
|
||||
|
@ -728,38 +801,76 @@ static void geo_node_mesh_primitive_cone_exec(GeoNodeExecParams params)
|
|||
const GeometryNodeMeshCircleFillType fill_type = (const GeometryNodeMeshCircleFillType)
|
||||
storage.fill_type;
|
||||
|
||||
auto return_default = [&]() {
|
||||
params.set_output("Top", fn::make_constant_field<bool>(false));
|
||||
params.set_output("Bottom", fn::make_constant_field<bool>(false));
|
||||
params.set_output("Side", fn::make_constant_field<bool>(false));
|
||||
params.set_output("Mesh", GeometrySet());
|
||||
};
|
||||
|
||||
const int circle_segments = params.extract_input<int>("Vertices");
|
||||
if (circle_segments < 3) {
|
||||
params.error_message_add(NodeWarningType::Info, TIP_("Vertices must be at least 3"));
|
||||
params.set_output("Mesh", GeometrySet());
|
||||
return;
|
||||
return return_default();
|
||||
}
|
||||
|
||||
const int side_segments = params.extract_input<int>("Side Segments");
|
||||
if (side_segments < 1) {
|
||||
params.error_message_add(NodeWarningType::Info, TIP_("Side Segments must be at least 1"));
|
||||
params.set_output("Mesh", GeometrySet());
|
||||
return;
|
||||
return return_default();
|
||||
}
|
||||
|
||||
const bool no_fill = fill_type == GEO_NODE_MESH_CIRCLE_FILL_NONE;
|
||||
const int fill_segments = no_fill ? 1 : params.extract_input<int>("Fill Segments");
|
||||
if (fill_segments < 1) {
|
||||
params.error_message_add(NodeWarningType::Info, TIP_("Fill Segments must be at least 1"));
|
||||
params.set_output("Mesh", GeometrySet());
|
||||
return;
|
||||
return return_default();
|
||||
}
|
||||
|
||||
const float radius_top = params.extract_input<float>("Radius Top");
|
||||
const float radius_bottom = params.extract_input<float>("Radius Bottom");
|
||||
const float depth = params.extract_input<float>("Depth");
|
||||
|
||||
Mesh *mesh = create_cylinder_or_cone_mesh(
|
||||
radius_top, radius_bottom, depth, circle_segments, side_segments, fill_segments, fill_type);
|
||||
ConeAttributeOutputs attribute_outputs;
|
||||
if (params.output_is_required("Top")) {
|
||||
attribute_outputs.top_id = StrongAnonymousAttributeID("top_selection");
|
||||
}
|
||||
if (params.output_is_required("Bottom")) {
|
||||
attribute_outputs.bottom_id = StrongAnonymousAttributeID("bottom_selection");
|
||||
}
|
||||
if (params.output_is_required("Side")) {
|
||||
attribute_outputs.side_id = StrongAnonymousAttributeID("side_selection");
|
||||
}
|
||||
|
||||
Mesh *mesh = create_cylinder_or_cone_mesh(radius_top,
|
||||
radius_bottom,
|
||||
depth,
|
||||
circle_segments,
|
||||
side_segments,
|
||||
fill_segments,
|
||||
fill_type,
|
||||
attribute_outputs);
|
||||
|
||||
/* Transform the mesh so that the base of the cone is at the origin. */
|
||||
BKE_mesh_translate(mesh, float3(0.0f, 0.0f, depth * 0.5f), false);
|
||||
|
||||
if (attribute_outputs.top_id) {
|
||||
params.set_output("Top",
|
||||
AnonymousAttributeFieldInput::Create<bool>(
|
||||
std::move(attribute_outputs.top_id), params.attribute_producer_name()));
|
||||
}
|
||||
if (attribute_outputs.bottom_id) {
|
||||
params.set_output(
|
||||
"Bottom",
|
||||
AnonymousAttributeFieldInput::Create<bool>(std::move(attribute_outputs.bottom_id),
|
||||
params.attribute_producer_name()));
|
||||
}
|
||||
if (attribute_outputs.side_id) {
|
||||
params.set_output("Side",
|
||||
AnonymousAttributeFieldInput::Create<bool>(
|
||||
std::move(attribute_outputs.side_id), params.attribute_producer_name()));
|
||||
}
|
||||
|
||||
params.set_output("Mesh", GeometrySet::create_with_mesh(mesh));
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,9 @@ static void geo_node_mesh_primitive_cylinder_declare(NodeDeclarationBuilder &b)
|
|||
.subtype(PROP_DISTANCE)
|
||||
.description(N_("The height of the cylinder"));
|
||||
b.add_output<decl::Geometry>(N_("Mesh"));
|
||||
b.add_output<decl::Bool>(N_("Top")).field_source();
|
||||
b.add_output<decl::Bool>(N_("Bottom")).field_source();
|
||||
b.add_output<decl::Bool>(N_("Side")).field_source();
|
||||
}
|
||||
|
||||
static void geo_node_mesh_primitive_cylinder_layout(uiLayout *layout,
|
||||
|
@ -97,33 +100,71 @@ static void geo_node_mesh_primitive_cylinder_exec(GeoNodeExecParams params)
|
|||
const GeometryNodeMeshCircleFillType fill_type = (const GeometryNodeMeshCircleFillType)
|
||||
storage.fill_type;
|
||||
|
||||
auto return_default = [&]() {
|
||||
params.set_output("Top", fn::make_constant_field<bool>(false));
|
||||
params.set_output("Bottom", fn::make_constant_field<bool>(false));
|
||||
params.set_output("Side", fn::make_constant_field<bool>(false));
|
||||
params.set_output("Mesh", GeometrySet());
|
||||
};
|
||||
|
||||
const float radius = params.extract_input<float>("Radius");
|
||||
const float depth = params.extract_input<float>("Depth");
|
||||
const int circle_segments = params.extract_input<int>("Vertices");
|
||||
if (circle_segments < 3) {
|
||||
params.error_message_add(NodeWarningType::Info, TIP_("Vertices must be at least 3"));
|
||||
params.set_output("Mesh", GeometrySet());
|
||||
return;
|
||||
return return_default();
|
||||
}
|
||||
|
||||
const int side_segments = params.extract_input<int>("Side Segments");
|
||||
if (side_segments < 1) {
|
||||
params.error_message_add(NodeWarningType::Info, TIP_("Side Segments must be at least 1"));
|
||||
params.set_output("Mesh", GeometrySet());
|
||||
return;
|
||||
return return_default();
|
||||
}
|
||||
|
||||
const bool no_fill = fill_type == GEO_NODE_MESH_CIRCLE_FILL_NONE;
|
||||
const int fill_segments = no_fill ? 1 : params.extract_input<int>("Fill Segments");
|
||||
if (fill_segments < 1) {
|
||||
params.error_message_add(NodeWarningType::Info, TIP_("Fill Segments must be at least 1"));
|
||||
params.set_output("Mesh", GeometrySet());
|
||||
return;
|
||||
return return_default();
|
||||
}
|
||||
|
||||
ConeAttributeOutputs attribute_outputs;
|
||||
if (params.output_is_required("Top")) {
|
||||
attribute_outputs.top_id = StrongAnonymousAttributeID("top_selection");
|
||||
}
|
||||
if (params.output_is_required("Bottom")) {
|
||||
attribute_outputs.bottom_id = StrongAnonymousAttributeID("bottom_selection");
|
||||
}
|
||||
if (params.output_is_required("Side")) {
|
||||
attribute_outputs.side_id = StrongAnonymousAttributeID("side_selection");
|
||||
}
|
||||
|
||||
/* The cylinder is a special case of the cone mesh where the top and bottom radius are equal. */
|
||||
Mesh *mesh = create_cylinder_or_cone_mesh(
|
||||
radius, radius, depth, circle_segments, side_segments, fill_segments, fill_type);
|
||||
Mesh *mesh = create_cylinder_or_cone_mesh(radius,
|
||||
radius,
|
||||
depth,
|
||||
circle_segments,
|
||||
side_segments,
|
||||
fill_segments,
|
||||
fill_type,
|
||||
attribute_outputs);
|
||||
|
||||
if (attribute_outputs.top_id) {
|
||||
params.set_output("Top",
|
||||
AnonymousAttributeFieldInput::Create<bool>(
|
||||
std::move(attribute_outputs.top_id), params.attribute_producer_name()));
|
||||
}
|
||||
if (attribute_outputs.bottom_id) {
|
||||
params.set_output(
|
||||
"Bottom",
|
||||
AnonymousAttributeFieldInput::Create<bool>(std::move(attribute_outputs.bottom_id),
|
||||
params.attribute_producer_name()));
|
||||
}
|
||||
if (attribute_outputs.side_id) {
|
||||
params.set_output("Side",
|
||||
AnonymousAttributeFieldInput::Create<bool>(
|
||||
std::move(attribute_outputs.side_id), params.attribute_producer_name()));
|
||||
}
|
||||
|
||||
params.set_output("Mesh", GeometrySet::create_with_mesh(mesh));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue