[Bf-blender-cvs] [a74a2677677] master: Cleanup: Move mesh primitive cube to the geometry module
Hans Goudey
noreply at git.blender.org
Tue May 10 10:21:43 CEST 2022
Commit: a74a267767706f57583ab1b3431f640570801784
Author: Hans Goudey
Date: Tue May 10 10:21:30 2022 +0200
Branches: master
https://developer.blender.org/rBa74a267767706f57583ab1b3431f640570801784
Cleanup: Move mesh primitive cube to the geometry module
This allows easy reuse elsewhere in Blender.
===================================================================
M source/blender/geometry/CMakeLists.txt
A source/blender/geometry/GEO_mesh_primitive_cuboid.hh
A source/blender/geometry/intern/mesh_primitive_cuboid.cc
M source/blender/nodes/geometry/node_geometry_util.hh
M source/blender/nodes/geometry/nodes/node_geo_bounding_box.cc
M source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc
===================================================================
diff --git a/source/blender/geometry/CMakeLists.txt b/source/blender/geometry/CMakeLists.txt
index 9dcacb13536..cf89426bfc4 100644
--- a/source/blender/geometry/CMakeLists.txt
+++ b/source/blender/geometry/CMakeLists.txt
@@ -7,6 +7,7 @@ set(INC
../blenlib
../blentranslation
../functions
+ ../guardedalloc
../makesdna
../makesrna
../../../intern/eigen
@@ -16,6 +17,7 @@ set(INC
set(SRC
intern/mesh_merge_by_distance.cc
+ intern/mesh_primitive_cuboid.cc
intern/mesh_to_curve_convert.cc
intern/point_merge_by_distance.cc
intern/realize_instances.cc
@@ -23,6 +25,7 @@ set(SRC
intern/uv_parametrizer.c
GEO_mesh_merge_by_distance.hh
+ GEO_mesh_primitive_cuboid.hh
GEO_mesh_to_curve.hh
GEO_point_merge_by_distance.hh
GEO_realize_instances.hh
diff --git a/source/blender/geometry/GEO_mesh_primitive_cuboid.hh b/source/blender/geometry/GEO_mesh_primitive_cuboid.hh
new file mode 100644
index 00000000000..d8f16065e2b
--- /dev/null
+++ b/source/blender/geometry/GEO_mesh_primitive_cuboid.hh
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#pragma once
+
+struct Mesh;
+struct float3;
+namespace blender {
+namespace bke {
+class AttributeIDRef;
+}
+} // namespace blender
+
+namespace blender::geometry {
+
+Mesh *create_cuboid_mesh(
+ const float3 &size, int verts_x, int verts_y, int verts_z, const bke::AttributeIDRef &uv_id);
+
+} // namespace blender::geometry
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc b/source/blender/geometry/intern/mesh_primitive_cuboid.cc
similarity index 77%
copy from source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc
copy to source/blender/geometry/intern/mesh_primitive_cuboid.cc
index 636ecb8ab41..e41516d0486 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc
+++ b/source/blender/geometry/intern/mesh_primitive_cuboid.cc
@@ -1,14 +1,19 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "BLI_index_range.hh"
+#include "BLI_math_vector.h"
+#include "BLI_math_vector.hh"
+
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
-#include "BKE_material.h"
+#include "BKE_attribute_access.hh"
+#include "BKE_geometry_set.hh"
#include "BKE_mesh.h"
-#include "node_geometry_util.hh"
+#include "GEO_mesh_primitive_cuboid.hh"
-namespace blender::nodes {
+namespace blender::geometry {
struct CuboidConfig {
float3 size;
@@ -315,12 +320,12 @@ static void calculate_polys(const CuboidConfig &config,
}
}
-static void calculate_uvs(const CuboidConfig &config, Mesh *mesh)
+static void calculate_uvs(const CuboidConfig &config, Mesh *mesh, const bke::AttributeIDRef &uv_id)
{
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);
+ bke::OutputAttribute_Typed<float2> uv_attribute =
+ mesh_component.attribute_try_get_for_output_only<float2>(uv_id, ATTR_DOMAIN_CORNER);
MutableSpan<float2> uvs = uv_attribute.as_span();
int loop_index = 0;
@@ -392,128 +397,27 @@ static void calculate_uvs(const CuboidConfig &config, Mesh *mesh)
uv_attribute.save();
}
-Mesh *create_cuboid_mesh(const float3 size,
+Mesh *create_cuboid_mesh(const float3 &size,
const int verts_x,
const int verts_y,
- const int verts_z)
+ const int verts_z,
+ const bke::AttributeIDRef &uv_id)
{
const CuboidConfig config(size, verts_x, verts_y, verts_z);
Mesh *mesh = BKE_mesh_new_nomain(
config.vertex_count, 0, 0, config.loop_count, config.poly_count);
- BKE_id_material_eval_ensure_default_slot(&mesh->id);
calculate_vertices(config, {mesh->mvert, mesh->totvert});
calculate_polys(config, {mesh->mpoly, mesh->totpoly}, {mesh->mloop, mesh->totloop});
BKE_mesh_calc_edges(mesh, false, false);
- calculate_uvs(config, mesh);
-
- return mesh;
-}
-
-} // namespace blender::nodes
-
-namespace blender::nodes::node_geo_mesh_primitive_cube_cc {
-
-static void node_declare(NodeDeclarationBuilder &b)
-{
- b.add_input<decl::Vector>(N_("Size"))
- .default_value(float3(1))
- .min(0.0f)
- .subtype(PROP_TRANSLATION)
- .description(N_("Side length along each axis"));
- b.add_input<decl::Int>(N_("Vertices X"))
- .default_value(2)
- .min(2)
- .max(1000)
- .description(N_("Number of vertices for the X side of the shape"));
- b.add_input<decl::Int>(N_("Vertices Y"))
- .default_value(2)
- .min(2)
- .max(1000)
- .description(N_("Number of vertices for the Y side of the shape"));
- b.add_input<decl::Int>(N_("Vertices Z"))
- .default_value(2)
- .min(2)
- .max(1000)
- .description(N_("Number of vertices for the Z side of the shape"));
- b.add_output<decl::Geometry>(N_("Mesh"));
-}
-
-static Mesh *create_cube_mesh(const float3 size,
- const int verts_x,
- const int verts_y,
- const int verts_z)
-{
- const int dimensions = (verts_x - 1 > 0) + (verts_y - 1 > 0) + (verts_z - 1 > 0);
- if (dimensions == 0) {
- return create_line_mesh(float3(0), float3(0), 1);
- }
- if (dimensions == 1) {
- float3 start;
- float3 delta;
- if (verts_x > 1) {
- start = {-size.x / 2.0f, 0, 0};
- delta = {size.x / (verts_x - 1), 0, 0};
- }
- else if (verts_y > 1) {
- start = {0, -size.y / 2.0f, 0};
- delta = {0, size.y / (verts_y - 1), 0};
- }
- else {
- start = {0, 0, -size.z / 2.0f};
- delta = {0, 0, size.z / (verts_z - 1)};
- }
-
- return create_line_mesh(start, delta, verts_x * verts_y * verts_z);
- }
- if (dimensions == 2) {
- if (verts_z == 1) { /* XY plane. */
- return create_grid_mesh(verts_x, verts_y, size.x, size.y);
- }
- if (verts_y == 1) { /* XZ plane. */
- Mesh *mesh = create_grid_mesh(verts_x, verts_z, size.x, size.z);
- transform_mesh(*mesh, float3(0), float3(M_PI_2, 0.0f, 0.0f), float3(1));
- return mesh;
- }
- /* YZ plane. */
- Mesh *mesh = create_grid_mesh(verts_z, verts_y, size.z, size.y);
- transform_mesh(*mesh, float3(0), float3(0.0f, M_PI_2, 0.0f), float3(1));
- return mesh;
- }
-
- return create_cuboid_mesh(size, verts_x, verts_y, verts_z);
-}
-
-static void node_geo_exec(GeoNodeExecParams params)
-{
- const float3 size = params.extract_input<float3>("Size");
- const int verts_x = params.extract_input<int>("Vertices X");
- const int verts_y = params.extract_input<int>("Vertices Y");
- const int verts_z = params.extract_input<int>("Vertices Z");
- if (verts_x < 1 || verts_y < 1 || verts_z < 1) {
- params.error_message_add(NodeWarningType::Info, TIP_("Vertices must be at least 1"));
- params.set_default_remaining_outputs();
- return;
+ if (uv_id) {
+ calculate_uvs(config, mesh, uv_id);
}
- Mesh *mesh = create_cube_mesh(size, verts_x, verts_y, verts_z);
-
- params.set_output("Mesh", GeometrySet::create_with_mesh(mesh));
+ return mesh;
}
-} // namespace blender::nodes::node_geo_mesh_primitive_cube_cc
-
-void register_node_type_geo_mesh_primitive_cube()
-{
- namespace file_ns = blender::nodes::node_geo_mesh_primitive_cube_cc;
-
- static bNodeType ntype;
-
- geo_node_type_base(&ntype, GEO_NODE_MESH_PRIMITIVE_CUBE, "Cube", NODE_CLASS_GEOMETRY);
- ntype.declare = file_ns::node_declare;
- ntype.geometry_node_execute = file_ns::node_geo_exec;
- nodeRegisterType(&ntype);
-}
+} // namespace blender::geometry
diff --git a/source/blender/nodes/geometry/node_geometry_util.hh b/source/blender/nodes/geometry/node_geometry_util.hh
index 5b7211e44b4..8f20da66c3b 100644
--- a/source/blender/nodes/geometry/node_geometry_util.hh
+++ b/source/blender/nodes/geometry/node_geometry_util.hh
@@ -57,8 +57,6 @@ Mesh *create_cylinder_or_cone_mesh(float radius_top,
GeometryNodeMeshCircleFillType fill_type,
ConeAttributeOutputs &attribute_outputs);
-Mesh *create_cuboid_mesh(float3 size, int verts_x, int verts_y, int verts_z);
-
/**
* Copies the point domain attributes from `in_component` that are in the mask to `out_component`.
*/
diff --git a/source/blender/nodes/geometry/nodes/node_geo_bounding_box.cc b/source/blender/nodes/geometry/nodes/node_geo_bounding_box.cc
index 558129fb384..00b10cc8a2f 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_bounding_box.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_bounding_box.cc
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "GEO_mesh_primitive_cuboid.hh"
+
#include "node_geometry_util.hh"
namespace blender::nodes::node_geo_bounding_box_cc {
@@ -53,7 +55,7 @@ static void node_geo_exec(GeoNodeExecParams params)
else {
const float3 scale = sub_max - sub_min;
const float3 center = sub_min + scale / 2.0f;
- Mesh *mesh = create_cuboid_mesh(scale, 2, 2, 2);
+ Mesh *mesh = geometry::create_cuboid_mesh(scale, 2, 2, 2, "uv_map");
transform_mesh(*mesh, center, float3(0), float3(1));
sub_geometry.replace_mesh(mesh);
sub_geometry.keep_only({GEO_COMPONENT_TYPE_MESH, GEO_COMPONENT_TYPE_INSTANCES});
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc
index 636ecb8ab41..0029b547375 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc
@@ -6,414 +6,9 @@
#include "BKE_material.h"
#include "BKE_mesh.h"
-#include "node_geometry_util.hh"
-
-namespace blender::nodes {
-
-struct CuboidConfig {
- float3 size;
- int verts_x;
- int verts_y;
- int verts_z;
- int edges_x;
- int edges_y;
- int edges_z;
- int vertex_count;
- int poly_count;
- int loop_count;
-
- CuboidConfig(float3 size, int verts_x, int verts_y, int verts_z)
- : size(size),
- verts_x(verts_x),
- verts_y(verts_y),
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list