BabylonJS / BabylonJS/BlenderExporter
Proposal: Support `Alpha` settings in material even when image texture's file format is PNG
- Dominant language
- Python
- Stars
- 308
- Forks
- 57
- PR merge metrics
- No merged PRs in 30d
Description
The team and I are encountering a bug where, after exporting, textured-objects are rendered in babylonjs as if they are transparent, i.e. without depth-testing, resulting in overlap.
After some investigation, it's found that material with image textures all have `hasAlpha` set to `true`. I experimented setting alpha to none in the material -> surface panel, without success:

We then tested changing the texture to jpeg, and indeed this fixes the problem. Digging the exporter's source code, I found that in this line:
https://github.com/BabylonJS/BlenderExporter/blob/949d71f7a0d1e53aa768f3da0e6ba3c25022c99d/src/babylon_js/materials/texture.py#L27
and in this line:
https://github.com/BabylonJS/BlenderExporter/blob/949d71f7a0d1e53aa768f3da0e6ba3c25022c99d/src/babylon_js/materials/texture.py#L135
`hasAlpha` is set according only to file format.
I propose that the exporter also supports the `Alpha` option as shown in the above screenshot. I'm not an expert as to what these options map to babylonjs, but at the very least it seems none should mean `hasAlpha: false`.
For our case, bmp and jpeg are not acceptable because:
1. bmp is huge. The size of one of our texture goes from 20KB (png) to 6MP (bmp). While this size might be acceptable for desktop games, this is not really a good fit for games served on the internet
2. jpeg, despite its excellent file size, is lossy
I don't mind contributing. It'd be great if you can provide pointer as to where to grab that `Alpha` settings in the material -> surface panel. Then it should be a matter of switching on the enum values and set to true/false accordingly.
Thanks!
**Info**:
Blender version: 3.6.5
Exporter version: 3.3.2
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in src/babylon_js/materials/texture.py at the referenced lines 27 and 135, then trace how the material Surface panel exposes its Alpha setting. Confirm how the enum values should affect BabylonJS hasAlpha, with PNG textures using false for None; done means the exported material reflects that setting instead of only the file format.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, python
- Domain
- computer-graphics, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100