LoginSignup
0
0

More than 3 years have passed since last update.

three.js tiletipの切り取り

Posted at

onload で切り取る。

//...

function tip(num,size){return (tex)=>{
  size=size||16,num=num||0;
  let img=tex.image,w=img.naturalWidth,h=img.naturalHeight
  ,c=document.createElement('canvas'),ctx=c.getContext("2d")
  ,nw=~~(w/size),nh =~~(h/size),x=num%nw,y=~~(num/nw)
  ;
  c.height=c.width=size
  ctx.drawImage(img,x*size,y*size,size,size, 0,0,size,size)
  tex.image.src=c.toDataURL()
  tex.needsUpdate=true////
 }
}

//var loader=new THREE.TextureLoader()
//let tex=loader.load(url,tip(number,size))

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0