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.

Material: transparent=true has no effect on glTF materials (since r132)

See original GitHub issue

With Three.js r132 I can no longer make my models transparent. I export Models in Blender (2.92.0) as .glb file. I then import via GLTFLoader and set the opacity in JavaScript. I am also unable to make the object transparent using the three.js editor (drag and drop .glb in the editor).

Steps to reproduce the behavior:

  1. Export “Blender cube” as .glb file
  2. Load the .glb via GLTFLoader
  3. Set opacity/transparency on the MeshStandardMaterial

(expect that model ist transparent)

Code

new GLTFLoader().load("cube.glb", (gltf) => {
    const cube = gltf.scene.getObjectByName("Cube");
    if (
      cube instanceof THREE.Mesh &&
      cube.material instanceof THREE.MeshStandardMaterial
    ) {
      scene.add(cube);
      cube.material.opacity = 0.5;
      cube.material.color.set("#0000ff");
      cube.material.transparent = true;
      cube.material.depthWrite = false;
      cube.material.side = THREE.FrontSide;
    }
  });

Expected behavior

With r131, the sample project looks like this:

r131

https://codesandbox.io/s/threejs-transparency-r131-rth6g

Screenshots

With r132, the sample project looks like this:

r132

https://codesandbox.io/s/threejs-transparency-r132-1hs0v

Platform:

  • Device: Desktop
  • OS: MacOS
  • Browser: Chrome
  • Three.js version: r132.2

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:19 (3 by maintainers)

github_iconTop GitHub Comments

15reactions
donmccurdycommented, Sep 28, 2021

In the latest version you may also need to set material.format = THREE.RGBAFormat to enable transparency. I’m not sure whether that change will remain in future versions though, see https://github.com/mrdoob/three.js/pull/22428#issuecomment-911819793.

4reactions
optimus007commented, Oct 2, 2021

to summarise

  • material.transparent : Boolean // master transparency control BUT _alphaTest will still work if this is false

  • material.opacity : Float 0-1 // Only works if material.format=THREE.RGBAFormat

  • material.alphaMap : greyscale opacity map // works if material.transparent=true & material.format is THREE.RGBAFormat NOTE: GLTF exporter does not export this channel & USDZ exporter does.

  • Alpha channel of material.map // ( transparent png image) will work if material.transparent=true & material.format is irrelevant here

  • material.format : THREE.format // Is THREE.RGBFormat for imported gltf files and is THREE.RGBAFormat when a new THREE.MeshStandardMaterial is created .

  • material._alphaTest : Float 0-1 // clips the transparent part before this threshold value. Side note: this was material.alphaTest before now its material._alphaTest but using matrial.alphaTest still works

is this correct ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Materials not rendering when using GLTFLoader - three.js forum
Using an online renderer (gltf-viewer.donmccurdy.com) to test my model and materials has no effect as the materials are not displayed.
Read more >
Three js glTF imported model's material contains unexpected ...
The property material.format was a temporary change in a few versions of three.js, and has been removed in three.js r137.
Read more >
How to export glTF file with Transparent Textures from Blender
In this blender tutorial, we take a look at how to export a GLTF file with texture transparency.Software and/or plugins used in this ......
Read more >
Understanding how Materials work with glTF models - YouTube
Any questions? Join us in discord: https://discord.com/invite/dFJncWwHunNote: The beginning of this stream is missing audio, but it kicks in ...
Read more >
How to fix missing materials and textures when exporting a ...
In short, if your glTF files exported from Blender don't have textures… ... house had a material assigned, but the material had no...
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