question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Textures not exported by python script

See original GitHub issue

Describe the bug I use the following script to export to GLTF:

import bpy
import sys
from pathlib import Path

argv = sys.argv
argv = argv[argv.index("--") + 1 :]  # get all args after "--"

filename = Path(argv[0])

bpy.ops.wm.open_mainfile(filepath=str(filename))
bpy.ops.export_scene.gltf(
    filepath=str(filename.with_suffix(".gltf")),
    export_format="GLTF_EMBEDDED",
    export_yup=True,
)

With the default blender cube with any texture applied, I get the following, and the export file doesn’t contain the texture:

Blender 2.93.5 (hash a791bdabd0b2 built 2021-10-13 00:53:14)
Read prefs: /home//.config/blender/2.93/config/userpref.blend
Read blend: models/untitled.blend
'/usr/bin/2.93/python/lib/python3.9/site-packages/libextern_draco.so' does not exist, draco mesh compression not available
10:31:49 | INFO: Starting glTF 2.0 export
10:31:49 | INFO: Extracting primitive: Cube
10:31:49 | INFO: Primitives created: 1
10:31:49 | WARNING: Image '<bpy_struct, Image("ds5.png") at 0x7f7e23485408>' has no color channels and cannot be exported.
10:31:49 | INFO: Finished glTF 2.0 export in 0.004320383071899414 s

It works fine if I export using the GUI. Am I missing something?

To Reproduce Steps to reproduce the behavior:

  1. Create new blender file, add a cube, add a texture to the cube.
  2. Run blender --background --python export.py -- <model>.blend
  3. Open the gltf file and list the textures

Expected behavior The gui and python script should both generate the same result.

Version

  • OS: archlinux
  • Blender Version: 2.93.5

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

2reactions
juliendurourecommented, Feb 6, 2022
2reactions
juliendurourecommented, Dec 13, 2021

Not sure what I did last time, but I can reproduce now. Seems to be an Blender API issue, that doesn’t retrieve texture (and even some node) correctly when used in background. I will open some issue in Blender tracker.

Read more comments on GitHub >

github_iconTop Results From Across the Web

OBJ + MTL import not exporting textures on .FBX in batch ...
I am importing a OBJ that has an corresponding MTL file in its folder. In Blender I am able to view this texture...
Read more >
[Python Script] Have trouble to export textures us... - 13371649
Currently, I'm using Substance 3D Painter 8.2 to do some export jobs. But I Found I couldn't use my previous code that worked...
Read more >
How can I determine with script which textures are attached to ...
I can import the fbx files, find the redundant materials, but I cannot figure out which textures are attached to the materials, ...
Read more >
Export textures only - Agisoft Metashape
Hello Thibaud, The error message indicates that you cannot create PhotoScan.Chunk() instances, you need to use doc.addChunk() option. The script ...
Read more >
How to export as png an image texture - Blender Artists
The idea is to read all images of a blend file and then export as PNG or JPG as thumbnails. Really the source...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found