133 const bNodeSocket &socket = *this->gizmo_node.input_by_identifier(identifier);
138 r_value = *value_opt;
183 bool any_interacting =
false;
187 return any_interacting;
197 float factor_from_transform = 1.0f;
198 float current_value = 0.0f;
204 gizmo_ =
WM_gizmo_new(
"GIZMO_GT_arrow_3d", &gzgroup,
nullptr);
219 if (is_interacting) {
277 edit_data_.current_value = 0.0f;
284 const float new_gizmo_value = *
static_cast<const float *
>(value_ptr);
285 self.edit_data_.current_value = new_gizmo_value;
286 const float offset = new_gizmo_value * self.edit_data_.factor_from_transform;
294 *
static_cast<float *
>(value_ptr) = self.edit_data_.current_value;
305 bool is_negative_transform =
false;
306 float current_value = 0.0f;
312 gizmo_ =
WM_gizmo_new(
"GIZMO_GT_dial_3d", &gzgroup,
nullptr);
327 if (is_interacting) {
342 int draw_options =
RNA_enum_get(gizmo_->ptr,
"draw_options");
344 RNA_enum_set(gizmo_->ptr,
"draw_options", draw_options);
395 edit_data_.current_value = 0.0f;
402 const float new_gizmo_value = *
static_cast<const float *
>(value_ptr);
403 self.edit_data_.current_value = new_gizmo_value;
404 float offset = new_gizmo_value;
405 if (self.edit_data_.is_negative_transform) {
414 *
static_cast<float *
>(value_ptr) = self.edit_data_.current_value;
422 std::array<wmGizmo *, 3> translation_gizmos_ = {};
423 std::array<wmGizmo *, 3> rotation_gizmos_ = {};
424 std::array<wmGizmo *, 3> scale_gizmos_ = {};
426 bool any_translation_visible_ =
false;
427 bool any_rotation_visible_ =
false;
428 bool any_scale_visible_ =
false;
439 float3 current_translation;
449 translation_gizmos_[axis] =
WM_gizmo_new(
"GIZMO_GT_arrow_3d", &gzgroup,
nullptr);
454 rotation_gizmos_[axis] =
WM_gizmo_new(
"GIZMO_GT_dial_3d", &gzgroup,
nullptr);
459 scale_gizmos_[axis] =
WM_gizmo_new(
"GIZMO_GT_arrow_3d", &gzgroup,
nullptr);
466 gizmos.extend(translation_gizmos_);
467 gizmos.extend(rotation_gizmos_);
468 gizmos.extend(scale_gizmos_);
496 transform_orientation_ = orientation_slot.
type;
507 any_translation_visible_ =
false;
508 any_rotation_visible_ =
false;
509 any_scale_visible_ =
false;
511 const auto &elem = std::get<nodes::inverse_eval::MatrixElem>(params.
elem.
elem);
514 const bool translation_used = (
storage.flag &
517 const bool rotation_used = (
storage.flag &
527 any_translation_visible_ |= translation_used;
528 any_rotation_visible_ |= rotation_used;
529 any_scale_visible_ |= scale_used;
536 wmGizmo *gizmo = translation_gizmos_[axis];
542 if (any_rotation_visible_) {
546 else if (any_scale_visible_) {
561 wmGizmo *gizmo = rotation_gizmos_[axis];
581 wmGizmo *gizmo = scale_gizmos_[axis];
585 const float length = (any_translation_visible_ || any_rotation_visible_) ? 0.775f : 1.0f;
593 const float4x4 &base_transform_from_socket)
597 wmGizmo *gizmo = translation_gizmos_[axis_i];
603 axis, base_transform_from_socket, params);
606 edit_data_.current_translation[axis_i] = 0.0f;
612 const void *value_ptr) {
614 const int axis_i =
Span(self.translation_gizmos_).first_index(
const_cast<wmGizmo *
>(gz));
615 const float new_gizmo_value = *
static_cast<const float *
>(value_ptr);
616 self.edit_data_.current_translation[axis_i] = new_gizmo_value;
618 translation[axis_i] = new_gizmo_value;
628 1.0f,
math::length((self.parent_transform_.
view<3, 3>() * orientation)[axis_i]));
636 const int axis_i =
Span(self.translation_gizmos_).first_index(
const_cast<wmGizmo *
>(gz));
637 *
static_cast<float *
>(value_ptr) = self.edit_data_.current_translation[axis_i];
644 const float4x4 &base_transform_from_socket)
648 wmGizmo *gizmo = rotation_gizmos_[axis_i];
654 axis, base_transform_from_socket, params);
657 edit_data_.current_rotation[axis_i] = 0.0f;
663 const void *value_ptr) {
665 const int axis_i =
Span(self.rotation_gizmos_).first_index(
const_cast<wmGizmo *
>(gz));
667 const float new_gizmo_value = *
static_cast<const float *
>(value_ptr);
668 self.edit_data_.current_rotation[axis_i] = new_gizmo_value;
671 float3 local_rotation_axis;
682 value.
view<3, 3>() = rotation_matrix * value.
view<3, 3>();
687 const int axis_i =
Span(self.rotation_gizmos_).first_index(
const_cast<wmGizmo *
>(gz));
688 *
static_cast<float *
>(value_ptr) = self.edit_data_.current_rotation[axis_i];
695 const float4x4 &base_transform_from_socket)
699 wmGizmo *gizmo = scale_gizmos_[axis_i];
705 axis, base_transform_from_socket, params);
708 edit_data_.current_scale[axis_i] = 0.0f;
714 const void *value_ptr) {
716 const int axis_i =
Span(self.scale_gizmos_).first_index(
const_cast<wmGizmo *
>(gz));
718 const float new_gizmo_value = *
static_cast<const float *
>(value_ptr);
719 self.edit_data_.current_scale[axis_i] = new_gizmo_value;
721 scale[axis_i] += new_gizmo_value;
740 for (
int i = 0; i < 3; i++) {
752 const int axis_i =
Span(self.scale_gizmos_).first_index(
const_cast<wmGizmo *
>(gz));
753 *
static_cast<float *
>(value_ptr) = self.edit_data_.current_scale[axis_i];
760 const float4x4 &base_transform_from_socket,
764 const float3 global_location =
767 float3 global_direction{};
769 global_direction = axis_direction;
773 base_transform_from_socket.
view<3, 3>(),
777 gizmo_transform.
location() = global_location;
805 return std::make_unique<LinearGizmo>();
807 return std::make_unique<DialGizmo>();
809 return std::make_unique<TransformGizmos>();
819 if (edit_data_component->gizmo_edit_hints_) {
820 if (
const float4x4 *m = edit_data_component->gizmo_edit_hints_->gizmo_transforms.lookup_ptr(
868 for (
const int reference_i : references.
index_range()) {
879 reference_geometry, gizmo_id, sub_transform))
902 if (
const bke::GeometrySet *viewer_geometry = viewer_log->main_geometry()) {
903 return *viewer_geometry;
936 MEM_delete(gzgroup_data);
961 auto compute_context_cache = std::make_shared<bke::ComputeContextCache>();
965 *compute_context_cache,
966 [&](
const Object &object_orig,
969 const bNode &gizmo_node,
973 if (new_gizmos_by_node.
contains(gizmo_id)) {
990 compute_context, gizmo_node, gizmo_socket);
993 ntree.ensure_topology_cache();
996 if (std::optional<std::unique_ptr<NodeGizmos>> old_gizmos =
997 gzgroup_data.gizmos_by_node.pop_try(gizmo_id))
1000 node_gizmos = old_gizmos->get();
1001 new_gizmos_by_node.
add(gizmo_id, std::move(*old_gizmos));
1006 new_node_gizmos->create_gizmos(*gzgroup);
1008 for (
wmGizmo *gizmo : new_node_gizmos->get_all_gizmos()) {
1011 node_gizmos = new_node_gizmos.get();
1012 new_gizmos_by_node.
add(gizmo_id, std::move(new_node_gizmos));
1022 const std::optional<float4x4> crazy_space_geometry_transform =
1027 if (missing_logged_data) {
1035 const bool missing_used_transform = gizmo_node.output_socket(0).is_logically_linked() &&
1036 !crazy_space_geometry_transform.has_value();
1037 if (missing_used_transform) {
1042 const float4x4 object_to_world{object_eval->object_to_world()};
1043 const float4x4 geometry_transform = crazy_space_geometry_transform.value_or(
1048 *
C, object_to_world * geometry_transform, gizmo_node, tree_log, report, elem};
1049 node_gizmos->
update(update_params);
1053 if (!any_interacting) {
1062 compute_context_cache,
1063 compute_context = &compute_context,
1064 gizmo_node_tree = &gizmo_node.owner_tree(),
1065 gizmo_node = &gizmo_node,
1066 object_orig = &object_orig,
1069 const UString socket_identifier,
1071 gizmo_node_tree->ensure_topology_cache();
1072 const bNodeSocket &socket = *gizmo_node->input_by_identifier(socket_identifier);
1075 const_cast<Object &
>(*object_orig),
1090 bool any_gizmo_interactive =
false;
1091 for (
const std::unique_ptr<NodeGizmos> &node_gizmos : new_gizmos_by_node.
values()) {
1092 any_gizmo_interactive |= node_gizmos->is_any_interacting();
1094 if (any_gizmo_interactive) {
1095 for (std::unique_ptr<NodeGizmos> &node_gizmos : new_gizmos_by_node.
values()) {
1096 for (
wmGizmo *gizmo : node_gizmos->get_all_gizmos()) {
1105 for (std::unique_ptr<NodeGizmos> &node_gizmos : gzgroup_data.gizmos_by_node.values()) {
1112 gzgroup_data.gizmos_by_node = std::move(new_gizmos_by_node);
1126 gzgt->
name =
"Geometry Nodes Widgets";
1127 gzgt->
idname =
"VIEW3D_GGT_geometry_nodes";
#define GEO_NODE_GIZMO_LINEAR
#define GEO_NODE_GIZMO_DIAL
#define GEO_NODE_GIZMO_TRANSFORM
General operations, lookup, etc. for blender objects.
#define SET_FLAG_FROM_TEST(value, test, flag)
btMatrix3x3 scaled(const btVector3 &s) const
Create a scaled copy of the matrix.
const ComputeContextHash & hash() const
constexpr IndexRange()=default
ValueIterator values() const &
bool add(const Key &key, const Value &value)
bool contains(const Key &key) const
bool contains(const Key &key) const
constexpr int64_t first_index_try(const T &search_value) const
constexpr IndexRange index_range() const
GeometrySet & geometry_set()
Span< int > reference_handles() const
Span< float4x4 > transforms() const
Span< InstanceReference > references() const
void update_style(const NodeGeometryDialGizmo &storage, const bool is_interacting)
bool update_transform(GizmosUpdateParams ¶ms)
Vector< wmGizmo * > get_all_gizmos() override
void create_gizmos(wmGizmoGroup &gzgroup) override
void update_target_property()
void update(GizmosUpdateParams ¶ms) override
void create_gizmos(wmGizmoGroup &gzgroup) override
Vector< wmGizmo * > get_all_gizmos() override
bool update_transform(GizmosUpdateParams ¶ms)
void update_target_property()
void update_style(const NodeGeometryLinearGizmo &storage)
void update(GizmosUpdateParams ¶ms) override
bool is_any_interacting()
virtual ~NodeGizmos()=default
ApplyChangeFn apply_change
virtual void create_gizmos(wmGizmoGroup &gzgroup)=0
virtual void update(GizmosUpdateParams &)
virtual Vector< wmGizmo * > get_all_gizmos()=0
static constexpr Value Z_POS
static constexpr Value Z_NEG
static constexpr Axis from_int(const int axis_int)
Set< int > evaluated_gizmo_nodes
std::optional< T > find_primitive_socket_value(const bNodeSocket &query_socket)
void ensure_evaluated_gizmo_nodes()
void ensure_socket_values()
#define storage(slot, qualifiers)
float length(VecOp< float, D >) RET
float3x3 scale(float3x3 mat, float2 scale)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
GeometrySet object_get_evaluated_geometry_set(const Object &object, bool apply_subdiv=true)
static ThemeColorID get_axis_theme_color_id(const int axis)
static float4x4 matrix_from_position_and_up_direction(const float3 &position, const float3 &direction, const math::AxisSigned direction_axis)
static void WIDGETGROUP_geometry_nodes_refresh(const bContext *C, wmGizmoGroup *gzgroup)
static const float4x4 * find_direct_gizmo_transform(const bke::GeometrySet &geometry, const bke::NodeGizmoID &gizmo_id)
static void WIDGETGROUP_geometry_nodes_setup(const bContext *, wmGizmoGroup *gzgroup)
static std::optional< float4x4 > find_gizmo_geometry_transform(const bke::GeometrySet &geometry, const bke::NodeGizmoID &gizmo_id)
static std::unique_ptr< NodeGizmos > create_gizmo_node_gizmos(const bNode &gizmo_node)
static void WIDGETGROUP_geometry_nodes_draw_prepare(const bContext *, wmGizmoGroup *)
static bool WIDGETGROUP_geometry_nodes_poll(const bContext *C, wmGizmoGroupType *)
static void make_matrix_orthonormal_but_keep_z_axis(float4x4 &m)
std::function< void( UString socket_identifier, FunctionRef< void(bke::SocketValueVariant &value)> modify_value)> ApplyChangeFn
static ThemeColorID get_gizmo_theme_color_id(const GeometryNodeGizmoColor color_id)
static bool gizmo_is_interacting(const wmGizmo &gizmo)
static bool has_nested_gizmo_transform(const bke::GeometrySet &geometry, const bke::NodeGizmoID &gizmo_id)
static void get_axis_gizmo_colors(const int axis, float *r_color, float *r_color_hi)
static bke::GeometrySet find_geometry_for_gizmo(const Object &object_eval, const NodesModifierData &nmd_orig, const View3D &v3d)
static std::optional< float4x4 > find_gizmo_geometry_transform_recursive(const bke::GeometrySet &geometry, const bke::NodeGizmoID &gizmo_id, const float4x4 &transform)
QuaternionBase< float > Quaternion
T length_squared(const VecBase< T, Size > &a)
bool is_orthonormal(const MatT &mat)
T to_vector(const Axis axis)
T length(const VecBase< T, Size > &a)
AxisAngleBase< float, AngleRadianBase< float > > AxisAngle
bool is_unit_scale(const MatBase< T, NumCol, NumRow > &m)
T average(const VecBase< T, Size > &a)
CartesianBasis invert(const CartesianBasis &basis)
AxisSigned cross(const AxisSigned a, const AxisSigned b)
MatT from_scale(const VecBase< typename MatT::base_type, ScaleDim > &scale)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
VecBase< T, 3 > to_scale(const MatBase< T, NumCol, NumRow > &mat)
VecBase< T, 3 > transform_direction(const MatBase< T, 3, 3 > &mat, const VecBase< T, 3 > &direction)
MatT from_rotation(const RotationT &rotation)
T determinant(const MatBase< T, Size, Size > &mat)
ie::ElemVariant get_editable_gizmo_elem(const ComputeContext &gizmo_context, const bNode &gizmo_node, const bNodeSocket &gizmo_socket)
void foreach_active_gizmo(const bContext &C, bke::ComputeContextCache &compute_context_cache, const ForeachGizmoFn fn)
void apply_gizmo_change(bContext &C, Object &object, NodesModifierData &nmd, eval_log::NodesEvalLog &eval_log, const ComputeContext &gizmo_context, const bNodeSocket &gizmo_socket, const FunctionRef< void(bke::SocketValueVariant &value)> apply_on_gizmo_value_fn)
void get_color_3fv(int colorid, float col[3])
void WM_main_add_notifier(uint type, void *reference)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
ScrArea * CTX_wm_area(const bContext *C)
int RNA_enum_get(PointerRNA *ptr, const char *name)
void WM_gizmo_target_property_def_func(wmGizmo *gz, const char *idname, const wmGizmoPropertyFnParams *params)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
void VIEW3D_GGT_geometry_nodes(wmGizmoGroupType *gzgt)
void rotation_between_vecs_to_quat(float q[4], const float v1[3], const float v2[3])
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
@ GEO_NODE_TRANSFORM_GIZMO_USE_SCALE_X
@ GEO_NODE_TRANSFORM_GIZMO_USE_TRANSLATION_X
@ GEO_NODE_TRANSFORM_GIZMO_USE_ROTATION_X
MatBase< float, 4, 4 > float4x4
void WM_gizmo_set_line_width(wmGizmo *gz, const float line_width)
void WM_gizmo_unlink(ListBaseT< wmGizmo > *gizmolist, wmGizmoMap *gzmap, wmGizmo *gz, bContext *C)
VecBase< float, 4 > float4
void WM_gizmo_set_flag(wmGizmo *gz, const int flag, const bool enable)
BMesh const char void * data
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
wmWindowManager * CTX_wm_manager(const bContext *C)
void BKE_main_ensure_invariants(Main &bmain, std::optional< Span< ID * > > modified_ids=std::nullopt)
void unit_m4(float m[4][4])
wmGizmo * WM_gizmo_new(const StringRef idname, wmGizmoGroup *gzgroup, PointerRNA *properties)
MatBase< float, 3, 3 > float3x3
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
void DEG_id_tag_update_for_side_effect_request(Depsgraph *depsgraph, ID *id, unsigned int flags)
@ GEO_NODE_GIZMO_COLOR_PRIMARY
@ GEO_NODE_GIZMO_COLOR_SECONDARY
@ ED_GIZMO_ARROW_STYLE_NORMAL
@ ED_GIZMO_ARROW_STYLE_CROSS
@ ED_GIZMO_ARROW_STYLE_BOX
@ WM_GIZMOGROUPTYPE_PERSISTENT
@ WM_GIZMO_DRAW_OFFSET_SCALE
Main * CTX_data_main(const bContext *C)
@ GEO_NODE_LINEAR_GIZMO_DRAW_STYLE_CROSS
@ GEO_NODE_LINEAR_GIZMO_DRAW_STYLE_BOX
@ GEO_NODE_LINEAR_GIZMO_DRAW_STYLE_ARROW
Scene * CTX_data_scene(const bContext *C)
wmKeyMap * WM_gizmogroup_setup_keymap_generic_maybe_drag(const wmGizmoGroupType *, wmKeyConfig *kc)
void copy_m4_m4(float m1[4][4], const float m2[4][4])
VecBase< float, 3 > float3
MINLINE float safe_divide(float a, float b)
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
@ V3D_GIZMO_HIDE_MODIFIER
View3D * CTX_wm_view3d(const bContext *C)
@ ED_GIZMO_DIAL_DRAW_FLAG_CLIP
@ ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE
const c_style_mat & ptr() const
const MatView< T, ViewNumCol, ViewNumRow, NumCol, NumRow, SrcStartCol, SrcStartRow, Alignment > view() const
static MatBase identity()
struct bNodeTree * node_group
NodesModifierRuntime * runtime
std::shared_ptr< nodes::eval_log::NodesEvalLog > eval_log
TransformOrientationSlot orientation_slots[4]
ListBaseT< SpaceLink > spacedata
eView3D_GizmoFlag gizmo_flag
bke::NodeGizmoID gizmo_id
const Object * object_orig
friend bool operator==(const GeoNodesObjectGizmoID &a, const GeoNodesObjectGizmoID &b)=default
Map< GeoNodesObjectGizmoID, std::unique_ptr< NodeGizmos > > gizmos_by_node
bool get_input_value(const UString identifier, T &r_value)
nodes::inverse_eval::ElemVariant elem
float4x4 parent_transform
std::variant< BoolElem, FloatElem, IntElem, VectorElem, RotationElem, MatrixElem > elem
wmGizmoGroupFnRefresh refresh
wmGizmoGroupFnSetupKeymap setup_keymap
wmGizmoGroupFnDrawPrepare draw_prepare
eWM_GizmoFlagGroupTypeFlag flag
wmGizmoMap * parent_gzmap
ListBaseT< wmGizmo > gizmos
void(*) customdata_free(void *)
wmGizmoPropertyFnSet value_set_fn
wmGizmoPropertyFnGet value_get_fn
float matrix_offset[4][4]