Welcome to mirror list, hosted at ThFree Co, Russian Federation.

node_geo_mesh_primitive_cone.cc « nodes « geometry « nodes « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4c1521aa6f1a2af31a74d31c630916c3a96825b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"

#include "BKE_material.h"
#include "BKE_mesh.h"

#include "UI_interface.h"
#include "UI_resources.h"

#include "node_geometry_util.hh"

static bNodeSocketTemplate geo_node_mesh_primitive_cone_in[] = {
    {SOCK_INT, N_("Vertices"), 32, 0.0f, 0.0f, 0.0f, 3, 4096},
    {SOCK_FLOAT, N_("Radius Top"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, FLT_MAX, PROP_DISTANCE},
    {SOCK_FLOAT, N_("Radius Bottom"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, FLT_MAX, PROP_DISTANCE},
    {SOCK_FLOAT, N_("Depth"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, FLT_MAX, PROP_DISTANCE},
    {-1, ""},
};

static bNodeSocketTemplate geo_node_mesh_primitive_cone_out[] = {
    {SOCK_GEOMETRY, N_("Geometry")},
    {-1, ""},
};

static void geo_node_mesh_primitive_cone_layout(uiLayout *layout,
                                                bContext *UNUSED(C),
                                                PointerRNA *ptr)
{
  uiLayoutSetPropSep(layout, true);
  uiLayoutSetPropDecorate(layout, false);
  uiItemR(layout, ptr, "fill_type", 0, nullptr, ICON_NONE);
}

static void geo_node_mesh_primitive_cone_init(bNodeTree *UNUSED(ntree), bNode *node)
{
  NodeGeometryMeshCone *node_storage = (NodeGeometryMeshCone *)MEM_callocN(
      sizeof(NodeGeometryMeshCone), __func__);

  node_storage->fill_type = GEO_NODE_MESH_CIRCLE_FILL_NGON;

  node->storage = node_storage;
}

namespace blender::nodes {

static int vert_total(const GeometryNodeMeshCircleFillType fill_type,
                      const int verts_num,
                      const bool top_is_point,
                      const bool bottom_is_point)
{
  int vert_total = 0;
  if (!top_is_point) {
    vert_total += verts_num;
    if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN) {
      vert_total++;
    }
  }
  else {
    vert_total++;
  }
  if (!bottom_is_point) {
    vert_total += verts_num;
    if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN) {
      vert_total++;
    }
  }
  else {
    vert_total++;
  }

  return vert_total;
}

static int edge_total(const GeometryNodeMeshCircleFillType fill_type,
                      const int verts_num,
                      const bool top_is_point,
                      const bool bottom_is_point)
{
  if (top_is_point && bottom_is_point) {
    return 1;
  }

  int edge_total = 0;
  if (!top_is_point) {
    edge_total += verts_num;
    if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN) {
      edge_total += verts_num;
    }
  }

  edge_total += verts_num;

  if (!bottom_is_point) {
    edge_total += verts_num;
    if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN) {
      edge_total += verts_num;
    }
  }

  return edge_total;
}

static int corner_total(const GeometryNodeMeshCircleFillType fill_type,
                        const int verts_num,
                        const bool top_is_point,
                        const bool bottom_is_point)
{
  if (top_is_point && bottom_is_point) {
    return 0;
  }

  int corner_total = 0;
  if (!top_is_point) {
    if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_NGON) {
      corner_total += verts_num;
    }
    else if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN) {
      corner_total += verts_num * 3;
    }
  }

  if (!top_is_point && !bottom_is_point) {
    corner_total += verts_num * 4;
  }
  else {
    corner_total += verts_num * 3;
  }

  if (!bottom_is_point) {
    if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_NGON) {
      corner_total += verts_num;
    }
    else if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN) {
      corner_total += verts_num * 3;
    }
  }

  return corner_total;
}

static int face_total(const GeometryNodeMeshCircleFillType fill_type,
                      const int verts_num,
                      const bool top_is_point,
                      const bool bottom_is_point)
{
  if (top_is_point && bottom_is_point) {
    return 0;
  }

  int face_total = 0;
  if (!top_is_point) {
    if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_NGON) {
      face_total++;
    }
    else if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN) {
      face_total += verts_num;
    }
  }

  face_total += verts_num;

  if (!bottom_is_point) {
    if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_NGON) {
      face_total++;
    }
    else if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN) {
      face_total += verts_num;
    }
  }

  return face_total;
}

