1

我像这样导入了我的 Object3D:

var globalObject; // this is a global object

var loader = new THREE.ObjectLoader();
loader.load('path/to/object3d.json', function(object) {
    globalObject = object;
    scene.add(globalObject);
});

我想要实现的是,当用户单击按钮时,整个对象的某些 Mesh 元素会获得纹理。我这样做:

// on button click {
    for(var i in globalObject.children) {
        // apply to Mesh of interest {
            var texture = THREE.ImageUtils.loadTexture('path/to/image.jpg');
            globalObject.children[i].material = new THREE.MeshLambertMaterial({map: texture, needsUpdate: true});
        } // end apply to Mesh of interest
    }
} // end on button click

就设置纹理而言,上面的代码似乎有效。这里的问题是纹理看起来有点扭曲。看起来像这样http://db.tt/S5VEsByd

如何纠正这个问题,以便将完整的纹理应用于两个表面?

4

1 回答 1

4

这应该可以解决问题:

// on button click {
    for(var i in globalObject.children) {
        // apply to Mesh of interest {
            var texture = THREE.ImageUtils.loadTexture('path/to/image.jpg');
            texture.wrapS = THREE.RepeatWrapping;
            texture.wrapT = THREE.RepeatWrapping;
            globalObject.children[i].material = new THREE.MeshLambertMaterial({map: texture, needsUpdate: true});
        } // end apply to Mesh of interest
    }
} // end on button click
于 2013-09-04T22:24:49.653 回答