This adds support for attaching gizmos for input values. The goal is to make it easier for users to set input values intuitively in the 3D viewport. We went through multiple different possible designs until we settled on the one implemented here. We picked it for it's flexibility and ease of use when using geometry node assets. The core principle in the design is that **gizmos are attached to existing input values instead of being the input value themselves**. This actually fits the existing concept of gizmos in Blender well, but may be a bit unintutitive in a node setup at first. The attachment is done using links in the node editor. The most basic usage of the node is to link a Value node to the new Linear Gizmo node. This attaches the gizmo to the input value and allows you to change it from the 3D view. The attachment is indicated by the gizmo icon in the sockets which are controlled by a gizmo as well as the back-link (notice the double link) when the gizmo is active. The core principle makes it straight forward to control the same node setup from the 3D view with gizmos, or by manually changing input values, or by driving the input values procedurally. If the input value is controlled indirectly by other inputs, it's often possible to **automatically propagate** the gizmo to the actual input. Backpropagation does not work for all nodes, although more nodes can be supported over time. This patch adds the first three gizmo nodes which cover common use cases: * **Linear Gizmo**: Creates a gizmo that controls a float or integer value using a linear movement of e.g. an arrow in the 3D viewport. * **Dial Gizmo**: Creates a circular gizmo in the 3D viewport that can be rotated to change the attached angle input. * **Transform Gizmo**: Creates a simple gizmo for location, rotation and scale. In the future, more built-in gizmos and potentially the ability for custom gizmos could be added. All gizmo nodes have a **Transform** geometry output. Using it is optional but it is recommended when the gizmo is used to control inputs that affect a geometry. When it is used, Blender will automatically transform the gizmos together with the geometry that they control. To achieve this, the output should be merged with the generated geometry using the *Join Geometry* node. The data contained in *Transform* output is not visible geometry, but just internal information that helps Blender to give a better user experience when using gizmos. The gizmo nodes have a multi-input socket. This allows **controlling multiple values** with the same gizmo. Only a small set of **gizmo shapes** is supported initially. It might be extended in the future but one goal is to give the gizmos used by different node group assets a familiar look and feel. A similar constraint exists for **colors**. Currently, one can choose from a fixed set of colors which can be modified in the theme settings. The set of **visible gizmos** is determined by a multiple factors because it's not really feasible to show all possible gizmos at all times. To see any of the geometry nodes gizmos, the "Active Modifier" option has to be enabled in the "Viewport Gizmos" popover. Then all gizmos are drawn for which at least one of the following is true: * The gizmo controls an input of the active modifier of the active object. * The gizmo controls a value in a selected node in an open node editor. * The gizmo controls a pinned value in an open node editor. Pinning works by clicking the gizmo icon next to the value. Pull Request: https://projects.blender.org/blender/blender/pulls/112677
101 lines
3.0 KiB
C++
101 lines
3.0 KiB
C++
/* SPDX-FileCopyrightText: 2024 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#include "NOD_value_elem_eval.hh"
|
|
|
|
namespace blender::nodes::value_elem {
|
|
|
|
std::optional<ElemVariant> get_elem_variant_for_socket_type(const eNodeSocketDatatype type)
|
|
{
|
|
switch (type) {
|
|
case SOCK_FLOAT:
|
|
return {{FloatElem()}};
|
|
case SOCK_INT:
|
|
return {{IntElem()}};
|
|
case SOCK_BOOLEAN:
|
|
return {{BoolElem()}};
|
|
case SOCK_VECTOR:
|
|
return {{VectorElem()}};
|
|
case SOCK_ROTATION:
|
|
return {{RotationElem()}};
|
|
case SOCK_MATRIX:
|
|
return {{MatrixElem()}};
|
|
default:
|
|
return std::nullopt;
|
|
}
|
|
}
|
|
|
|
std::optional<ElemVariant> convert_socket_elem(const bNodeSocket &old_socket,
|
|
const bNodeSocket &new_socket,
|
|
const ElemVariant &old_elem)
|
|
{
|
|
const eNodeSocketDatatype old_type = eNodeSocketDatatype(old_socket.type);
|
|
const eNodeSocketDatatype new_type = eNodeSocketDatatype(new_socket.type);
|
|
if (old_type == new_type) {
|
|
return old_elem;
|
|
}
|
|
if (ELEM(old_type, SOCK_INT, SOCK_FLOAT, SOCK_BOOLEAN) &&
|
|
ELEM(new_type, SOCK_INT, SOCK_FLOAT, SOCK_BOOLEAN))
|
|
{
|
|
std::optional<ElemVariant> new_elem = get_elem_variant_for_socket_type(new_type);
|
|
if (old_elem) {
|
|
new_elem->set_all();
|
|
}
|
|
return new_elem;
|
|
}
|
|
switch (old_type) {
|
|
case SOCK_MATRIX: {
|
|
const MatrixElem &transform_elem = std::get<MatrixElem>(old_elem.elem);
|
|
if (new_type == SOCK_ROTATION) {
|
|
return ElemVariant{transform_elem.rotation};
|
|
}
|
|
break;
|
|
}
|
|
case SOCK_ROTATION: {
|
|
const RotationElem &rotation_elem = std::get<RotationElem>(old_elem.elem);
|
|
if (new_type == SOCK_MATRIX) {
|
|
MatrixElem matrix_elem;
|
|
matrix_elem.rotation = rotation_elem;
|
|
return ElemVariant{matrix_elem};
|
|
}
|
|
if (new_type == SOCK_VECTOR) {
|
|
return ElemVariant{rotation_elem.euler};
|
|
}
|
|
break;
|
|
}
|
|
case SOCK_VECTOR: {
|
|
const VectorElem &vector_elem = std::get<VectorElem>(old_elem.elem);
|
|
if (new_type == SOCK_ROTATION) {
|
|
RotationElem rotation_elem;
|
|
rotation_elem.euler = vector_elem;
|
|
if (rotation_elem) {
|
|
rotation_elem.angle = FloatElem::all();
|
|
rotation_elem.axis = VectorElem::all();
|
|
}
|
|
return ElemVariant{rotation_elem};
|
|
}
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
return std::nullopt;
|
|
}
|
|
|
|
ElemEvalParams::ElemEvalParams(const bNode &node,
|
|
const Map<const bNodeSocket *, ElemVariant> &elem_by_socket,
|
|
Vector<SocketElem> &output_elems)
|
|
: elem_by_socket_(elem_by_socket), output_elems_(output_elems), node(node)
|
|
{
|
|
}
|
|
|
|
InverseElemEvalParams::InverseElemEvalParams(
|
|
const bNode &node,
|
|
const Map<const bNodeSocket *, ElemVariant> &elem_by_socket,
|
|
Vector<SocketElem> &input_elems)
|
|
: elem_by_socket_(elem_by_socket), input_elems_(input_elems), node(node)
|
|
{
|
|
}
|
|
|
|
} // namespace blender::nodes::value_elem
|