WIP: Geometry Nodes: Rotation type #107954

Closed
Hans Goudey wants to merge 4 commits from HooglyBoogly:geometry-nodes-rotation-type into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
2 changed files with 9 additions and 12 deletions
Showing only changes of commit 8928b3a5cb - Show all commits

View File

@ -34,10 +34,7 @@ static void node_declare(NodeDeclarationBuilder &b)
.description(
"Index of the instance used for each point. This is only used when Pick Instances "
"is on. By default the point index is used");
b.add_input<decl::Vector>("Rotation")
.subtype(PROP_EULER)
.field_on({0})
.description("Rotation of the instances");
b.add_input<decl::Rotation>("Rotation").field_on({0}).description("Rotation of the instances");
b.add_input<decl::Vector>("Scale")
.default_value({1.0f, 1.0f, 1.0f})
.subtype(PROP_XYZ)
@ -59,7 +56,7 @@ static void add_instances_from_component(
VArray<bool> pick_instance;
VArray<int> indices;
VArray<float3> rotations;
VArray<math::Quaternion> rotations;
VArray<float3> scales;
const bke::GeometryFieldContext field_context{src_component, domain};
@ -70,7 +67,7 @@ static void add_instances_from_component(
* selected indices should be copied. */
evaluator.add(params.get_input<Field<bool>>("Pick Instance"), &pick_instance);
evaluator.add(params.get_input<Field<int>>("Instance Index"), &indices);
evaluator.add(params.get_input<Field<float3>>("Rotation"), &rotations);
evaluator.add(params.get_input<Field<math::Quaternion>>("Rotation"), &rotations);
evaluator.add(params.get_input<Field<float3>>("Scale"), &scales);
evaluator.evaluate();
@ -118,8 +115,7 @@ static void add_instances_from_component(
/* Compute base transform for every instances. */
float4x4 &dst_transform = dst_transforms[range_i];
dst_transform = math::from_loc_rot_scale<float4x4>(
positions[i], math::EulerXYZ(rotations[i]), scales[i]);
dst_transform = math::from_loc_rot_scale<float4x4>(positions[i], rotations[i], scales[i]);
/* Reference that will be used by this new instance. */
int dst_handle = empty_reference_handle;

View File

@ -8,6 +8,7 @@
#include "BLI_math_matrix.hh"
#include "BLI_math_matrix_types.hh"
#include "BLI_math_quaternion.hh"
#include "BLI_task.hh"
#include "DNA_mesh_types.h"
@ -26,9 +27,9 @@
namespace blender::nodes {
static bool use_translate(const float3 rotation, const float3 scale)
static bool use_translate(const math::Quaternion rotation, const float3 scale)
{
if (compare_ff(math::length_squared(rotation), 0.0f, 1e-9f) != 1) {
if (!math::is_equal(float4(rotation), float4(math::Quaternion::identity()), 1e7f)) {
return false;
}
if (compare_ff(scale.x, 1.0f, 1e-9f) != 1 || compare_ff(scale.y, 1.0f, 1e-9f) != 1 ||
@ -267,7 +268,7 @@ static void node_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Geometry>("Geometry");
b.add_input<decl::Vector>("Translation").subtype(PROP_TRANSLATION);
b.add_input<decl::Vector>("Rotation").subtype(PROP_EULER);
b.add_input<decl::Rotation>("Rotation");
b.add_input<decl::Vector>("Scale").default_value({1, 1, 1}).subtype(PROP_XYZ);
b.add_output<decl::Geometry>("Geometry").propagate_all();
}
@ -276,7 +277,7 @@ static void node_geo_exec(GeoNodeExecParams params)
{
GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
const float3 translation = params.extract_input<float3>("Translation");
const float3 rotation = params.extract_input<float3>("Rotation");
const math::Quaternion rotation = params.extract_input<math::Quaternion>("Rotation");
const float3 scale = params.extract_input<float3>("Scale");
/* Use only translation if rotation and scale don't apply. */