2013-07-18 45 views
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; 
} 

回答

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]); 
} 
相關問題