Skip to content

Commit

Permalink
Unused Texture via user extension
Browse files Browse the repository at this point in the history
  • Loading branch information
julienduroure committed Nov 20, 2023
1 parent a5a3a49 commit 6f8922f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
7 changes: 5 additions & 2 deletions addons/io_scene_gltf2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,11 @@ def __init__(self):
default=False)

export_unused_textures: BoolProperty(
name='Unused textures',
description='Export image texture nodes not assigned to any material',
name='Prepare Unused textures',
description=(
'Export image texture nodes not assigned to any material.'
'This feature is not standard, need an external extension to be included in the glTF file'
),
default=False)

export_colors: BoolProperty(
Expand Down
13 changes: 9 additions & 4 deletions addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,15 @@ def __export(export_settings):
additional_json_textures = fix_json([i.to_dict() for i in exporter.additional_data.additional_textures])

# Now that we have the final json, we can add the additional data
if len(additional_json_textures) > 0:
if json.get('extras') is None:
json['extras'] = {}
json['extras']['additionalTextures'] = additional_json_textures
# We can not do that for all people, because we don't want this extra to become "a standard"
# So let's use the "extras" field filled by a user extension

export_user_extensions('gather_gltf_additional_textures_hook', export_settings, json, additional_json_textures)

# if len(additional_json_textures) > 0:
# if json.get('extras') is None:
# json['extras'] = {}
# json['extras']['additionalTextures'] = additional_json_textures

return json, buffer

Expand Down
1 change: 1 addition & 0 deletions example-addons/example_gltf_exporter_extension/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ gather_animation_object_sampled_channel_target_hook(self, blender_object, channe
gather_attribute_keep(self, keep_attribute, export_settings)
gather_attribute_change(self, attribute, data, is_normalized_byte_color, export_settings)
gather_attributes_change(self, attributes, export_settings)
gather_gltf_additional_textures_hook(self, json, additioan_json_textures, export_settings)
```
4 changes: 3 additions & 1 deletion tests/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2150,7 +2150,8 @@ describe('Exporter', function() {
assert.strictEqual(asset.textures.length, 20);
});

it('exports addtional textures & images', function() {
// These tests are disabled because they require an user extension to be registered
/*it('exports addtional textures & images', function() {
let gltfPath_1 = path.resolve(outDirPath, '33_unused_texture_and_image.gltf');
var asset = JSON.parse(fs.readFileSync(gltfPath_1));
Expand All @@ -2169,6 +2170,7 @@ describe('Exporter', function() {
assert.strictEqual(asset.materials.length, 1);
assert.strictEqual(asset.extras['additionalTextures'].length, 1);
});
*/

it('exports addtional images', function() {
let gltfPath_1 = path.resolve(outDirPath, '33_unused_image.gltf');
Expand Down

0 comments on commit 6f8922f

Please sign in to comment.