-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Texture bug on r137 #23353
Comments
This issue is related to the latest The problem is that your asset is blended with the HTML background since for some reasons the DDS texture holds alpha values < 1. One workaround to solve the issue is to add this block to your object.traverse( function ( child ) {
if ( child.material ) child.material.alphaWrite = false;
} ); This will define the material as opaque by setting a |
Here is a complete code example that should load the sword as expected. Note that since import * as THREE from 'three';
import { MTLLoader } from './jsm/loaders/MTLLoader.js';
import { OBJLoader } from './jsm/loaders/OBJLoader.js';
import { DDSLoader } from './jsm/loaders/DDSLoader.js';
import { OrbitControls } from './jsm/controls/OrbitControls.js';
let camera, scene, renderer;
init();
animate();
function init() {
const container = document.createElement( 'div' );
document.body.appendChild( container );
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
camera.position.set( 250, 250, 0 );
camera.lookAt( 0, 0, 0 );
// scene
scene = new THREE.Scene();
scene.background = new THREE.Color( 0xcccccc );
const ambientLight = new THREE.AmbientLight( 0xcccccc, 0.4 );
scene.add( ambientLight );
const pointLight = new THREE.PointLight( 0xffffff, 0.8 );
camera.add( pointLight );
scene.add( camera );
// model
const manager = new THREE.LoadingManager();
manager.addHandler( /\.dds$/i, new DDSLoader() );
new MTLLoader( manager )
.setPath( 'models/obj/temp1/' )
.load( '00270.mtl', function ( materials ) {
materials.preload();
new OBJLoader( manager )
.setMaterials( materials )
.setPath( 'models/obj/temp1/' )
.load( '00270.obj', function ( object ) {
object.traverse( function ( child ) {
if ( child.material ) child.material.alphaWrite = false;
} );
scene.add( object );
} );
} );
//
//
renderer = new THREE.WebGLRenderer();
renderer.outputEncoding = THREE.sRGBEncoding;
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
//
window.addEventListener( 'resize', onWindowResize );
const controls = new OrbitControls( camera, renderer.domElement );
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
//
function animate() {
requestAnimationFrame( animate );
render();
}
function render() {
renderer.render( scene, camera );
} |
Perfect, it worked. I was reading the migration guide but I wasn't able to pinpoint where the problem was coming from. Thank you. |
Makes me wonder if this line:
Should be this instead: alphaWrite: material.alphaWrite && material.transparent, This stuff hurts my brain a bit. /cc @donmccurdy |
I've added a note that But I fear many user will not understand that 3D objects are potentially blended with the HTML background and thus don't understand the note in the migration guide. It seems these cases will require some support. |
It didn't work, I edited it on the node_modules folder, also tried setting it to false, it stayed the same... (I kept the sRGBEncoding, only removed the alphaWrite's on the my side). |
Oh, hmm... Then maybe the problem is that Maybe if |
Having a different value of |
You're right: https://jsfiddle.net/zfgebmux/ |
So if |
Maybe we should reconsider #23166 (comment) for a long-term and glTF compliant solution. |
Hmm, I already tried that. And now that we are setting |
As far as I can see the only issue of #18631 is that it broke this use case:
In this new world of And then we'll be able to get rid of |
Fixed: https://jsfiddle.net/wsuhyr52/ 😬 |
@Karbust If you update to |
Correct, it's working without alphaWrite. Thank you |
Describe the bug
DDS and PNG textures lose all color, I don't know how to really explain, I attached screenshots bellow. Since I only use these 2 types of textures, I can't test other types.
If the browser has DDS support, it will be used, otherwise fallback to PNG. This happens on all browsers and devices I tested.
To Reproduce
Steps to reproduce the behavior:
Go to either of the live examples below and press on a weapon or amor icon, the differences will be visible.
Code
A code snippet of how I'm using it.
Live example
Screenshots
Public version with r136:

Dev version with r137

Platform:
The text was updated successfully, but these errors were encountered: