123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- import { serialize, SerializationHelper, serializeAsColor3, expandToProperty, serializeAsTexture } from "../../Misc/decorators";
- import { Scene } from "../../scene";
- import { Color3 } from "../../Maths/math.color";
- import { BaseTexture } from "../../Materials/Textures/baseTexture";
- import { PBRBaseSimpleMaterial } from "./pbrBaseSimpleMaterial";
- import { _TypeStore } from '../../Misc/typeStore';
- /**
- * The PBR material of BJS following the specular glossiness convention.
- *
- * This fits to the PBR convention in the GLTF definition:
- * https://github.com/KhronosGroup/glTF/tree/2.0/extensions/Khronos/KHR_materials_pbrSpecularGlossiness
- */
- export class PBRSpecularGlossinessMaterial extends PBRBaseSimpleMaterial {
- /**
- * Specifies the diffuse color of the material.
- */
- @serializeAsColor3("diffuse")
- @expandToProperty("_markAllSubMeshesAsTexturesDirty", "_albedoColor")
- public diffuseColor: Color3;
- /**
- * Specifies the diffuse texture of the material. This can also contains the opcity value in its alpha
- * channel.
- */
- @serializeAsTexture()
- @expandToProperty("_markAllSubMeshesAsTexturesDirty", "_albedoTexture")
- public diffuseTexture: BaseTexture;
- /**
- * Specifies the specular color of the material. This indicates how reflective is the material (none to mirror).
- */
- @serializeAsColor3("specular")
- @expandToProperty("_markAllSubMeshesAsTexturesDirty", "_reflectivityColor")
- public specularColor: Color3;
- /**
- * Specifies the glossiness of the material. This indicates "how sharp is the reflection".
- */
- @serialize()
- @expandToProperty("_markAllSubMeshesAsTexturesDirty", "_microSurface")
- public glossiness: number;
- /**
- * Specifies both the specular color RGB and the glossiness A of the material per pixels.
- */
- @serializeAsTexture()
- @expandToProperty("_markAllSubMeshesAsTexturesDirty", "_reflectivityTexture")
- public specularGlossinessTexture: BaseTexture;
- /**
- * Instantiates a new PBRSpecularGlossinessMaterial instance.
- *
- * @param name The material name
- * @param scene The scene the material will be use in.
- */
- constructor(name: string, scene: Scene) {
- super(name, scene);
- this._useMicroSurfaceFromReflectivityMapAlpha = true;
- }
- /**
- * Return the currrent class name of the material.
- */
- public getClassName(): string {
- return "PBRSpecularGlossinessMaterial";
- }
- /**
- * Makes a duplicate of the current material.
- * @param name - name to use for the new material.
- */
- public clone(name: string): PBRSpecularGlossinessMaterial {
- var clone = SerializationHelper.Clone(() => new PBRSpecularGlossinessMaterial(name, this.getScene()), this);
- clone.id = name;
- clone.name = name;
- this.clearCoat.copyTo(clone.clearCoat);
- this.anisotropy.copyTo(clone.anisotropy);
- this.brdf.copyTo(clone.brdf);
- this.sheen.copyTo(clone.sheen);
- this.subSurface.copyTo(clone.subSurface);
- return clone;
- }
- /**
- * Serialize the material to a parsable JSON object.
- */
- public serialize(): any {
- var serializationObject = SerializationHelper.Serialize(this);
- serializationObject.customType = "BABYLON.PBRSpecularGlossinessMaterial";
- serializationObject.clearCoat = this.clearCoat.serialize();
- serializationObject.anisotropy = this.anisotropy.serialize();
- serializationObject.brdf = this.brdf.serialize();
- serializationObject.sheen = this.sheen.serialize();
- serializationObject.subSurface = this.subSurface.serialize();
- return serializationObject;
- }
- /**
- * Parses a JSON object correponding to the serialize function.
- */
- public static Parse(source: any, scene: Scene, rootUrl: string): PBRSpecularGlossinessMaterial {
- const material = SerializationHelper.Parse(() => new PBRSpecularGlossinessMaterial(source.name, scene), source, scene, rootUrl);
- if (source.clearCoat) {
- material.clearCoat.parse(source.clearCoat, scene, rootUrl);
- }
- if (source.anisotropy) {
- material.anisotropy.parse(source.anisotropy, scene, rootUrl);
- }
- if (source.brdf) {
- material.brdf.parse(source.brdf, scene, rootUrl);
- }
- if (source.sheen) {
- material.sheen.parse(source.sheen, scene, rootUrl);
- }
- if (source.subSurface) {
- material.subSurface.parse(source.subSurface, scene, rootUrl);
- }
- return material;
- }
- }
- _TypeStore.RegisteredTypes["BABYLON.PBRSpecularGlossinessMaterial"] = PBRSpecularGlossinessMaterial;
|