82 this->top_is_point = this->radius_top == 0.0f;
83 this->bottom_is_point = this->radius_bottom == 0.0f;
85 this->bottom_has_center_vert = this->bottom_is_point ||
88 this->tot_quad_rings = this->calculate_total_quad_rings();
89 this->tot_edge_rings = this->calculate_total_edge_rings();
90 this->tot_verts = this->calculate_total_verts();
91 this->tot_edges = this->calculate_total_edges();
92 this->tot_corners = this->calculate_total_corners();
95 this->first_ring_verts_start = this->top_has_center_vert ? 1 :
first_vert;
96 this->last_vert = this->tot_verts - 1;
97 this->last_ring_verts_start = this->last_vert - this->circle_segments;
99 this->first_ring_edges_start = this->top_has_center_vert ? this->circle_segments : 0;
100 this->last_ring_edges_start = this->first_ring_edges_start +
101 this->tot_quad_rings * this->circle_segments * 2;
102 this->last_fan_edges_start = this->tot_edges - this->circle_segments;
103 this->last_edge = this->tot_edges - 1;
105 this->top_faces_start = 0;
106 if (!this->top_is_point) {
108 this->top_faces_len += this->top_has_center_vert ?
circle_segments : 0;
112 this->top_faces_len = 0;
115 this->side_faces_start = this->top_faces_len;
116 if (this->top_is_point && this->bottom_is_point) {
117 this->side_faces_len = 0;
123 if (!this->bottom_is_point) {
125 this->bottom_faces_len += this->bottom_has_center_vert ?
circle_segments : 0;
129 this->bottom_faces_len = 0;
131 this->bottom_faces_start = this->side_faces_start + this->side_faces_len;
133 this->tot_faces = this->top_faces_len + this->side_faces_len + this->bottom_faces_len;
137 int calculate_total_quad_rings();
138 int calculate_total_edge_rings();
139 int calculate_total_verts();
140 int calculate_total_edges();
141 int calculate_total_corners();
144int ConeConfig::calculate_total_quad_rings()
165int ConeConfig::calculate_total_edge_rings()
186int ConeConfig::calculate_total_verts()
215int ConeConfig::calculate_total_edges()
235int ConeConfig::calculate_total_corners()
241 int corner_total = 0;
268 circle[i].x = std::cos(
angle);
269 circle[i].y = std::sin(
angle);
270 angle += angle_delta;
277 positions[vert_index++] = {0.0f, 0.0f, config.
height};
284 const float top_fill_radius = top_fill_radius_delta * (i + 1);
286 const float x = circle[j].x * top_fill_radius;
287 const float y = circle[j].y * top_fill_radius;
288 positions[vert_index++] = {
x,
y, config.
height};
298 const float ring_radius = config.
radius_top + (side_radius_delta * (i + 1));
299 const float ring_height = config.
height - (height_delta * (i + 1));
301 const float x = circle[j].x * ring_radius;
302 const float y = circle[j].y * ring_radius;
303 positions[vert_index++] = {
x,
y, ring_height};
311 const float bottom_fill_radius = config.
radius_bottom - (i * bottom_fill_radius_delta);
313 const float x = circle[j].x * bottom_fill_radius;
314 const float y = circle[j].y * bottom_fill_radius;
315 positions[vert_index++] = {
x,
y, -config.
height};
322 positions[vert_index++] = {0.0f, 0.0f, -config.
height};
333 int2 &edge = edges[edge_index++];
342 const int next_ring_vert_start = this_ring_vert_start + config.
circle_segments;
345 int2 &edge = edges[edge_index++];
346 edge[0] = this_ring_vert_start + j;
355 int2 &edge = edges[edge_index++];
356 edge[0] = this_ring_vert_start + j;
357 edge[1] = next_ring_vert_start + j;
364 int2 &edge = edges[edge_index++];
376 int rings_face_start = 0;
377 int rings_loop_start = 0;
385 const int top_center_vert = 0;
386 const int top_fan_edges_start = 0;
389 const int loop_start = i * 3;
396 corner_edges[loop_start + 1] = top_fan_edges_start + ((i + 1) % config.
circle_segments);
398 corner_verts[loop_start + 2] = top_center_vert;
399 corner_edges[loop_start + 2] = top_fan_edges_start + i;
403 rings_face_start = 1;
414 face_sizes.
slice(rings_face_start, ring_faces_num).
fill(4);
416 const int this_ring_loop_start = rings_loop_start + i * config.
circle_segments * 4;
418 const int next_ring_vert_start = this_ring_vert_start + config.
circle_segments;
422 const int next_ring_edges_start = this_ring_edges_start + (2 * config.
circle_segments);
423 const int ring_connections_start = this_ring_edges_start + config.
circle_segments;
426 const int loop_start = this_ring_loop_start + j * 4;
428 corner_verts[loop_start + 0] = this_ring_vert_start + j;
429 corner_edges[loop_start + 0] = ring_connections_start + j;
431 corner_verts[loop_start + 1] = next_ring_vert_start + j;
432 corner_edges[loop_start + 1] = next_ring_edges_start + j;
434 corner_verts[loop_start + 2] = next_ring_vert_start + ((j + 1) % config.
circle_segments);
435 corner_edges[loop_start + 2] = ring_connections_start + ((j + 1) % config.
circle_segments);
437 corner_verts[loop_start + 3] = this_ring_vert_start + ((j + 1) % config.
circle_segments);
438 corner_edges[loop_start + 3] = this_ring_edges_start + j;
442 const int bottom_face_start = rings_face_start + ring_faces_num;
443 const int bottom_loop_start = rings_loop_start + ring_faces_num * 4;
450 const int loop_start = bottom_loop_start + i * 3;
455 corner_verts[loop_start + 1] = config.
last_vert;
469 corner_verts[bottom_loop_start + i] = config.
last_vert - i;
480 if (attribute_outputs.
top_id) {
513 if (attribute_outputs.
side_id) {
542 circle[i].x = std::cos(
angle) * 0.225f;
543 circle[i].y = std::sin(
angle) * 0.225f;
544 angle += angle_delta;
551 const float2 center_left(0.25f, 0.25f);
560 uvs[corner++] = radius_factor_delta * circle[i] + center_left;
561 uvs[corner++] = radius_factor_delta * circle[(i + 1) % config.
circle_segments] +
563 uvs[corner++] = center_left;
569 uvs[corner++] = radius_factor_delta * circle[i] + center_left;
573 for (
const int i :
IndexRange(1, left_circle_segment_count - 1)) {
574 const float inner_radius_factor = i * radius_factor_delta;
575 const float outer_radius_factor = (i + 1) * radius_factor_delta;
577 uvs[corner++] = inner_radius_factor * circle[j] + center_left;
578 uvs[corner++] = outer_radius_factor * circle[j] + center_left;
579 uvs[corner++] = outer_radius_factor * circle[(j + 1) % config.
circle_segments] +
581 uvs[corner++] = inner_radius_factor * circle[(j + 1) % config.
circle_segments] +
591 const float y_delta = (1.0f - bottom) /
float(config.
side_segments);
595 uvs[corner++] =
float2(j * x_delta, i * y_delta + bottom);
596 uvs[corner++] =
float2(j * x_delta, (i + 1) * y_delta + bottom);
597 uvs[corner++] =
float2((j + 1) * x_delta, (i + 1) * y_delta + bottom);
598 uvs[corner++] =
float2((j + 1) * x_delta, i * y_delta + bottom);
605 const float2 center_right(0.75f, 0.25f);
613 for (
const int i :
IndexRange(right_circle_segment_count - 1)) {
614 const float outer_radius_factor = 1.0f - i * radius_factor_delta;
615 const float inner_radius_factor = 1.0f - (i + 1) * radius_factor_delta;
617 uvs[corner++] = outer_radius_factor * circle[j] + center_right;
618 uvs[corner++] = inner_radius_factor * circle[j] + center_right;
619 uvs[corner++] = inner_radius_factor * circle[(j + 1) % config.
circle_segments] +
621 uvs[corner++] = outer_radius_factor * circle[(j + 1) % config.
circle_segments] +
629 uvs[corner++] = radius_factor_delta * circle[i] + center_right;
630 uvs[corner++] = center_right;
631 uvs[corner++] = radius_factor_delta * circle[(i + 1) % config.
circle_segments] +
639 uvs[corner++] = radius_factor_delta * circle[config.
circle_segments - 1 - i] +
652 mesh->vert_positions_for_write().first() =
float3(0);
663 const float radius_bottom,
665 const int circle_segments,
666 const int side_segments,
667 const int fill_segments,
672 radius_top, radius_bottom, depth, circle_segments, side_segments, fill_segments, fill_type);
677 if (config.
height == 0.0f) {
682 const float3 delta(0.0f, 0.0f, z_delta);
705 mesh->tag_loose_verts_none();
706 mesh->tag_loose_edges_none();
707 mesh->tag_overlapping_none();
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
constexpr IndexRange()=default
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
constexpr MutableSpan drop_back(const int64_t n) const
constexpr void fill(const T &value) const
constexpr T & first() const
constexpr MutableSpan take_front(const int64_t n) const
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
GSpanAttributeWriter lookup_or_add_for_write_only_span(StringRef name, AttrDomain domain, AttrType data_type)
void fill_index_range(MutableSpan< T > span, const T start=0)
void mesh_smooth_set(Mesh &mesh, bool use_smooth, bool keep_sharp_edges=false)
static Bounds< float3 > calculate_bounds_cylinder(const ConeConfig &config)
static void calculate_cone_uvs(const ConeConfig &config, Mesh *mesh, const StringRef uv_map_id)
Mesh * create_cylinder_or_cone_mesh(float radius_top, float radius_bottom, float depth, int circle_segments, int side_segments, int fill_segments, ConeFillType fill_type, ConeAttributeOutputs &attribute_outputs)
static Mesh * create_vertex_mesh()
static void calculate_cone_faces(const ConeConfig &config, MutableSpan< int > corner_verts, MutableSpan< int > corner_edges, MutableSpan< int > face_sizes)
Bounds< float3 > calculate_bounds_radial_primitive(float radius_top, float radius_bottom, int segments, float height)
Mesh * create_line_mesh(float3 start, float3 delta, int count)
static void calculate_cone_edges(const ConeConfig &config, MutableSpan< int2 > edges)
static void calculate_selection_outputs(const ConeConfig &config, const ConeAttributeOutputs &attribute_outputs, bke::MutableAttributeAccessor attributes)
static void calculate_cone_verts(const ConeConfig &config, MutableSpan< float3 > positions)
OffsetIndices< int > accumulate_counts_to_offsets(MutableSpan< int > counts_to_offsets, int start_offset=0)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
Mesh * BKE_mesh_new_nomain(int verts_num, int edges_num, int faces_num, int corners_num)
VecBase< float, 3 > float3
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
MutableVArraySpan< T > span
std::optional< std::string > side_id
std::optional< std::string > top_id
std::optional< std::string > uv_map_id
std::optional< std::string > bottom_id
bool bottom_has_center_vert
int first_ring_verts_start
int last_ring_verts_start
int last_ring_edges_start
int first_ring_edges_start
ConeConfig(float radius_top, float radius_bottom, float depth, int circle_segments, int side_segments, int fill_segments, ConeFillType fill_type)