roadProceduralTexture.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { serializeAsColor3, SerializationHelper } from "babylonjs/Misc/decorators";
  2. import { Color3 } from "babylonjs/Maths/math";
  3. import { Texture } from "babylonjs/Materials/Textures/texture";
  4. import { ProceduralTexture } from "babylonjs/Materials/Textures/Procedurals/proceduralTexture";
  5. import { Scene } from "babylonjs/scene";
  6. import { _TypeStore } from 'babylonjs/Misc/typeStore';
  7. import "./roadProceduralTexture.fragment";
  8. export class RoadProceduralTexture extends ProceduralTexture {
  9. private _roadColor = new Color3(0.53, 0.53, 0.53);
  10. constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean) {
  11. super(name, size, "roadProceduralTexture", scene, fallbackTexture, generateMipMaps);
  12. this.updateShaderUniforms();
  13. }
  14. public updateShaderUniforms() {
  15. this.setColor3("roadColor", this._roadColor);
  16. }
  17. @serializeAsColor3()
  18. public get roadColor(): Color3 {
  19. return this._roadColor;
  20. }
  21. public set roadColor(value: Color3) {
  22. this._roadColor = value;
  23. this.updateShaderUniforms();
  24. }
  25. /**
  26. * Serializes this road procedural texture
  27. * @returns a serialized road procedural texture object
  28. */
  29. public serialize(): any {
  30. var serializationObject = SerializationHelper.Serialize(this, super.serialize());
  31. serializationObject.customType = "BABYLON.RoadProceduralTexture";
  32. return serializationObject;
  33. }
  34. /**
  35. * Creates a Road Procedural Texture from parsed road procedural texture data
  36. * @param parsedTexture defines parsed texture data
  37. * @param scene defines the current scene
  38. * @param rootUrl defines the root URL containing road procedural texture information
  39. * @returns a parsed Road Procedural Texture
  40. */
  41. public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): RoadProceduralTexture {
  42. var texture = SerializationHelper.Parse(() => new RoadProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps), parsedTexture, scene, rootUrl);
  43. return texture;
  44. }
  45. }
  46. _TypeStore.RegisteredTypes["BABYLON.RoadProceduralTexture"] = RoadProceduralTexture;