用three.js更新纹理

问题描述 投票:0回答:1

我在three.js中有一个纹理化的模型,我希望能够在页面加载时交换出.gltf文件中定义的纹理。我一直在here寻找灵感。

"images": [
{
  "uri": "flat_baseColor.png"
},
// etc

所以我要更新纹理

var images = [
"./textures/01.jpg",
//  "./textures/01.jpg",
];


var texture = new THREE.TextureLoader().load( images[0] );

var my_material = new THREE.MeshBasicMaterial({map: texture});

// load the model
var loader = new GLTFLoader().setPath( 'models/gltf/' ); // trex
loader.load( 'creature_posed.gltf', function ( gltf ) 
{
    gltf.scene.traverse( function ( child )
    {
        if ( child.isMesh )
        {
            // The textures go for a double flip, I have no idea why
            // Texture compensation
            texture.flipX = false;
            texture.flipY = false;
            child.material = my_material;
            texture.needsUpdate = true;
        }
    } );


    var model = gltf.scene;

仅纹理相当苍白。 :(texture ob model before and after update

我已经对其进行了测试,因此它不是纹理)。错过了什么?

three.js textures
1个回答
0
投票

[加载纹理时,您需要注意色彩空间:如果纹理具有颜色数据(例如.map.emissiveMap),则可能是sRGB。

texture.encoding = THREE.sRGBEncoding;

请参见GLTFLoader docscolor management in three.js。这也假定renderer.outputEncoding = THREE.sRGBEncoding

three.js r113

© www.soinside.com 2019 - 2024. All rights reserved.