WIP: Geometry Nodes: A Modeling Approach of Gizmo #108744
@ -15,8 +15,6 @@ namespace blender::bke {
|
||||
class GizmosGeometry {
|
||||
private:
|
||||
blender::VectorSet<std::string> paths_;
|
||||
blender::VectorSet<bNode *> nodes_;
|
||||
blender::VectorSet<bNodeTree *> trees_;
|
||||
blender::Array<int> mapping;
|
||||
|
||||
CustomDataAttributes attributes_;
|
||||
@ -24,13 +22,6 @@ class GizmosGeometry {
|
||||
public:
|
||||
GizmosGeometry() = default;
|
||||
GizmosGeometry(std::string path);
|
||||
GizmosGeometry(std::string path, bNode *node)
|
||||
: paths_{std::move(path)},
|
||||
nodes_{node},
|
||||
trees_{const_cast<bNodeTree *>(&node->owner_tree())},
|
||||
mapping(1, 0){};
|
||||
// GizmosGeometry(int pathes, int gizmos);
|
||||
// GizmosGeometry(const GizmosGeometry &other);
|
||||
|
||||
GizmosGeometry *copy() const;
|
||||
|
||||
@ -44,16 +35,6 @@ class GizmosGeometry {
|
||||
return paths_;
|
||||
}
|
||||
|
||||
const Span<bNode *> nodes() const
|
||||
{
|
||||
return nodes_;
|
||||
}
|
||||
|
||||
const Span<bNodeTree *> trees() const
|
||||
{
|
||||
return trees_;
|
||||
}
|
||||
|
||||
Span<int> paths_mapping() const
|
||||
{
|
||||
return mapping;
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "ED_screen.h"
|
||||
|
||||
#include "RNA_access.h"
|
||||
#include "RNA_path.h"
|
||||
#include "RNA_prototypes.h"
|
||||
|
||||
#include "UI_resources.h"
|
||||
@ -42,6 +43,13 @@ struct GeometryNodeGizmoWrapper {
|
||||
: gizmos_geometry(gizmos_geometry_source), gizmos_objects(gizmos_geometry.gizmos_num())
|
||||
{
|
||||
}
|
||||
|
||||
~GeometryNodeGizmoWrapper() = default;
|
||||
|
||||
static void free(void *this_)
|
||||
{
|
||||
static_cast<GeometryNodeGizmoWrapper *>(this_)->~GeometryNodeGizmoWrapper();
|
||||
}
|
||||
};
|
||||
|
||||
static const bke::GizmosGeometry *gizmos_from_context_try(const bContext *C)
|
||||
@ -92,6 +100,7 @@ static void geometry_node_setup(const bContext *C, wmGizmoGroup *gzgroup)
|
||||
|
||||
GeometryNodeGizmoWrapper &gzgroup_data = *(new GeometryNodeGizmoWrapper(*gizmos));
|
||||
gzgroup->customdata = &gzgroup_data;
|
||||
gzgroup->customdata_free = GeometryNodeGizmoWrapper::free;
|
||||
|
||||
for (const int index : IndexRange(gizmos->gizmos_num())) {
|
||||
wmGizmo *gizmo = WM_gizmo_new("GIZMO_GT_arrow_3d", gzgroup, NULL);
|
||||
@ -107,30 +116,31 @@ static void geometry_node_refresh(const bContext *C, wmGizmoGroup *gzgroup)
|
||||
{
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
const Object *object = BKE_view_layer_active_object_get(view_layer);
|
||||
GeometryNodeGizmoWrapper &gzgroup_data = *static_cast<GeometryNodeGizmoWrapper *>(
|
||||
gzgroup->customdata);
|
||||
GeometryNodeGizmoWrapper &gzgroup_data = *static_cast<GeometryNodeGizmoWrapper *>(gzgroup->customdata);
|
||||
|
||||
const bke::GizmosGeometry *gizmos_geometry = gizmos_from_context_try(C);
|
||||
|
||||
const Span<bNode *> nodes = gizmos_geometry->nodes();
|
||||
const Span<bNodeTree *> trees = gizmos_geometry->trees();
|
||||
const Span<std::string> pathes = gizmos_geometry->pathes();
|
||||
|
||||
const Span<int> paths_mapping = gizmos_geometry->paths_mapping();
|
||||
for (const int index : paths_mapping.index_range()) {
|
||||
PointerRNA node_ptr;
|
||||
|
||||
bNode *node = nodes[index];
|
||||
printf("> %p;\n", node);
|
||||
bNodeTree *tree = trees[index];
|
||||
const StringRefNull rna_path = pathes[index];
|
||||
RNA_pointer_create(&tree->id, &RNA_Node, node, &node_ptr);
|
||||
|
||||
wmGizmo *gizmo = gzgroup_data.gizmos_objects[index];
|
||||
|
||||
const StringRefNull rna_path = pathes[index];
|
||||
|
||||
PointerRNA blender_data_pointer;
|
||||
RNA_pointer_create(NULL, &RNA_BlendData, CTX_data_main(C), &blender_data_pointer);
|
||||
|
||||
PointerRNA node_ptr;
|
||||
PropertyRNA *value_prop;
|
||||
BLI_assert(RNA_path_resolve_full(&blender_data_pointer,
|
||||
rna_path.data(),
|
||||
&node_ptr,
|
||||
&value_prop,
|
||||
nullptr));
|
||||
|
||||
const float3 normal = {1.0f, 0.0f, 0.0f};
|
||||
WM_gizmo_set_matrix_rotation_from_z_axis(gizmo, normal);
|
||||
WM_gizmo_set_matrix_location(gizmo, object->object_to_world[3]);
|
||||
WM_gizmo_target_property_def_rna(gizmo, "offset", &node_ptr, rna_path.data(), -1);
|
||||
WM_gizmo_target_property_def_rna(gizmo, "offset", &node_ptr, "value", -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ set(INC
|
||||
../../makesrna
|
||||
../../render
|
||||
../../windowmanager
|
||||
../../../../extern/fmtlib/include
|
||||
../../../../intern/guardedalloc
|
||||
# RNA_prototypes.h
|
||||
${CMAKE_BINARY_DIR}/source/blender/makesrna
|
||||
|
@ -2,6 +2,9 @@
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#define FMT_HEADER_ONLY
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "BKE_gizmos.hh"
|
||||
|
||||
#include "node_geometry_util.hh"
|
||||
@ -13,6 +16,7 @@ NODE_STORAGE_FUNCS(NodeGeometryArrowGizmo)
|
||||
static void node_declare(NodeDeclarationBuilder &b)
|
||||
{
|
||||
b.add_output<decl::Geometry>("Gizmo");
|
||||
b.add_output<decl::Float>("Value");
|
||||
}
|
||||
|
||||
static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
|
||||
@ -29,11 +33,14 @@ static void node_init(bNodeTree * /*tree*/, bNode *node)
|
||||
|
||||
static void node_geo_exec(GeoNodeExecParams params)
|
||||
{
|
||||
printf(">>> %p;\n", ¶ms.node());
|
||||
bke::GizmosGeometry *gizmo = new bke::GizmosGeometry("value",
|
||||
const_cast<bNode *>(¶ms.node()));
|
||||
|
||||
const bNode &node = params.node();
|
||||
const bNodeTree &tree = node.owner_tree();
|
||||
std::string gizmos_value_path_str = fmt::format(TIP_("node_groups[\"{}\"].nodes[\"{}\"]"), tree.id.name + 2, node.name);
|
||||
bke::GizmosGeometry *gizmo = new bke::GizmosGeometry(std::move(gizmos_value_path_str));
|
||||
params.set_output("Gizmo", GeometrySet::create_with_gizmos(gizmo));
|
||||
|
||||
const NodeGeometryArrowGizmo &storage = node_storage(node);
|
||||
params.set_output("Value", storage.value);
|
||||
}
|
||||
|
||||
} // namespace blender::nodes::node_geo_arrow_gizmo_cc
|
||||
|
Loading…
Reference in New Issue
Block a user