2016-02-17 101 views
0

在2d對象的中心/右側/左側顯示貼圖的最簡單方法是什麼?Three.js - 在對象的一部分上顯示紋理貼圖

我試圖玩偏移和重複的紋理,但沒有運氣,我無法找到答案的任何地方。

另外,我已經試過這樣:

 someButton.onClick(function() { 

      var geom = editor.selected.geometry; 
      var uvs = geom.faceVertexUvs[0]; 

      var face0 = uvs[0]; 
      face0[0] = new THREE.Vector2(0,1); 
      face0[1] = new THREE.Vector2(0,0.2); 
      face0[2] = new THREE.Vector2(0.5,1); 

      var face1 = uvs[1]; 
      face1[0] = new THREE.Vector2(0,0.2); 
      face1[1] = new THREE.Vector2(0.5,0.2); 
      face1[2] = new THREE.Vector2(0.5,1); 

      geom.uvsNeedUpdate = true; 

    }); 

再次,沒有運氣。

例如,如果對象是一個二維正方形,我想居中無尾熊圖象,其需要是這樣的:

koala bear on center of square

我想要動態地改變紋理的位置 由於事先

+1

你能顯示你的一些代碼嘗試? – AndrewPolland

+0

當然編輯過。 – RoeePeleg

+0

嘗試'face0 [0] .set(u,v);'不要實例化一個新實例。 – WestLangley

回答

0

我終於有一個很好的解決方案上來,看看是否有幫助:

someButton.onClick(function() { 

    var obj = editor.selected; 
    var width = obj.geometry.parameters.width; 
    var height = obj.geometry.parameters.height; 
    var geometry = new THREE.PlaneGeometry(width,height, 3, 3); 
    var material = obj.material; 

    material.map.wrapS = material.map.wrapT = THREE.RepeatWrapping; 
    material.map.repeat.x = material.map.repeat.y = 3; 

    var materials = []; 
    materials.push(material); 
    materials.push(new THREE.MeshBasicMaterial({})); 

    for (var i = 0; i < 18; i++) { 
     if (i == 8 || i == 9) geomtery.faces[i].materialIndex = 0; 
     else geomtery.faces[i].materialIndex = 1; 
    } 

    obj.geomtery = geomtery; 
    obj.material = new THREE.MeshFaceMaterial(materials); 
    editor.signals.materialChanged.dispatch(obj); 

});