pbrMetallicRoughnessMaterial.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import { __decorate } from "../../tslib.es6.js";
  2. import { serialize, serializeAsColor3, expandToProperty, serializeAsTexture } from "../../Misc/decorators.js";
  3. import { SerializationHelper } from "../../Misc/decorators.serialization.js";
  4. import { PBRBaseSimpleMaterial } from "./pbrBaseSimpleMaterial.js";
  5. import { RegisterClass } from "../../Misc/typeStore.js";
  6. /**
  7. * The PBR material of BJS following the metal roughness convention.
  8. *
  9. * This fits to the PBR convention in the GLTF definition:
  10. * https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Archived/KHR_materials_pbrSpecularGlossiness/README.md
  11. */
  12. export class PBRMetallicRoughnessMaterial extends PBRBaseSimpleMaterial {
  13. /**
  14. * Instantiates a new PBRMetalRoughnessMaterial instance.
  15. *
  16. * @param name The material name
  17. * @param scene The scene the material will be use in.
  18. */
  19. constructor(name, scene) {
  20. super(name, scene);
  21. this._useRoughnessFromMetallicTextureAlpha = false;
  22. this._useRoughnessFromMetallicTextureGreen = true;
  23. this._useMetallnessFromMetallicTextureBlue = true;
  24. this.metallic = 1.0;
  25. this.roughness = 1.0;
  26. }
  27. /**
  28. * @returns the current class name of the material.
  29. */
  30. getClassName() {
  31. return "PBRMetallicRoughnessMaterial";
  32. }
  33. /**
  34. * Makes a duplicate of the current material.
  35. * @param name - name to use for the new material.
  36. * @returns cloned material instance
  37. */
  38. clone(name) {
  39. const clone = SerializationHelper.Clone(() => new PBRMetallicRoughnessMaterial(name, this.getScene()), this);
  40. clone.id = name;
  41. clone.name = name;
  42. this.clearCoat.copyTo(clone.clearCoat);
  43. this.anisotropy.copyTo(clone.anisotropy);
  44. this.brdf.copyTo(clone.brdf);
  45. this.sheen.copyTo(clone.sheen);
  46. this.subSurface.copyTo(clone.subSurface);
  47. return clone;
  48. }
  49. /**
  50. * Serialize the material to a parsable JSON object.
  51. * @returns the JSON object
  52. */
  53. serialize() {
  54. const serializationObject = SerializationHelper.Serialize(this);
  55. serializationObject.customType = "BABYLON.PBRMetallicRoughnessMaterial";
  56. serializationObject.clearCoat = this.clearCoat.serialize();
  57. serializationObject.anisotropy = this.anisotropy.serialize();
  58. serializationObject.brdf = this.brdf.serialize();
  59. serializationObject.sheen = this.sheen.serialize();
  60. serializationObject.subSurface = this.subSurface.serialize();
  61. serializationObject.iridescence = this.iridescence.serialize();
  62. return serializationObject;
  63. }
  64. /**
  65. * Parses a JSON object corresponding to the serialize function.
  66. * @param source - JSON source object.
  67. * @param scene - Defines the scene we are parsing for
  68. * @param rootUrl - Defines the rootUrl of this parsed object
  69. * @returns a new PBRMetalRoughnessMaterial
  70. */
  71. static Parse(source, scene, rootUrl) {
  72. const material = SerializationHelper.Parse(() => new PBRMetallicRoughnessMaterial(source.name, scene), source, scene, rootUrl);
  73. if (source.clearCoat) {
  74. material.clearCoat.parse(source.clearCoat, scene, rootUrl);
  75. }
  76. if (source.anisotropy) {
  77. material.anisotropy.parse(source.anisotropy, scene, rootUrl);
  78. }
  79. if (source.brdf) {
  80. material.brdf.parse(source.brdf, scene, rootUrl);
  81. }
  82. if (source.sheen) {
  83. material.sheen.parse(source.sheen, scene, rootUrl);
  84. }
  85. if (source.subSurface) {
  86. material.subSurface.parse(source.subSurface, scene, rootUrl);
  87. }
  88. if (source.iridescence) {
  89. material.iridescence.parse(source.iridescence, scene, rootUrl);
  90. }
  91. return material;
  92. }
  93. }
  94. __decorate([
  95. serializeAsColor3(),
  96. expandToProperty("_markAllSubMeshesAsTexturesDirty", "_albedoColor")
  97. ], PBRMetallicRoughnessMaterial.prototype, "baseColor", void 0);
  98. __decorate([
  99. serializeAsTexture(),
  100. expandToProperty("_markAllSubMeshesAsTexturesDirty", "_albedoTexture")
  101. ], PBRMetallicRoughnessMaterial.prototype, "baseTexture", void 0);
  102. __decorate([
  103. serialize(),
  104. expandToProperty("_markAllSubMeshesAsTexturesDirty")
  105. ], PBRMetallicRoughnessMaterial.prototype, "metallic", void 0);
  106. __decorate([
  107. serialize(),
  108. expandToProperty("_markAllSubMeshesAsTexturesDirty")
  109. ], PBRMetallicRoughnessMaterial.prototype, "roughness", void 0);
  110. __decorate([
  111. serializeAsTexture(),
  112. expandToProperty("_markAllSubMeshesAsTexturesDirty", "_metallicTexture")
  113. ], PBRMetallicRoughnessMaterial.prototype, "metallicRoughnessTexture", void 0);
  114. RegisterClass("BABYLON.PBRMetallicRoughnessMaterial", PBRMetallicRoughnessMaterial);
  115. //# sourceMappingURL=pbrMetallicRoughnessMaterial.js.map