Last active
May 5, 2022 14:51
-
-
Save momo-the-monster/9471364 to your computer and use it in GitHub Desktop.
Three.JS Atlas Loader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// json is a JSON atlas generated by TexturePacker | |
// imagepath is a url to the full texture atlas image | |
var atlasTexture = THREE.ImageUtils.loadTexture( imagepath, undefined, function() { | |
for (var key in json.frames) { | |
var tex = atlasTexture.clone(); | |
var frame = json.frames[key].frame; | |
tex.repeat.x = ( frame.w / atlasTexture.image.width ); | |
tex.repeat.y = ( frame.h / atlasTexture.image.height ); | |
tex.offset.x = ( Math.abs( frame.x ) / atlasTexture.image.width ); | |
tex.offset.y = ( Math.abs( frame.y )/ atlasTexture.image.height ); | |
tex.needsUpdate = true; | |
var material = new THREE.MeshPhongMaterial( { transparent:true, map: tex, side: THREE.DoubleSide} ); | |
scope.materials.push( material ); | |
} | |
}); |
https://threejs.org/docs/#api/textures/Texture
Texture.clone is not a "deep copy", the image is shared.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Are you make clone of whole image for every frame ? O_o
or it is just copy of texture that used the same image all time?