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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2021-01-13 19:30:42 +0300
committerHans Goudey <h.goudey@me.com>2021-01-13 19:32:06 +0300
commit1f4c1c5fc73423f87b69621f0f6131b02d014a9f (patch)
tree6efee48cd919103c86ba0b1b2402b64d2e187a4a /source/blender/nodes
parentbae4d00e2a33e255b33b59dbd273d56f3d796f0f (diff)
Geometry Nodes: Add "Point Translate" and "Point Scale" nodes
The translate node moves every point in the geometry, and the scale node multiplies the "scale" attribute of the input geometry by its input. While these operations are already possible with the "Attribute" nodes, these new nodes fit nicely with the nodes specifically for changing the "rotation" attribute that already exist, and they provide a simpler way to do the same thing. Differential Revision: https://developer.blender.org/D10100
Diffstat (limited to 'source/blender/nodes')
-rw-r--r--source/blender/nodes/CMakeLists.txt4
-rw-r--r--source/blender/nodes/NOD_geometry.h2
-rw-r--r--source/blender/nodes/NOD_static_types.h2
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_point_scale.cc99
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_point_translate.cc101
5 files changed, 207 insertions, 1 deletions
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index 19c95d3373d..e9985cb0e13 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -155,8 +155,10 @@ set(SRC
geometry/nodes/node_geo_object_info.cc
geometry/nodes/node_geo_point_distribute.cc
geometry/nodes/node_geo_point_instance.cc
- geometry/nodes/node_geo_point_separate.cc
geometry/nodes/node_geo_point_rotate.cc
+ geometry/nodes/node_geo_point_scale.cc
+ geometry/nodes/node_geo_point_separate.cc
+ geometry/nodes/node_geo_point_translate.cc
geometry/nodes/node_geo_subdivision_surface.cc
geometry/nodes/node_geo_transform.cc
geometry/nodes/node_geo_triangulate.cc
diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h
index 22f04356426..523d0cfa24d 100644
--- a/source/blender/nodes/NOD_geometry.h
+++ b/source/blender/nodes/NOD_geometry.h
@@ -40,6 +40,8 @@ void register_node_type_geo_attribute_randomize(void);
void register_node_type_geo_attribute_math(void);
void register_node_type_geo_join_geometry(void);
void register_node_type_geo_point_separate(void);
+void register_node_type_geo_point_scale(void);
+void register_node_type_geo_point_translate(void);
void register_node_type_geo_attribute_compare(void);
void register_node_type_geo_attribute_mix(void);
void register_node_type_geo_attribute_color_ramp(void);
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index 07a377dbdf6..f58dca18325 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -287,6 +287,8 @@ DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_COMPARE, def_geo_attribute_attribute_co
DefNode(GeometryNode, GEO_NODE_POINT_ROTATE, def_geo_point_rotate, "POINT_ROTATE", RotatePoints, "Point Rotate", "")
DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_VECTOR_MATH, def_geo_attribute_vector_math, "ATTRIBUTE_VECTOR_MATH", AttributeVectorMath, "Attribute Vector Math", "")
DefNode(GeometryNode, GEO_NODE_ALIGN_ROTATION_TO_VECTOR, def_geo_align_rotation_to_vector, "ALIGN_ROTATION_TO_VECTOR", AlignRotationToVector, "Align Rotation to Vector", "")
+DefNode(GeometryNode, GEO_NODE_POINT_SCALE, def_geo_point_scale, "POINT_SCALE", PointScale, "Point Scale", "")
+DefNode(GeometryNode, GEO_NODE_POINT_TRANSLATE, def_geo_point_translate, "POINT_TRANSLATE", PointTranslate, "Point Translate", "")
/* undefine macros */
#undef DefNode
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_scale.cc b/source/blender/nodes/geometry/nodes/node_geo_point_scale.cc
new file mode 100644
index 00000000000..165f467fef0
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_scale.cc
@@ -0,0 +1,99 @@
+/*
+ * 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 "node_geometry_util.hh"
+
+#include "BKE_colorband.h"
+
+static bNodeSocketTemplate geo_node_point_scale_in[] = {
+ {SOCK_GEOMETRY, N_("Geometry")},
+ {SOCK_STRING, N_("Factor")},
+ {SOCK_VECTOR, N_("Factor"), 1.0f, 1.0f, 1.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_XYZ},
+ {-1, ""},
+};
+
+static bNodeSocketTemplate geo_node_point_scale_out[] = {
+ {SOCK_GEOMETRY, N_("Geometry")},
+ {-1, ""},
+};
+
+namespace blender::nodes {
+
+static void execute_on_component(GeoNodeExecParams params, GeometryComponent &component)
+{
+ Float3WriteAttribute scale_attribute = component.attribute_try_ensure_for_write(
+ "scale", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3);
+ ReadAttributePtr attribute = params.get_input_attribute(
+ "Factor", component, ATTR_DOMAIN_POINT, CD_PROP_FLOAT3, nullptr);
+ if (!attribute) {
+ return;
+ }
+
+ Span<float3> data = attribute->get_span<float3>();
+ MutableSpan<float3> scale_span = scale_attribute.get_span();
+ for (const int i : scale_span.index_range()) {
+ scale_span[i] = scale_span[i] * data[i];
+ }
+
+ scale_attribute.apply_span();
+}
+
+static void geo_node_point_scale_exec(GeoNodeExecParams params)
+{
+ GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
+
+ if (geometry_set.has<MeshComponent>()) {
+ execute_on_component(params, geometry_set.get_component_for_write<MeshComponent>());
+ }
+ if (geometry_set.has<PointCloudComponent>()) {
+ execute_on_component(params, geometry_set.get_component_for_write<PointCloudComponent>());
+ }
+
+ params.set_output("Geometry", std::move(geometry_set));
+}
+
+static void geo_node_point_scale_init(bNodeTree *UNUSED(tree), bNode *node)
+{
+ NodeGeometryPointScale *data = (NodeGeometryPointScale *)MEM_callocN(
+ sizeof(NodeGeometryPointScale), __func__);
+
+ data->input_type = GEO_NODE_ATTRIBUTE_INPUT_ATTRIBUTE;
+ node->storage = data;
+}
+
+static void geo_node_point_scale_update(bNodeTree *UNUSED(ntree), bNode *node)
+{
+ NodeGeometryPointScale &node_storage = *(NodeGeometryPointScale *)node->storage;
+
+ update_attribute_input_socket_availabilities(
+ *node, "Factor", (GeometryNodeAttributeInputMode)node_storage.input_type);
+}
+
+} // namespace blender::nodes
+
+void register_node_type_geo_point_scale()
+{
+ static bNodeType ntype;
+
+ geo_node_type_base(&ntype, GEO_NODE_POINT_SCALE, "Point Scale", NODE_CLASS_GEOMETRY, 0);
+ node_type_socket_templates(&ntype, geo_node_point_scale_in, geo_node_point_scale_out);
+ node_type_init(&ntype, blender::nodes::geo_node_point_scale_init);
+ node_type_update(&ntype, blender::nodes::geo_node_point_scale_update);
+ node_type_storage(
+ &ntype, "NodeGeometryPointScale", node_free_standard_storage, node_copy_standard_storage);
+ ntype.geometry_node_execute = blender::nodes::geo_node_point_scale_exec;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_translate.cc b/source/blender/nodes/geometry/nodes/node_geo_point_translate.cc
new file mode 100644
index 00000000000..1dbc6016024
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_translate.cc
@@ -0,0 +1,101 @@
+/*
+ * 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 "node_geometry_util.hh"
+
+#include "BKE_colorband.h"
+
+static bNodeSocketTemplate geo_node_point_translate_in[] = {
+ {SOCK_GEOMETRY, N_("Geometry")},
+ {SOCK_STRING, N_("Translation")},
+ {SOCK_VECTOR, N_("Translation"), 0.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_TRANSLATION},
+ {-1, ""},
+};
+
+static bNodeSocketTemplate geo_node_point_translate_out[] = {
+ {SOCK_GEOMETRY, N_("Geometry")},
+ {-1, ""},
+};
+
+namespace blender::nodes {
+
+static void execute_on_component(GeoNodeExecParams params, GeometryComponent &component)
+{
+ Float3WriteAttribute position_attribute = component.attribute_try_ensure_for_write(
+ "position", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3);
+ ReadAttributePtr attribute = params.get_input_attribute(
+ "Translation", component, ATTR_DOMAIN_POINT, CD_PROP_FLOAT3, nullptr);
+ if (!attribute) {
+ return;
+ }
+
+ Span<float3> data = attribute->get_span<float3>();
+ MutableSpan<float3> scale_span = position_attribute.get_span();
+ for (const int i : scale_span.index_range()) {
+ scale_span[i] = scale_span[i] + data[i];
+ }
+
+ position_attribute.apply_span();
+}
+
+static void geo_node_point_translate_exec(GeoNodeExecParams params)
+{
+ GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
+
+ if (geometry_set.has<MeshComponent>()) {
+ execute_on_component(params, geometry_set.get_component_for_write<MeshComponent>());
+ }
+ if (geometry_set.has<PointCloudComponent>()) {
+ execute_on_component(params, geometry_set.get_component_for_write<PointCloudComponent>());
+ }
+
+ params.set_output("Geometry", std::move(geometry_set));
+}
+
+static void geo_node_point_translate_init(bNodeTree *UNUSED(tree), bNode *node)
+{
+ NodeGeometryPointTranslate *data = (NodeGeometryPointTranslate *)MEM_callocN(
+ sizeof(NodeGeometryPointTranslate), __func__);
+
+ data->input_type = GEO_NODE_ATTRIBUTE_INPUT_ATTRIBUTE;
+ node->storage = data;
+}
+
+static void geo_node_point_translate_update(bNodeTree *UNUSED(ntree), bNode *node)
+{
+ NodeGeometryPointTranslate &node_storage = *(NodeGeometryPointTranslate *)node->storage;
+
+ update_attribute_input_socket_availabilities(
+ *node, "Translation", (GeometryNodeAttributeInputMode)node_storage.input_type);
+}
+
+} // namespace blender::nodes
+
+void register_node_type_geo_point_translate()
+{
+ static bNodeType ntype;
+
+ geo_node_type_base(&ntype, GEO_NODE_POINT_TRANSLATE, "Point Translate", NODE_CLASS_GEOMETRY, 0);
+ node_type_socket_templates(&ntype, geo_node_point_translate_in, geo_node_point_translate_out);
+ node_type_init(&ntype, blender::nodes::geo_node_point_translate_init);
+ node_type_update(&ntype, blender::nodes::geo_node_point_translate_update);
+ node_type_storage(&ntype,
+ "NodeGeometryPointTranslate",
+ node_free_standard_storage,
+ node_copy_standard_storage);
+ ntype.geometry_node_execute = blender::nodes::geo_node_point_translate_exec;
+ nodeRegisterType(&ntype);
+}