Threejs更新从Blender导出的模型的UV贴图

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

我正在使用Blender在Blender中创建一些表格模型,并使用UV贴图应用纹理并使用GLTF导出。当我使用gltf加载程序并加载对象并将其添加到场景时,它可以正常工作。

代码:

  var container, scene, camera, renderer, controls, stats;
  var Table;
    // SCENE
     scene = new THREE.Scene();
    // CAMERA
    var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight;
    var VIEW_ANGLE = 45, ASPECT = SCREEN_WIDTH / SCREEN_HEIGHT, NEAR = 0.1, FAR = 20000;
    camera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR);
    scene.add(camera);
    camera.position.set(2,2,5);
    camera.lookAt(scene.position);  
    // RENDERER
    if ( Detector.webgl )
        renderer = new THREE.WebGLRenderer( {antialias:true} );
    else
        renderer = new THREE.CanvasRenderer(); 
    renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
    container = document.getElementById( 'webgl' );
    container.appendChild( renderer.domElement );
    // CONTROLS
    controls = new THREE.OrbitControls( camera, renderer.domElement );
    // EVENTS


    // STATS
    stats = new Stats();
    stats.domElement.style.position = 'absolute';
    stats.domElement.style.bottom = '0px';
    stats.domElement.style.zIndex = 100;
    container.appendChild( stats.domElement );

    // LIGHT
    var light = new THREE.PointLight(0xffffff,1);
    light.position.set(-2,3,-3);
    scene.add(light);

    var ambient = new THREE.AmbientLight( 0xffffff, 3.9);
    scene.add( ambient );

    var loader = new THREE.GLTFLoader();
    loader.load( './Model/table.glb',
        function ( gltf ) {
            gltf.scene.traverse( function ( node ) {
                           if(node.isMesh ){
                  if(node.name==="Table"){
                                 Table = node;
                  }                                                          
               }

        });
              scene.add(gltf.scene);

        });

     },
     function ( xhr ) {
        console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
     },
     function ( error ) {
        console.log( 'An error happened---' +error);
     }
    );

型号:请在此处查看型号https://github.com/SourceCodeZone/Model/blob/master/table.glb

UV MAPenter image description here

结果enter image description here

而且问题出在我尝试从threejs方面更改模型时,

我在下面的代码中使用过

    var textureLoader = new THREE.TextureLoader();
    textureLoader.load( "./Texture/table/Table-map-new.png", function ( map ) {
        Table.material.map = map;

        Table.material.needsUpdate = true;
    });

并且我使用的纹理与搅拌机中使用的纹理相同,但颜色不同enter image description here

结果似乎没有对齐的纹理,可能是问题所在。enter image description here

three.js blender texture-mapping gltf uv-mapping
1个回答
0
投票

根据there.js documentation,问题出在代码中

GLTFLoader将自动正确配置从.gltf或.glb文件引用的纹理,并假定渲染器的设置如上所述。当从外部加载纹理(例如,使用TextureLoader)并将其应用于glTF模型时,必须提供色彩空间和方向:

// If texture is used for color information, set colorspace.
texture.encoding = THREE.sRGBEncoding;

// UVs use the convention that (0, 0) corresponds to the upper left corner of a texture.
texture.flipY = false;
© www.soinside.com 2019 - 2024. All rights reserved.