mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Merge pull request #94482 from pablitar/3.x
[3.x] Fix external images getting embedded on import
This commit is contained in:
commit
b58d16f0b8
2 changed files with 18 additions and 8 deletions
|
@ -3106,6 +3106,7 @@ Error GLTFDocument::_parse_images(Ref<GLTFState> p_state, const String &p_base_p
|
||||||
Ref<Texture> texture = ResourceLoader::load(uri);
|
Ref<Texture> texture = ResourceLoader::load(uri);
|
||||||
if (texture.is_valid()) {
|
if (texture.is_valid()) {
|
||||||
p_state->images.push_back(texture->get_data());
|
p_state->images.push_back(texture->get_data());
|
||||||
|
p_state->external_images_paths.insert(i, uri);
|
||||||
continue;
|
continue;
|
||||||
} else if (mimetype == "image/png" || mimetype == "image/jpeg") {
|
} else if (mimetype == "image/png" || mimetype == "image/jpeg") {
|
||||||
// Fallback to loading as byte array.
|
// Fallback to loading as byte array.
|
||||||
|
@ -3234,17 +3235,25 @@ Error GLTFDocument::_parse_textures(Ref<GLTFState> p_state) {
|
||||||
}
|
}
|
||||||
p_state->textures.push_back(t);
|
p_state->textures.push_back(t);
|
||||||
|
|
||||||
|
Ref<Texture> tex;
|
||||||
|
|
||||||
// Create and cache the texture used in the engine
|
// Create and cache the texture used in the engine
|
||||||
Ref<ImageTexture> imgTex;
|
if (p_state->external_images_paths.has(t->get_src_image())) {
|
||||||
imgTex.instance();
|
tex = ResourceLoader::load(p_state->external_images_paths[t->get_src_image()]);
|
||||||
imgTex->create_from_image(p_state->images[t->get_src_image()]);
|
} else {
|
||||||
|
Ref<ImageTexture> img_tex;
|
||||||
|
img_tex.instance();
|
||||||
|
img_tex->create_from_image(p_state->images[t->get_src_image()]);
|
||||||
|
|
||||||
// Set texture filter and repeat based on sampler settings
|
// Set texture filter and repeat based on sampler settings. Only supported for embedded textures
|
||||||
const Ref<GLTFTextureSampler> sampler = _get_sampler_for_texture(p_state, i);
|
const Ref<GLTFTextureSampler> sampler = _get_sampler_for_texture(p_state, i);
|
||||||
Texture::Flags flags = sampler->get_texture_flags();
|
Texture::Flags flags = sampler->get_texture_flags();
|
||||||
imgTex->set_flags(flags);
|
img_tex->set_flags(flags);
|
||||||
|
|
||||||
p_state->texture_cache.insert(i, imgTex);
|
tex = img_tex;
|
||||||
|
}
|
||||||
|
|
||||||
|
p_state->texture_cache.insert(i, tex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
|
|
|
@ -78,6 +78,7 @@ class GLTFState : public Resource {
|
||||||
Vector<Ref<GLTFTextureSampler>> texture_samplers;
|
Vector<Ref<GLTFTextureSampler>> texture_samplers;
|
||||||
Ref<GLTFTextureSampler> default_texture_sampler;
|
Ref<GLTFTextureSampler> default_texture_sampler;
|
||||||
Vector<Ref<Image>> images;
|
Vector<Ref<Image>> images;
|
||||||
|
Map<GLTFImageIndex, String> external_images_paths;
|
||||||
Map<GLTFTextureIndex, Ref<Texture>> texture_cache;
|
Map<GLTFTextureIndex, Ref<Texture>> texture_cache;
|
||||||
Vector<String> extensions_used;
|
Vector<String> extensions_used;
|
||||||
Vector<String> extensions_required;
|
Vector<String> extensions_required;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue