author Yannick Deubel (https://github.com/yandeu)
 *  copyright license https import { LinearFilter , Texture } from 'three' ; import { SimpleSprite } from './simpleSprite' ; import { canvas , createNewTexture } from './_misc' ; type DrawCanvas = ( ctx : CanvasRenderingContext2D ) => void ; export class DrawTexture extends Texture { width : number ; height : number ; drawCanvas : DrawCanvas ; clone ( ) { return new DrawTexture ( this . width , this . height , this . drawCanvas ) . copy ( this ) as this ; } copy ( source ) { super . copy ( source ) ; return this ; } constructor ( width , height , drawCanvas ) { const ctx = canvas . getContext ( '2d' ) as CanvasRenderingContext2D ; ctx . clearRect ( 0 , 0 , canvas . width , canvas . height ) ; canvas . height = height ; canvas . width = width ; drawCanvas ( ctx ) ; const imageData = ctx . getImageData ( 0 , 0 , canvas . width , canvas . height ) as any ; super ( imageData ) ; this . minFilter = LinearFilter ; this . generateMipmaps = false ; this . width = width ; this . height = height ; this . drawCanvas = drawCanvas ; this . needsUpdate = true ; } } export class DrawSprite extends SimpleSprite { private _drawCanvas : DrawCanvas ; clone ( ) { return new DrawSprite ( this . textureWidth , this . textureHeight , this . _drawCanvas ) . copy ( this ) as this ; } copy ( source ) { super . copy ( source ) ; return this ; } constructor ( width , height , drawCanvas ) { const ctx = canvas . getContext ( '2d' ) as CanvasRenderingContext2D ; ctx . clearRect ( 0 , 0 , canvas . width , canvas . height ) ; canvas . height = height ; canvas . width = width ; drawCanvas ( ctx ) ; const image = ctx . getImageData ( 0 , 0 , canvas . width , canvas . height ) ; const texture = createNewTexture ( image ) ; super ( texture ) ; this . _drawCanvas = drawCanvas ; } }