Merge pull request #5888 from ynput/bugfix/blender-fix_pack_image

Blender: Fix blend extraction and packed images
This commit is contained in:
Simone Barbieri 2023-11-09 09:45:57 +00:00 committed by GitHub
commit 1fa9ecdcd3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -28,16 +28,22 @@ class ExtractBlend(publish.Extractor):
for obj in instance:
data_blocks.add(obj)
# Pack used images in the blend files.
if obj.type == 'MESH':
for material_slot in obj.material_slots:
mat = material_slot.material
if mat and mat.use_nodes:
tree = mat.node_tree
if tree.type == 'SHADER':
for node in tree.nodes:
if node.bl_idname == 'ShaderNodeTexImage':
if node.image:
node.image.pack()
if obj.type != 'MESH':
continue
for material_slot in obj.material_slots:
mat = material_slot.material
if not(mat and mat.use_nodes):
continue
tree = mat.node_tree
if tree.type != 'SHADER':
continue
for node in tree.nodes:
if node.bl_idname != 'ShaderNodeTexImage':
continue
# Check if image is not packed already
# and pack it if not.
if node.image and node.image.packed_file is None:
node.image.pack()
bpy.data.libraries.write(filepath, data_blocks)