static void calculate_uvs(Mesh *mesh,
                          const bool top_is_point,
                          const bool bottom_is_point,
                          const int verts_num,
                          const GeometryNodeMeshCircleFillType fill_type)
{
  MeshComponent mesh_component;
  mesh_component.replace(mesh, GeometryOwnershipType::Editable);
  OutputAttribute_Typed<float2> uv_attribute =
      mesh_component.attribute_try_get_for_output_only<float2>("uv_map", ATTR_DOMAIN_CORNER);
  MutableSpan<float2> uvs = uv_attribute.as_span();

  Array<float2> circle(verts_num);
  float angle = 0.0f;
  const float angle_delta = 2.0f * M_PI / static_cast<float>(verts_num);
  for (const int i : IndexRange(verts_num)) {
    circle[i].x = std::cos(angle) * 0.225f + 0.25f;
    circle[i].y = std::sin(angle) * 0.225f + 0.25f;
    angle += angle_delta;
  }

  int loop_index = 0;
  if (!top_is_point) {
    if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_NGON) {
      for (const int i : IndexRange(verts_num)) {
        uvs[loop_index++] = circle[i];
      }
    }
    else if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN) {
      for (const int i : IndexRange(verts_num)) {
        uvs[loop_index++] = circle[i];
        uvs[loop_index++] = circle[(i + 1) % verts_num];
        uvs[loop_index++] = float2(0.25f, 0.25f);
      }
    }
  }

  /* Create side corners and faces. */
  if (!top_is_point && !bottom_is_point) {
    const float bottom = (fill_type == GEO_NODE_MESH_CIRCLE_FILL_NONE) ? 0.0f : 0.5f;
    /* Quads connect the top and bottom. */
    for (const int i : IndexRange(verts_num)) {
      const float vert = static_cast<float>(i);
      uvs[loop_index++] = float2(vert / verts_num, bottom);
      uvs[loop_index++] = float2(vert / verts_num, 1.0f);
      uvs[loop_index++] = float2((vert + 1.0f) / verts_num, 1.0f);
      uvs[loop_index++] = float2((vert + 1.0f) / verts_num, bottom);
    }
  }
  else {
    /* Triangles connect the top and bottom section. */
    if (!top_is_point) {
      for (const int i : IndexRange(verts_num)) {
        uvs[loop_index++] = circle[i] + float2(0.5f, 0.0f);
        uvs[loop_index++] = float2(0.75f, 0.25f);
        uvs[loop_index++] = circle[(i + 1) % verts_num] + float2(0.5f, 0.0f);
      }
    }
    else {
      BLI_assert(!bottom_is_point);
      for (const int i : IndexRange(verts_num)) {
        uvs[loop_index++] = circle[i];
        uvs[loop_index++] = circle[(i + 1) % verts_num];
        uvs[loop_index++] = float2(0.25f, 0.25f);
      }
    }
  }

  /* Create bottom corners and faces. */
  if (!bottom_is_point) {
    if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_NGON) {
      for (const int i : IndexRange(verts_num)) {
        /* Go backwards because of reversed face normal. */
        uvs[loop_index++] = circle[verts_num - 1 - i] + float2(0.5f, 0.0f);
      }
    }
    else if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN) {
      for (const int i : IndexRange(verts_num)) {
        uvs[loop_index++] = circle[i] + float2(0.5f, 0.0f);
        uvs[loop_index++] = float2(0.75f, 0.25f);
        uvs[loop_index++] = circle[(i + 1) % verts_num] + float2(0.5f, 0.0f);
      }
    }
  }

  uv_attribute.save();
}

