纹理加载和异步

// 加载纹理方法
function loadImgTexture(geometry, material, imgUrl, callback) {
    var loader = new THREE.TextureLoader();
    loader.load(imgUrl, function(texture) {
        material.map = texture
        var mesh = new THREE.Mesh(geometry, material);
        callback(mesh)
    })
}

 

// 创建地球,并加载纹理
var earthColor = "#44abda"
var earthGeometry = new THREE.SphereGeometry(3, 20, 20);
var earthMaterial = new THREE.MeshBasicMaterial({ color: earthColor });
var earth
loadImgTexture(earthGeometry, earthMaterial, "earth.jpg", function(meshObj) {
    earth = meshObj
    scene.add(earth)
    renderScene()
})

 

纹理加载是异步的,可以把render渲染放到纹理加载完毕后。

posted @ 2018-06-21 15:50  最好的年纪  阅读(401)  评论(0编辑  收藏  举报