Merge pull request #109375 from ColinSORourke/VisualShaderEmbedHandling

Fix VisualShader Conversion failing with subresources
This commit is contained in:
Thaddeus Crews 2025-09-19 09:17:10 -05:00
commit 2753d333f6
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
5 changed files with 54 additions and 2 deletions

View file

@ -967,6 +967,37 @@ void VisualShader::set_node_position(Type p_type, int p_id, const Vector2 &p_pos
g->nodes[p_id].position = p_position;
}
// Returns 0 if no embeds, 1 if external embeds, 2 if builtin embeds
int VisualShader::has_node_embeds() const {
bool external_embeds = false;
for (int i = 0; i < TYPE_MAX; i++) {
for (const KeyValue<int, Node> &E : graph[i].nodes) {
List<PropertyInfo> props;
E.value.node->get_property_list(&props);
// For classes that inherit from VisualShaderNode, the class properties start at the 12th, and the last value is always 'script'
for (int j = 12; j < props.size() - 1; j++) {
// VisualShaderNodeCustom cannot have embeds
if (props.get(j).name == "VisualShaderNodeCustom") {
break;
}
// Ref<Resource> properties get classed as type Variant::Object
if (props.get(j).type == Variant::OBJECT) {
Ref<Resource> res = E.value.node->get(props.get(j).name);
if (res.is_valid()) {
if (res->is_built_in()) {
return 2;
} else {
external_embeds = true;
}
}
}
}
}
}
return external_embeds;
}
Vector2 VisualShader::get_node_position(Type p_type, int p_id) const {
ERR_FAIL_INDEX_V(p_type, TYPE_MAX, Vector2());
const Graph *g = &graph[p_type];

View file

@ -183,6 +183,7 @@ public: // internal methods
void add_node(Type p_type, const Ref<VisualShaderNode> &p_node, const Vector2 &p_position, int p_id);
void set_node_position(Type p_type, int p_id, const Vector2 &p_position);
int has_node_embeds() const;
void add_varying(const String &p_name, VaryingMode p_mode, VaryingType p_type);
void remove_varying(const String &p_name);