Mesh *create_cylinder_or_cone_mesh(const float radius_top,
                                   const float radius_bottom,
                                   const float depth,
                                   const int verts_num,
                                   const GeometryNodeMeshCircleFillType fill_type)
{
  const bool top_is_point = radius_top == 0.0f;
  const bool bottom_is_point = radius_bottom == 0.0f;
  const float height = depth * 0.5f;
  /* Handle the case of a line / single point before everything else to avoid
   * the need to check for it later. */
  if (top_is_point && bottom_is_point) {
    const bool single_vertex = height == 0.0f;
    Mesh *mesh = BKE_mesh_new_nomain(single_vertex ? 1 : 2, single_vertex ? 0 : 1, 0, 0, 0);
    copy_v3_v3(mesh->mvert[0].co, float3(0.0f, 0.0f, height));
    if (single_vertex) {
      const short up[3] = {0, 0, SHRT_MAX};
      copy_v3_v3_short(mesh->mvert[0].no, up);
      return mesh;
    }
    copy_v3_v3(mesh->mvert[1].co, float3(0.0f, 0.0f, -height));
    mesh->medge[0].v1 = 0;
    mesh->medge[0].v2 = 1;
    mesh->medge[0].flag |= ME_LOOSEEDGE;
    BKE_mesh_calc_normals(mesh);
    return mesh;
  }

  Mesh *mesh = BKE_mesh_new_nomain(
      vert_total(fill_type, verts_num, top_is_point, bottom_is_point),
      edge_total(fill_type, verts_num, top_is_point, bottom_is_point),
      0,
      corner_total(fill_type, verts_num, top_is_point, bottom_is_point),
      face_total(fill_type, verts_num, top_is_point, bottom_is_point));
  MutableSpan<MVert> verts{mesh->mvert, mesh->totvert};
  MutableSpan<MLoop> loops{mesh->mloop, mesh->totloop};
  MutableSpan<MEdge> edges{mesh->medge, mesh->totedge};
  MutableSpan<MPoly> polys{mesh->mpoly, mesh->totpoly};

  /* Calculate vertex positions. */
  const int top_verts_start = 0;
  const int bottom_verts_start = top_verts_start + (!top_is_point ? verts_num : 1);
  float angle = 0.0f;
  const float angle_delta = 2.0f * M_PI / static_cast<float>(verts_num);
  for (const int i : IndexRange(verts_num)) {
    const float x = std::cos(angle);
    const float y = std::sin(angle);
    if (!top_is_point) {
      copy_v3_v3(verts[top_verts_start + i].co, float3(x * radius_top, y * radius_top, height));
    }
    if (!bottom_is_point) {
      copy_v3_v3(verts[bottom_verts_start + i].co,
                 float3(x * radius_bottom, y * radius_bottom, -height));
    }
    angle += angle_delta;
  }
  if (top_is_point) {
    copy_v3_v3(verts[top_verts_start].co, float3(0.0f, 0.0f, height));
  }
  if (bottom_is_point) {
    copy_v3_v3(verts[bottom_verts_start].co, float3(0.0f, 0.0f, -height));
  }

  /* Add center vertices for the triangle fans at the end. */
  const int top_center_vert_index = bottom_verts_start + (bottom_is_point ? 1 : verts_num);
  const int bottom_center_vert_index = top_center_vert_index + (top_is_point ? 0 : 1);
  if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN) {
    if (!top_is_point) {
      copy_v3_v3(verts[top_center_vert_index].co, float3(0.0f, 0.0f, height));
    }
    if (!bottom_is_point) {
      copy_v3_v3(verts[bottom_center_vert_index].co, float3(0.0f, 0.0f, -height));
    }
  }

  /* Create top edges. */
  const int top_edges_start = 0;
  const int top_fan_edges_start = (!top_is_point &&
                                   fill_type == GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN) ?
                                      top_edges_start + verts_num :
                                      top_edges_start;
  if (!top_is_point) {
    for (const int i : IndexRange(verts_num)) {
      MEdge &edge = edges[top_edges_start + i];
      edge.v1 = top_verts_start + i;
      edge.v2 = top_verts_start + (i + 1) % verts_num;
      edge.flag = ME_EDGEDRAW | ME_EDGERENDER;
    }
    if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN) {
      for (const int i : IndexRange(verts_num)) {
        MEdge &edge = edges[top_fan_edges_start + i];
        edge.v1 = top_center_vert_index;
        edge.v2 = top_verts_start + i;
        edge.flag = ME_EDGEDRAW | ME_EDGERENDER;
      }
    }
  }

  /* Create connecting edges. */
  const int connecting_edges_start = top_fan_edges_start + (!top_is_point ? verts_num : 0);
  for (const int i : IndexRange(verts_num)) {
    MEdge &edge = edges[connecting_edges_start + i];
    edge.v1 = top_verts_start + (!top_is_point ? i : 0);
    edge.v2 = bottom_verts_start + (!bottom_is_point ? i : 0);
    edge.flag = ME_EDGEDRAW | ME_EDGERENDER;
  }

  /* Create bottom edges. */
  const int bottom_edges_start = connecting_edges_start + verts_num;
  const int bottom_fan_edges_start = (!bottom_is_point &&
                                      fill_type == GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN) ?
                                         bottom_edges_start + verts_num :
                                         bottom_edges_start;
  if (!bottom_is_point) {
    for (const int i : IndexRange(verts_num)) {
      MEdge &edge = edges[bottom_edges_start + i];
      edge.v1 = bottom_verts_start + i;
      edge.v2 = bottom_verts_start + (i + 1) % verts_num;
      edge.flag = ME_EDGEDRAW | ME_EDGERENDER;
    }
    if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN) {
      for (const int i : IndexRange(verts_num)) {
        MEdge &edge = edges[bottom_fan_edges_start + i];
        edge.v1 = bottom_center_vert_index;
        edge.v2 = bottom_verts_start + i;
        edge.flag = ME_EDGEDRAW | ME_EDGERENDER;
      }
    }
  }

  /* Create top corners and faces. */
  int loop_index = 0;
  int poly_index = 0;
  if (!top_is_point) {
    if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_NGON) {
      MPoly &poly = polys[poly_index++];
      poly.loopstart = loop_index;
      poly.totloop = verts_num;

      for (const int i : IndexRange(verts_num)) {
        MLoop &loop = loops[loop_index++];
        loop.v = top_verts_start + i;
        loop.e = top_edges_start + i;
      }
    }
    else if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN) {
      for (const int i : IndexRange(verts_num)) {
        MPoly &poly = polys[poly_index++];
        poly.loopstart = loop_index;
        poly.totloop = 3;

        MLoop &loop_a = loops[loop_index++];
        loop_a.v = top_verts_start + i;
        loop_a.e = top_edges_start + i;
        MLoop &loop_b = loops[loop_index++];
        loop_b.v = top_verts_start + (i + 1) % verts_num;
        loop_b.e = top_fan_edges_start + (i + 1) % verts_num;
        MLoop &loop_c = loops[loop_index++];
        loop_c.v = top_center_vert_index;
        loop_c.e = top_fan_edges_start + i;
      }
    }
  }

  /* Create side corners and faces. */
  if (!top_is_point && !bottom_is_point) {
    /* Quads connect the top and bottom. */
    for (const int i : IndexRange(verts_num)) {
      MPoly &poly = polys[poly_index++];
      poly.loopstart = loop_index;
      poly.totloop = 4;

      MLoop &loop_a = loops[loop_index++];
      loop_a.v = top_verts_start + i;
      loop_a.e = connecting_edges_start + i;
      MLoop &loop_b = loops[loop_index++];
      loop_b.v = bottom_verts_start + i;
      loop_b.e = bottom_edges_start + i;
      MLoop &loop_c = loops[loop_index++];
      loop_c.v = bottom_verts_start + (i + 1) % verts_num;
      loop_c.e = connecting_edges_start + (i + 1) % verts_num;
      MLoop &loop_d = loops[loop_index++];
      loop_d.v = top_verts_start + (i + 1) % verts_num;
      loop_d.e = top_edges_start + i;
    }
  }
  else {
    /* Triangles connect the top and bottom section. */
    if (!top_is_point) {
      for (const int i : IndexRange(verts_num)) {
        MPoly &poly = polys[poly_index++];
        poly.loopstart = loop_index;
        poly.totloop = 3;

        MLoop &loop_a = loops[loop_index++];
        loop_a.v = top_verts_start + i;
        loop_a.e = connecting_edges_start + i;
        MLoop &loop_b = loops[loop_index++];
        loop_b.v = bottom_verts_start;
        loop_b.e = connecting_edges_start + (i + 1) % verts_num;
        MLoop &loop_c = loops[loop_index++];
        loop_c.v = top_verts_start + (i + 1) % verts_num;
        loop_c.e = top_edges_start + i;
      }
    }
    else {
      BLI_assert(!bottom_is_point);
      for (const int i : IndexRange(verts_num)) {
        MPoly &poly = polys[poly_index++];
        poly.loopstart = loop_index;
        poly.totloop = 3;

        MLoop &loop_a = loops[loop_index++];
        loop_a.v = bottom_verts_start + i;
        loop_a.e = bottom_edges_start + i;
        MLoop &loop_b = loops[loop_index++];
        loop_b.v = bottom_verts_start + (i + 1) % verts_num;
        loop_b.e = connecting_edges_start + (i + 1) % verts_num;
        MLoop &loop_c = loops[loop_index++];
        loop_c.v = top_verts_start;
        loop_c.e = connecting_edges_start + i;
      }
    }
  }

  /* Create bottom corners and faces. */
  if (!bottom_is_point) {
    if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_NGON) {
      MPoly &poly = polys[poly_index++];
      poly.loopstart = loop_index;
      poly.totloop = verts_num;

      for (const int i : IndexRange(verts_num)) {
        /* Go backwards to reverse surface normal. */
        MLoop &loop = loops[loop_index++];
        loop.v = bottom_verts_start + verts_num - 1 - i;
        loop.e = bottom_edges_start + verts_num - 1 - (i + 1) % verts_num;
      }
    }
    else if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN) {
      for (const int i : IndexRange(verts_num)) {
        MPoly &poly = polys[poly_index++];
        poly.loopstart = loop_index;
        poly.totloop = 3;

        MLoop &loop_a = loops[loop_index++];
        loop_a.v = bottom_verts_start + i;
        loop_a.e = bottom_fan_edges_start + i;
        MLoop &loop_b = loops[loop_index++];
        loop_b.v = bottom_center_vert_index;
        loop_b.e = bottom_fan_edges_start + (i + 1) % verts_num;
        MLoop &loop_c = loops[loop_index++];
        loop_c.v = bottom_verts_start + (i + 1) % verts_num;
        loop_c.e = bottom_edges_start + i;
      }
    }
  }

  BKE_mesh_calc_normals(mesh);

  calculate_uvs(mesh, top_is_point, bottom_is_point, verts_num, fill_type);

  BLI_assert(BKE_mesh_is_valid(mesh));

  return mesh;
}

