0

我目前正在为球体几何的每个球面加载不同的纹理,目前它从上到下加载纹理。无论如何要在球体中间开始加载纹理并继续向外?

仅供参考,这就是我目前为每个球面分配纹理的方式

var sphere  = new THREE.SphereGeometry( 250, geo_width, geo_height );   

var materials = []; 
for( var y = 0; y < geo_height; y++ ){
    for( var x = 0; x < geo_width; x++ ){
        materials.push( loadTexture('getImage.php?x=' + x + '&y=' + y + '&zoom=2&type=' + type ) );
    }   
}   

for( var i = 0; i < sphere.faces.length; i++ ){
    sphere.faces[ i ].materialIndex = i;
}   
4

1 回答 1

1

是的,你可以这样做。首先,您应该按照要显示它们的顺序开始加载纹理。在您的情况下,您需要更改循环,以首先加载球体中间的纹理。

var materials = new Array(geo_height*geo_width);
// loading middle part of textures
for( var y = yFrom; y < yTo; y++ ){
    for( var x = xFrom; x < xTo; x++ ){
        materials[y * geo_width + x] = loadTexture('getImage.php?x=' + x + '&y=' + y + '&zoom=2&type=' + type );
    }
}
// loading other textures
for( var y = 0; y < geo_height; y++ ){
    for( var x = 0; x < geo_width; x++ ){
        if (materials[y * geo_width + x] == undefined)
            materials[y * geo_width + x] = loadTexture('getImage.php?x=' + x + '&y=' + y + '&zoom=2&type=' + type );
    }
}

有时,如果您想确保某些纹理在其他纹理之前加载,您可以使用加载回调函数来同步它们。为此目的使用 Imageutils.loadTexture(url, mapping, onLoad, onError)。例如,按包加载纹理:

function loadTexturesPack(texturesPack, cb) {
    var count = 0,
        textures = [],
        onLoad = function() {
            count++;
            if (count == texturesPack.length) 
                cb(textures);
        };
    for (var i = 0; i < texturesPack.length; i++) {
        textures.push(Imageutils.loadTexture(texturesPack.url, null, onLoad));        
    }
}

function loadPacks(packs) {
    var i = 0;
        onLoad = function(textures) {
            i++;   
            // do something with loaded textures  
            // ...      
            // load next texture pack 
            if (i < packs.length) {
                loadTexturesPack(pack[i]);
            }
        };
    loadTexturesPack(pack[0]);
}
于 2013-07-19T07:41:37.947 回答