Geometry Nodes: use texture socket in Attribute Sample Texture node

There is a new Texture data-block socket that we can use in Geometry
Nodes now. This commit replaces the texture property of a node and
gives it a texture input socket instead. That increases flexibility.

The texture socket still has some limitations that will be lifted in the
next couple of days (e.g. it's not supported by the switch node and
cannot be exposed the a modifier yet).

Differential Revision: https://developer.blender.org/D11222
This commit is contained in:
Jacques Lucke 2021-05-14 11:22:02 +02:00
parent a939317862
commit 2871fadcad
6 changed files with 58 additions and 46 deletions

View File

@ -31,6 +31,7 @@
#include "BKE_lib_id.h"
#include "BKE_main.h"
#include "BKE_node.h"
#include "BLO_readfile.h"
#include "readfile.h"
@ -57,6 +58,30 @@ void do_versions_after_linking_300(Main *bmain, ReportList *UNUSED(reports))
*/
{
/* Keep this block, even when empty. */
/* Use new texture socket in Attribute Sample Texture node. */
LISTBASE_FOREACH (bNodeTree *, ntree, &bmain->nodetrees) {
if (ntree->type != NTREE_GEOMETRY) {
continue;
}
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
if (node->type != GEO_NODE_ATTRIBUTE_SAMPLE_TEXTURE) {
continue;
}
if (node->id == NULL) {
continue;
}
LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
if (socket->type == SOCK_TEXTURE) {
bNodeSocketValueTexture *socket_value = (bNodeSocketValueTexture *)
socket->default_value;
socket_value->value = (Tex *)node->id;
break;
}
}
node->id = NULL;
}
}
}
}

View File

@ -35,6 +35,7 @@ struct bContext;
struct bContextDataResult;
struct bNode;
struct bNodeTree;
struct bNodeSocket;
struct wmOperatorType;
struct SpaceProperties_Runtime {
@ -66,6 +67,7 @@ typedef struct ButsTextureUser {
struct bNodeTree *ntree;
struct bNode *node;
struct bNodeSocket *socket;
const char *category;
int icon;

View File

@ -75,15 +75,16 @@ static SpaceProperties *find_space_properties(const bContext *C);
/************************* Texture User **************************/
static void buttons_texture_user_node_property_add(ListBase *users,
ID *id,
PointerRNA ptr,
PropertyRNA *prop,
bNodeTree *ntree,
bNode *node,
const char *category,
int icon,
const char *name)
static void buttons_texture_user_socket_property_add(ListBase *users,
ID *id,
PointerRNA ptr,
PropertyRNA *prop,
bNodeTree *ntree,
bNode *node,
bNodeSocket *socket,
const char *category,
int icon,
const char *name)
{
ButsTextureUser *user = MEM_callocN(sizeof(ButsTextureUser), "ButsTextureUser");
@ -92,6 +93,7 @@ static void buttons_texture_user_node_property_add(ListBase *users,
user->prop = prop;
user->ntree = ntree;
user->node = node;
user->socket = socket;
user->category = category;
user->icon = icon;
user->name = name;
@ -181,25 +183,29 @@ static void buttons_texture_modifier_geonodes_users_add(Object *ob,
/* Recurse into the node group */
buttons_texture_modifier_geonodes_users_add(ob, nmd, (bNodeTree *)node->id, users);
}
else if (node->type == GEO_NODE_ATTRIBUTE_SAMPLE_TEXTURE) {
RNA_pointer_create(&node_tree->id, &RNA_Node, node, &ptr);
prop = RNA_struct_find_property(&ptr, "texture");
if (prop == NULL) {
LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
if (socket->flag & SOCK_UNAVAIL) {
continue;
}
if (socket->type != SOCK_TEXTURE) {
continue;
}
RNA_pointer_create(&node_tree->id, &RNA_NodeSocket, socket, &ptr);
prop = RNA_struct_find_property(&ptr, "default_value");
PointerRNA texptr = RNA_property_pointer_get(&ptr, prop);
Tex *tex = (RNA_struct_is_a(texptr.type, &RNA_Texture)) ? (Tex *)texptr.data : NULL;
if (tex != NULL) {
buttons_texture_user_node_property_add(users,
&ob->id,
ptr,
prop,
node_tree,
node,
N_("Geometry Nodes"),
RNA_struct_ui_icon(ptr.type),
nmd->modifier.name);
buttons_texture_user_socket_property_add(users,
&ob->id,
ptr,
prop,
node_tree,
node,
socket,
N_("Geometry Nodes"),
RNA_struct_ui_icon(ptr.type),
nmd->modifier.name);
}
}
}

View File

@ -9510,19 +9510,6 @@ static void def_geo_point_translate(StructRNA *srna)
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
}
static void def_geo_attribute_sample_texture(StructRNA *srna)
{
PropertyRNA *prop;
prop = RNA_def_property(srna, "texture", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "id");
RNA_def_property_struct_type(prop, "Texture");
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT);
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Texture", "Texture to sample values from");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update_relations");
}
static void def_geo_object_info(StructRNA *srna)
{
PropertyRNA *prop;

View File

@ -281,7 +281,7 @@ DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_MIX, def_geo_attribute_mix, "ATTRIBUTE_
DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_PROXIMITY, def_geo_attribute_proximity, "ATTRIBUTE_PROXIMITY", AttributeProximity, "Attribute Proximity", "")
DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_RANDOMIZE, def_geo_attribute_randomize, "ATTRIBUTE_RANDOMIZE", AttributeRandomize, "Attribute Randomize", "")
DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_REMOVE, 0, "ATTRIBUTE_REMOVE", AttributeRemove, "Attribute Remove", "")
DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_SAMPLE_TEXTURE, def_geo_attribute_sample_texture, "ATTRIBUTE_SAMPLE_TEXTURE", AttributeSampleTexture, "Attribute Sample Texture", "")
DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_SAMPLE_TEXTURE, 0, "ATTRIBUTE_SAMPLE_TEXTURE", AttributeSampleTexture, "Attribute Sample Texture", "")
DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_SEPARATE_XYZ, def_geo_attribute_separate_xyz, "ATTRIBUTE_SEPARATE_XYZ", AttributeSeparateXYZ, "Attribute Separate XYZ", "")
DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_TRANSFER, def_geo_attribute_transfer, "ATTRIBUTE_TRANSFER", AttributeTransfer, "Attribute Transfer", "")
DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_VECTOR_MATH, def_geo_attribute_vector_math, "ATTRIBUTE_VECTOR_MATH", AttributeVectorMath, "Attribute Vector Math", "")

