All files / src/WebGL/materials SpriteMaterial.ts

0% Statements 0/30
0% Branches 0/6
0% Functions 0/2
0% Lines 0/30

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57                                                                                                                 
import { SpriteAlignment } from "../constants/SpriteAlignment";
import { Texture } from "../core/Texture";
import { Color } from "../core/Color";
import { Vector2 } from "../math";
import { Material } from "./Material";
export class SpriteMaterial extends Material {
  sizeAttenuation: boolean;
  screenOffset: any;
  scaleByViewPort: boolean;
  alignment: any;
  scaleByViewport: any;
 
  color = new Color(0xffffff);
  map = new Texture();
  useScreenCoordinates = true;
  fog = false; // use scene fog
  uvOffset = new Vector2(0, 0);
  uvScale = new Vector2(1, 1);
  
  constructor(parameters?: any) {
    super();
    this.depthTest = !this.useScreenCoordinates;
    this.sizeAttenuation = !this.useScreenCoordinates;
    this.screenOffset = this.screenOffset;
    this.scaleByViewPort = !this.sizeAttenuation;
    this.alignment = SpriteAlignment.center.clone();
 
    this.setValues(parameters);
 
    parameters = parameters || {};
 
    Iif (parameters.depthTest === undefined)
      this.depthTest = !this.useScreenCoordinates;
    Iif (parameters.sizeAttenuation === undefined)
      this.sizeAttenuation = !this.useScreenCoordinates;
    Iif (parameters.scaleByViewPort === undefined)
      this.scaleByViewPort = !this.sizeAttenuation;
  }
 
  clone<T extends this>(material = new SpriteMaterial() as T): T {
    super.clone.call(this, material);
 
    material.color.copy(this.color);
    material.map = this.map;
 
    material.useScreenCoordinates = this.useScreenCoordinates;
    material.screenOffset = this.screenOffset;
    material.sizeAttenuation = this.sizeAttenuation;
    material.scaleByViewport = this.scaleByViewPort;
    material.alignment.copy(this.alignment);
 
    material.uvOffset.copy(this.uvOffset);
 
    return material;
  }
}