static void geo_node_mesh_primitive_cone_exec(GeoNodeExecParams params)
{
  const bNode &node = params.node();
  const NodeGeometryMeshCone &storage = *(const NodeGeometryMeshCone *)node.storage;

  const GeometryNodeMeshCircleFillType fill_type = (const GeometryNodeMeshCircleFillType)
                                                       storage.fill_type;

  const int verts_num = params.extract_input<int>("Vertices");
  if (verts_num < 3) {
    params.set_output("Geometry", GeometrySet());
    return;
  }

  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, verts_num, fill_type);
  BKE_id_material_eval_ensure_default_slot(&mesh->id);

  /* 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);

  params.set_output("Geometry", GeometrySet::create_with_mesh(mesh));
}

}  // namespace blender::nodes

void register_node_type_geo_mesh_primitive_cone()
{
  static bNodeType ntype;

  geo_node_type_base(&ntype, GEO_NODE_MESH_PRIMITIVE_CONE, "Cone", NODE_CLASS_GEOMETRY, 0);
  node_type_socket_templates(
      &ntype, geo_node_mesh_primitive_cone_in, geo_node_mesh_primitive_cone_out);
  node_type_init(&ntype, geo_node_mesh_primitive_cone_init);
  node_type_storage(
      &ntype, "NodeGeometryMeshCone", node_free_standard_storage, node_copy_standard_storage);
  ntype.geometry_node_execute = blender::nodes::geo_node_mesh_primitive_cone_exec;
  ntype.draw_buttons = geo_node_mesh_primitive_cone_layout;
  nodeRegisterType(&ntype);
}