View File

@ -30,6 +30,7 @@
static bNodeSocketTemplate geo_node_attribute_sample_texture_in[] = {
{SOCK_GEOMETRY, N_("Geometry")},
{SOCK_TEXTURE, N_("Texture")},
{SOCK_STRING, N_("Mapping")},
{SOCK_STRING, N_("Result")},
{-1, ""},
@ -40,13 +41,6 @@ static bNodeSocketTemplate geo_node_attribute_sample_texture_out[] = {
{-1, ""},
};
static void geo_node_attribute_sample_texture_layout(uiLayout *layout,
bContext *C,
PointerRNA *ptr)
{
uiTemplateID(layout, C, ptr, "texture", "texture.new", nullptr, nullptr, 0, ICON_NONE, nullptr);
}
namespace blender::nodes {
static AttributeDomain get_result_domain(const GeometryComponent &component,
@ -71,8 +65,7 @@ static AttributeDomain get_result_domain(const GeometryComponent &component,
static void execute_on_component(GeometryComponent &component, const GeoNodeExecParams &params)
{
const bNode &node = params.node();
Tex *texture = reinterpret_cast<Tex *>(node.id);
Tex *texture = params.get_input<Tex *>("Texture");
if (texture == nullptr) {
return;
}
@ -144,6 +137,5 @@ void register_node_type_geo_sample_texture()
node_type_socket_templates(
&ntype, geo_node_attribute_sample_texture_in, geo_node_attribute_sample_texture_out);
ntype.geometry_node_execute = blender::nodes::geo_node_attribute_sample_texture_exec;
ntype.draw_buttons = geo_node_attribute_sample_texture_layout;
nodeRegisterType(&ntype);
}