三JS问题与纹理偏移和重复定位的精灵表元素



我有一个精灵表(使用Texture Packer导出),并且正在使用(纹理的)offsetrepeat属性来显示我的精灵表的元素。

这目前不起作用(并且裁剪出了我纹理中错误的元素)——如果有人对我的错误有一些了解,我会很高兴的。

这是我的代码:

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;

谢谢。

解决了它。为了将来的参考,这是我最终得到的一个使用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);

希望这能给其他人带来希望。

最新更新