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:
authorDalai Felinto <dalai@blender.org>2021-01-19 19:30:44 +0300
committerDalai Felinto <dalai@blender.org>2021-01-19 19:30:44 +0300
commit8b777ee6d69d4805c64756cf6a33db894160ce29 (patch)
treeb9d8decb26cf0841fbdc6451c1ad337eda6649b0 /source/blender/nodes
parenta9203e25a2e1f1489b8a3705f8883cdd86f094c7 (diff)
Geometry Nodes - Object Info: option to apply obj transform to the geometry
By design the modified object transformations should still work and affect the geometry nodes results. The current behaviour, however, would make the geometry from the object info to not be affected by the modified object transformations. This patch changes that by default. In a similar fashion the Location, Rotation and Scale sockets outputs should be aware of whether the output should be in the global space or in the space of the nodetree. To solve this, the patch introduces a new transformation space "enum" where users can pick "Original" or "Relative" space. Original -------- Output the geometry relative to the input object transform, and the location, rotation and scale relative to the world origin. Relative -------- Bring the input object geometry, location, rotation and scale into the modified object maintaining the relative position between the two objects in the scene. Relative space violates a bit the design of the nodetree. The geometry in this case is transformed so that moving the modified object doesn't interfere with the geometry. This is particularly useful for the boolean node for instance. "Original" is the default space, but old files are set to "Relative" for backwards compatibility. Differential Revision: https://developer.blender.org/D10124
Diffstat (limited to 'source/blender/nodes')
-rw-r--r--source/blender/nodes/NOD_static_types.h2
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_object_info.cc30
2 files changed, 28 insertions, 4 deletions
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index f58dca18325..e91b385a87e 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -275,7 +275,7 @@ DefNode(GeometryNode, GEO_NODE_SUBDIVISION_SURFACE, 0, "SUBDIVISION_SURFACE", Su
DefNode(GeometryNode, GEO_NODE_BOOLEAN, def_geo_boolean, "BOOLEAN", Boolean, "Boolean", "")
DefNode(GeometryNode, GEO_NODE_POINT_DISTRIBUTE, def_geo_point_distribute, "POINT_DISTRIBUTE", PointDistribute, "Point Distribute", "")
DefNode(GeometryNode, GEO_NODE_POINT_INSTANCE, def_geo_point_instance, "POINT_INSTANCE", PointInstance, "Point Instance", "")
-DefNode(GeometryNode, GEO_NODE_OBJECT_INFO, 0, "OBJECT_INFO", ObjectInfo, "Object Info", "")
+DefNode(GeometryNode, GEO_NODE_OBJECT_INFO, def_geo_object_info, "OBJECT_INFO", ObjectInfo, "Object Info", "")
DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_RANDOMIZE, def_geo_attribute_randomize, "ATTRIBUTE_RANDOMIZE", AttributeRandomize, "Attribute Randomize", "")
DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_MATH, def_geo_attribute_math, "ATTRIBUTE_MATH", AttributeMath, "Attribute Math", "")
DefNode(GeometryNode, GEO_NODE_JOIN_GEOMETRY, 0, "JOIN_GEOMETRY", JoinGeometry, "Join Geometry", "")
diff --git a/source/blender/nodes/geometry/nodes/node_geo_object_info.cc b/source/blender/nodes/geometry/nodes/node_geo_object_info.cc
index 07d6858369d..ab5e4f8964a 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_object_info.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_object_info.cc
@@ -38,6 +38,11 @@ static bNodeSocketTemplate geo_node_object_info_out[] = {
namespace blender::nodes {
static void geo_node_object_info_exec(GeoNodeExecParams params)
{
+ const bNode &bnode = params.node();
+ NodeGeometryObjectInfo *node_storage = (NodeGeometryObjectInfo *)bnode.storage;
+ const bool transform_space_relative = (node_storage->transform_space ==
+ GEO_NODE_TRANSFORM_SPACE_RELATIVE);
+
bke::PersistentObjectHandle object_handle = params.extract_input<bke::PersistentObjectHandle>(
"Object");
Object *object = params.handle_map().lookup(object_handle);
@@ -54,7 +59,12 @@ static void geo_node_object_info_exec(GeoNodeExecParams params)
mul_m4_m4m4(transform, self_object->imat, object->obmat);
float quaternion[4];
- mat4_decompose(location, quaternion, scale, transform);
+ if (transform_space_relative) {
+ mat4_decompose(location, quaternion, scale, transform);
+ }
+ else {
+ mat4_decompose(location, quaternion, scale, object->obmat);
+ }
quat_to_eul(rotation, quaternion);
if (object != self_object) {
@@ -66,8 +76,10 @@ static void geo_node_object_info_exec(GeoNodeExecParams params)
/* Make a copy because the life time of the other mesh might be shorter. */
Mesh *copied_mesh = BKE_mesh_copy_for_eval(mesh, false);
- /* Transform into the local space of the object that is being modified. */
- BKE_mesh_transform(copied_mesh, transform, true);
+ if (transform_space_relative) {
+ /* Transform into the local space of the object that is being modified. */
+ BKE_mesh_transform(copied_mesh, transform, true);
+ }
MeshComponent &mesh_component = geometry_set.get_component_for_write<MeshComponent>();
mesh_component.replace(copied_mesh);
@@ -82,6 +94,15 @@ static void geo_node_object_info_exec(GeoNodeExecParams params)
params.set_output("Scale", scale);
params.set_output("Geometry", geometry_set);
}
+
+static void geo_node_object_info_node_init(bNodeTree *UNUSED(tree), bNode *node)
+{
+ NodeGeometryObjectInfo *data = (NodeGeometryObjectInfo *)MEM_callocN(
+ sizeof(NodeGeometryObjectInfo), __func__);
+ data->transform_space = GEO_NODE_TRANSFORM_SPACE_ORIGINAL;
+ node->storage = data;
+}
+
} // namespace blender::nodes
void register_node_type_geo_object_info()
@@ -90,6 +111,9 @@ void register_node_type_geo_object_info()
geo_node_type_base(&ntype, GEO_NODE_OBJECT_INFO, "Object Info", NODE_CLASS_INPUT, 0);
node_type_socket_templates(&ntype, geo_node_object_info_in, geo_node_object_info_out);
+ node_type_init(&ntype, blender::nodes::geo_node_object_info_node_init);
+ node_type_storage(
+ &ntype, "NodeGeometryObjectInfo", node_free_standard_storage, node_copy_standard_storage);
ntype.geometry_node_execute = blender::nodes::geo_node_object_info_exec;
nodeRegisterType(&ntype);
}