Nodes: add boilerplate for image sockets
The sockets are not exposed in any nodes yet. They work similar to the Object/Collection/Texture sockets, which also just reference a data block. Based on rB207472930834 Reviewed By: JacquesLucke Differential Revision: https://developer.blender.org/D12861
This commit is contained in:

committed by
Charlie Jolly

parent
138aa20959
commit
25a255c32a
@@ -916,6 +916,9 @@ static void create_inspection_string_for_generic_value(const geo_log::GenericVal
|
|||||||
else if (type.is<Tex *>()) {
|
else if (type.is<Tex *>()) {
|
||||||
id_to_inspection_string((ID *)*value.get<Tex *>(), ID_TE);
|
id_to_inspection_string((ID *)*value.get<Tex *>(), ID_TE);
|
||||||
}
|
}
|
||||||
|
else if (type.is<Image *>()) {
|
||||||
|
id_to_inspection_string((ID *)*value.get<Image *>(), ID_IM);
|
||||||
|
}
|
||||||
else if (type.is<Collection *>()) {
|
else if (type.is<Collection *>()) {
|
||||||
id_to_inspection_string((ID *)*value.get<Collection *>(), ID_GR);
|
id_to_inspection_string((ID *)*value.get<Collection *>(), ID_GR);
|
||||||
}
|
}
|
||||||
|
@@ -151,6 +151,12 @@ static void addIdsUsedBySocket(const ListBase *sockets, Set<ID *> &ids)
|
|||||||
ids.add(&texture->id);
|
ids.add(&texture->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (socket->type == SOCK_IMAGE) {
|
||||||
|
Image *image = ((bNodeSocketValueImage *)socket->default_value)->value;
|
||||||
|
if (image != nullptr) {
|
||||||
|
ids.add(&image->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,6 +242,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
|
|||||||
add_collection_relation(ctx, *collection);
|
add_collection_relation(ctx, *collection);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case ID_IM:
|
||||||
case ID_TE: {
|
case ID_TE: {
|
||||||
DEG_add_generic_id_relation(ctx->node, id, "Nodes Modifier");
|
DEG_add_generic_id_relation(ctx->node, id, "Nodes Modifier");
|
||||||
}
|
}
|
||||||
@@ -420,6 +427,12 @@ static IDProperty *id_property_create_from_socket(const bNodeSocket &socket)
|
|||||||
idprop.id = (ID *)value->value;
|
idprop.id = (ID *)value->value;
|
||||||
return IDP_New(IDP_ID, &idprop, socket.identifier);
|
return IDP_New(IDP_ID, &idprop, socket.identifier);
|
||||||
}
|
}
|
||||||
|
case SOCK_IMAGE: {
|
||||||
|
bNodeSocketValueImage *value = (bNodeSocketValueImage *)socket.default_value;
|
||||||
|
IDPropertyTemplate idprop = {0};
|
||||||
|
idprop.id = (ID *)value->value;
|
||||||
|
return IDP_New(IDP_ID, &idprop, socket.identifier);
|
||||||
|
}
|
||||||
case SOCK_MATERIAL: {
|
case SOCK_MATERIAL: {
|
||||||
bNodeSocketValueMaterial *value = (bNodeSocketValueMaterial *)socket.default_value;
|
bNodeSocketValueMaterial *value = (bNodeSocketValueMaterial *)socket.default_value;
|
||||||
IDPropertyTemplate idprop = {0};
|
IDPropertyTemplate idprop = {0};
|
||||||
@@ -448,6 +461,7 @@ static bool id_property_type_matches_socket(const bNodeSocket &socket, const IDP
|
|||||||
case SOCK_OBJECT:
|
case SOCK_OBJECT:
|
||||||
case SOCK_COLLECTION:
|
case SOCK_COLLECTION:
|
||||||
case SOCK_TEXTURE:
|
case SOCK_TEXTURE:
|
||||||
|
case SOCK_IMAGE:
|
||||||
case SOCK_MATERIAL:
|
case SOCK_MATERIAL:
|
||||||
return property.type == IDP_ID;
|
return property.type == IDP_ID;
|
||||||
}
|
}
|
||||||
@@ -517,6 +531,12 @@ static void init_socket_cpp_value_from_property(const IDProperty &property,
|
|||||||
*(Tex **)r_value = texture;
|
*(Tex **)r_value = texture;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case SOCK_IMAGE: {
|
||||||
|
ID *id = IDP_Id(&property);
|
||||||
|
Image *image = (id && GS(id->name) == ID_IM) ? (Image *)id : nullptr;
|
||||||
|
*(Image **)r_value = image;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case SOCK_MATERIAL: {
|
case SOCK_MATERIAL: {
|
||||||
ID *id = IDP_Id(&property);
|
ID *id = IDP_Id(&property);
|
||||||
Material *material = (id && GS(id->name) == ID_MA) ? (Material *)id : nullptr;
|
Material *material = (id && GS(id->name) == ID_MA) ? (Material *)id : nullptr;
|
||||||
@@ -1145,6 +1165,10 @@ static void draw_property_for_socket(uiLayout *layout,
|
|||||||
uiItemPointerR(layout, md_ptr, rna_path, bmain_ptr, "textures", socket.name, ICON_TEXTURE);
|
uiItemPointerR(layout, md_ptr, rna_path, bmain_ptr, "textures", socket.name, ICON_TEXTURE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case SOCK_IMAGE: {
|
||||||
|
uiItemPointerR(layout, md_ptr, rna_path, bmain_ptr, "images", socket.name, ICON_IMAGE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
if (input_has_attribute_toggle(*nmd->node_group, socket_index)) {
|
if (input_has_attribute_toggle(*nmd->node_group, socket_index)) {
|
||||||
const std::string rna_path_use_attribute = "[\"" + std::string(socket_id_esc) +
|
const std::string rna_path_use_attribute = "[\"" + std::string(socket_id_esc) +
|
||||||
|
@@ -193,6 +193,13 @@ class Texture : public IDSocketDeclaration {
|
|||||||
Texture();
|
Texture();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Image : public IDSocketDeclaration {
|
||||||
|
public:
|
||||||
|
using Builder = SocketDeclarationBuilder<Image>;
|
||||||
|
|
||||||
|
Image();
|
||||||
|
};
|
||||||
|
|
||||||
class Geometry : public SocketDeclaration {
|
class Geometry : public SocketDeclaration {
|
||||||
public:
|
public:
|
||||||
using Builder = SocketDeclarationBuilder<Geometry>;
|
using Builder = SocketDeclarationBuilder<Geometry>;
|
||||||
@@ -339,6 +346,10 @@ inline Texture::Texture() : IDSocketDeclaration("NodeSocketTexture")
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Image::Image() : IDSocketDeclaration("NodeSocketImage")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/** \} */
|
/** \} */
|
||||||
|
|
||||||
} // namespace blender::nodes::decl
|
} // namespace blender::nodes::decl
|
||||||
|
@@ -109,6 +109,7 @@ static bool geometry_node_tree_socket_type_valid(bNodeTreeType *UNUSED(ntreetype
|
|||||||
SOCK_GEOMETRY,
|
SOCK_GEOMETRY,
|
||||||
SOCK_COLLECTION,
|
SOCK_COLLECTION,
|
||||||
SOCK_TEXTURE,
|
SOCK_TEXTURE,
|
||||||
|
SOCK_IMAGE,
|
||||||
SOCK_MATERIAL);
|
SOCK_MATERIAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -808,6 +808,7 @@ static bNodeSocketType *make_socket_type_string()
|
|||||||
MAKE_CPP_TYPE(Object, Object *, CPPTypeFlags::BasicType)
|
MAKE_CPP_TYPE(Object, Object *, CPPTypeFlags::BasicType)
|
||||||
MAKE_CPP_TYPE(Collection, Collection *, CPPTypeFlags::BasicType)
|
MAKE_CPP_TYPE(Collection, Collection *, CPPTypeFlags::BasicType)
|
||||||
MAKE_CPP_TYPE(Texture, Tex *, CPPTypeFlags::BasicType)
|
MAKE_CPP_TYPE(Texture, Tex *, CPPTypeFlags::BasicType)
|
||||||
|
MAKE_CPP_TYPE(Image, Image *, CPPTypeFlags::BasicType)
|
||||||
MAKE_CPP_TYPE(Material, Material *, CPPTypeFlags::BasicType)
|
MAKE_CPP_TYPE(Material, Material *, CPPTypeFlags::BasicType)
|
||||||
|
|
||||||
static bNodeSocketType *make_socket_type_object()
|
static bNodeSocketType *make_socket_type_object()
|
||||||
@@ -858,6 +859,18 @@ static bNodeSocketType *make_socket_type_texture()
|
|||||||
return socktype;
|
return socktype;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bNodeSocketType *make_socket_type_image()
|
||||||
|
{
|
||||||
|
bNodeSocketType *socktype = make_standard_socket_type(SOCK_IMAGE, PROP_NONE);
|
||||||
|
socktype->get_base_cpp_type = []() { return &blender::fn::CPPType::get<Image *>(); };
|
||||||
|
socktype->get_base_cpp_value = [](const bNodeSocket &socket, void *r_value) {
|
||||||
|
*(Image **)r_value = ((bNodeSocketValueImage *)socket.default_value)->value;
|
||||||
|
};
|
||||||
|
socktype->get_geometry_nodes_cpp_type = socktype->get_base_cpp_type;
|
||||||
|
socktype->get_geometry_nodes_cpp_value = socktype->get_base_cpp_value;
|
||||||
|
return socktype;
|
||||||
|
}
|
||||||
|
|
||||||
static bNodeSocketType *make_socket_type_material()
|
static bNodeSocketType *make_socket_type_material()
|
||||||
{
|
{
|
||||||
bNodeSocketType *socktype = make_standard_socket_type(SOCK_MATERIAL, PROP_NONE);
|
bNodeSocketType *socktype = make_standard_socket_type(SOCK_MATERIAL, PROP_NONE);
|
||||||
@@ -906,14 +919,14 @@ void register_standard_node_socket_types(void)
|
|||||||
|
|
||||||
nodeRegisterSocketType(make_socket_type_object());
|
nodeRegisterSocketType(make_socket_type_object());
|
||||||
|
|
||||||
nodeRegisterSocketType(make_standard_socket_type(SOCK_IMAGE, PROP_NONE));
|
|
||||||
|
|
||||||
nodeRegisterSocketType(make_socket_type_geometry());
|
nodeRegisterSocketType(make_socket_type_geometry());
|
||||||
|
|
||||||
nodeRegisterSocketType(make_socket_type_collection());
|
nodeRegisterSocketType(make_socket_type_collection());
|
||||||
|
|
||||||
nodeRegisterSocketType(make_socket_type_texture());
|
nodeRegisterSocketType(make_socket_type_texture());
|
||||||
|
|
||||||
|
nodeRegisterSocketType(make_socket_type_image());
|
||||||
|
|
||||||
nodeRegisterSocketType(make_socket_type_material());
|
nodeRegisterSocketType(make_socket_type_material());
|
||||||
|
|
||||||
nodeRegisterSocketType(make_socket_type_virtual());
|
nodeRegisterSocketType(make_socket_type_virtual());
|
||||||
|
@@ -467,6 +467,14 @@ static int node_datatype_priority(eNodeSocketDatatype from, eNodeSocketDatatype
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case SOCK_IMAGE: {
|
||||||
|
switch (from) {
|
||||||
|
case SOCK_IMAGE:
|
||||||
|
return 1;
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
case SOCK_MATERIAL: {
|
case SOCK_MATERIAL: {
|
||||||
switch (from) {
|
switch (from) {
|
||||||
case SOCK_MATERIAL:
|
case SOCK_MATERIAL:
|
||||||
|
Reference in New Issue
Block a user