babylon.brickProceduralTexture.ts 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. module BABYLON {
  3. export class BrickProceduralTexture extends ProceduralTexture {
  4. private _numberOfBricksHeight: number = 15;
  5. private _numberOfBricksWidth: number = 5;
  6. private _jointColor = new Color3(0.72, 0.72, 0.72);
  7. private _brickColor = new Color3(0.77, 0.47, 0.40);
  8. constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean) {
  9. super(name, size, "brickProceduralTexture", scene, fallbackTexture, generateMipMaps);
  10. this.updateShaderUniforms();
  11. }
  12. public updateShaderUniforms() {
  13. this.setFloat("numberOfBricksHeight", this._numberOfBricksHeight);
  14. this.setFloat("numberOfBricksWidth", this._numberOfBricksWidth);
  15. this.setColor3("brickColor", this._brickColor);
  16. this.setColor3("jointColor", this._jointColor);
  17. }
  18. @serialize()
  19. public get numberOfBricksHeight(): number {
  20. return this._numberOfBricksHeight;
  21. }
  22. public set numberOfBricksHeight(value: number) {
  23. this._numberOfBricksHeight = value;
  24. this.updateShaderUniforms();
  25. }
  26. @serialize()
  27. public get numberOfBricksWidth(): number {
  28. return this._numberOfBricksWidth;
  29. }
  30. public set numberOfBricksWidth(value: number) {
  31. this._numberOfBricksWidth = value;
  32. this.updateShaderUniforms();
  33. }
  34. @serializeAsColor3()
  35. public get jointColor(): Color3 {
  36. return this._jointColor;
  37. }
  38. public set jointColor(value: Color3) {
  39. this._jointColor = value;
  40. this.updateShaderUniforms();
  41. }
  42. @serializeAsColor3()
  43. public get brickColor(): Color3 {
  44. return this._brickColor;
  45. }
  46. public set brickColor(value: Color3) {
  47. this._brickColor = value;
  48. this.updateShaderUniforms();
  49. }
  50. /**
  51. * Serializes this brick procedural texture
  52. * @returns a serialized brick procedural texture object
  53. */
  54. public serialize(): any {
  55. var serializationObject = SerializationHelper.Serialize(this, super.serialize());
  56. serializationObject.customType = "BABYLON.BrickProceduralTexture";
  57. return serializationObject;
  58. }
  59. /**
  60. * Creates a Brick Procedural Texture from parsed brick procedural texture data
  61. * @param parsedTexture defines parsed texture data
  62. * @param scene defines the current scene
  63. * @param rootUrl defines the root URL containing brick procedural texture information
  64. * @returns a parsed Brick Procedural Texture
  65. */
  66. public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): BrickProceduralTexture {
  67. var texture = SerializationHelper.Parse(() => new BrickProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps), parsedTexture, scene, rootUrl);
  68. return texture;
  69. }
  70. }
  71. }