2016-01-06 30 views
0

我有一個精靈表(與紋理打包器導出),並使用offsetrepeat屬性(紋理)來顯示我的精靈表的元素。三個JS問題紋理偏移和重複的定位元素的spritesheet

這是目前不工作(和裁剪我的紋理的錯誤元素) - 如果任何人有一些洞察我的錯誤將會喜歡它。

這裏是我的代碼:

var tx = this._loadedTexture.clone(); // THREE.Texture 
var txData = this._atlas.frames[name]; 
var txFrame = txData.frame;//txFrame = Object {x: 122, y: 0, w: 68, h: 64} 
var img = tx.image; // HTMLImageElement - image.width = 256 image.height = 512 

tx.repeat.x = txFrame.w/img.width; 
tx.repeat.y = txFrame.h/img.height; 

tx.offset.x = (txFrame.x/img.width); 
tx.offset.y = (txFrame.y/img.height); 
tx.needsUpdate = true; 

謝謝。

回答

2

解決了它。對於未來的參考,這是我結束了得到一個精靈表與紋理圖集在ThreeJS(0.73)工作:

tx.wrapS = tx.wrapT = THREE.RepeatWrapping; 
tx.repeat.set(txFrame.w/img.width, txFrame.h/img.height); 
tx.offset.x = ((txFrame.x)/img.width); 
tx.offset.y = 1 - (txFrame.h/img.height) - (txFrame.y/img.height); 

希望這會希望別人在那裏。

+0

有同樣的問題,謝謝你的答案!你有沒有得到輪換處理工作?我有一個地圖集,可以從旋轉打包中獲益很多,但是將它們解析回THREE.Textures會令人困惑。 –

+0

我沒有添加旋轉。發現將它保持爲一個精靈圖紙/紋理的性能要高得多。 – user2386872