@babylonjs/core 6.7.0 → 6.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Culling/ray.d.ts +7 -2
- package/Culling/ray.js +8 -3
- package/Culling/ray.js.map +1 -1
- package/Engines/Extensions/engine.multiview.d.ts +6 -1
- package/Engines/Extensions/engine.multiview.js +27 -7
- package/Engines/Extensions/engine.multiview.js.map +1 -1
- package/Engines/Native/nativeInterfaces.d.ts +1 -0
- package/Engines/Native/nativeInterfaces.js.map +1 -1
- package/Engines/Processors/Expressions/shaderDefineExpression.d.ts +37 -0
- package/Engines/Processors/Expressions/shaderDefineExpression.js +57 -0
- package/Engines/Processors/Expressions/shaderDefineExpression.js.map +1 -1
- package/Engines/Processors/shaderProcessor.js +26 -13
- package/Engines/Processors/shaderProcessor.js.map +1 -1
- package/Engines/WebGL/webGLRenderTargetWrapper.d.ts +19 -0
- package/Engines/WebGL/webGLRenderTargetWrapper.js +20 -1
- package/Engines/WebGL/webGLRenderTargetWrapper.js.map +1 -1
- package/Engines/engine.d.ts +8 -1
- package/Engines/engineCapabilities.d.ts +2 -0
- package/Engines/engineCapabilities.js.map +1 -1
- package/Engines/nativeEngine.d.ts +2 -0
- package/Engines/nativeEngine.js +16 -0
- package/Engines/nativeEngine.js.map +1 -1
- package/Engines/thinEngine.js +6 -9
- package/Engines/thinEngine.js.map +1 -1
- package/Loading/sceneLoader.d.ts +8 -8
- package/Loading/sceneLoader.js +35 -19
- package/Loading/sceneLoader.js.map +1 -1
- package/Materials/Node/nodeMaterial.d.ts +6 -1
- package/Materials/Node/nodeMaterial.js +7 -5
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Materials/multiMaterial.js +1 -1
- package/Materials/multiMaterial.js.map +1 -1
- package/Materials/shaderMaterial.d.ts +23 -4
- package/Materials/shaderMaterial.js +38 -5
- package/Materials/shaderMaterial.js.map +1 -1
- package/Meshes/abstractMesh.d.ts +2 -1
- package/Meshes/abstractMesh.js +2 -1
- package/Meshes/abstractMesh.js.map +1 -1
- package/Misc/deepCopier.js +1 -1
- package/Misc/deepCopier.js.map +1 -1
- package/Misc/observable.d.ts +11 -0
- package/Misc/observable.js +26 -1
- package/Misc/observable.js.map +1 -1
- package/Particles/gpuParticleSystem.d.ts +1 -0
- package/Particles/gpuParticleSystem.js +3 -2
- package/Particles/gpuParticleSystem.js.map +1 -1
- package/Rendering/boundingBoxRenderer.js +2 -4
- package/Rendering/boundingBoxRenderer.js.map +1 -1
- package/Shaders/ShadersInclude/pbrDebug.js +8 -1
- package/Shaders/ShadersInclude/pbrDebug.js.map +1 -1
- package/Shaders/velocity.fragment.d.ts +5 -0
- package/Shaders/velocity.fragment.js +13 -0
- package/Shaders/velocity.fragment.js.map +1 -0
- package/Shaders/velocity.vertex.d.ts +7 -0
- package/Shaders/velocity.vertex.js +23 -0
- package/Shaders/velocity.vertex.js.map +1 -0
- package/XR/features/WebXRLayers.js +16 -6
- package/XR/features/WebXRLayers.js.map +1 -1
- package/XR/features/WebXRSpaceWarp.d.ts +138 -0
- package/XR/features/WebXRSpaceWarp.js +290 -0
- package/XR/features/WebXRSpaceWarp.js.map +1 -0
- package/XR/features/index.d.ts +1 -0
- package/XR/features/index.js +1 -0
- package/XR/features/index.js.map +1 -1
- package/XR/webXRFeaturesManager.d.ts +4 -0
- package/XR/webXRFeaturesManager.js +4 -0
- package/XR/webXRFeaturesManager.js.map +1 -1
- package/XR/webXRSessionManager.d.ts +4 -0
- package/XR/webXRSessionManager.js +6 -0
- package/XR/webXRSessionManager.js.map +1 -1
- package/package.json +1 -1
- package/scene.d.ts +5 -2
- package/scene.js +5 -2
- package/scene.js.map +1 -1
|
@@ -37,7 +37,7 @@ export class MultiMaterial extends Material {
|
|
|
37
37
|
super(name, scene, true);
|
|
38
38
|
/** @internal */
|
|
39
39
|
this._waitingSubMaterialsUniqueIds = [];
|
|
40
|
-
this.getScene().
|
|
40
|
+
this.getScene().addMultiMaterial(this);
|
|
41
41
|
this.subMaterials = new Array();
|
|
42
42
|
this._storeEffectOnSubMeshes = true; // multimaterial is considered like a push material
|
|
43
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multiMaterial.js","sourceRoot":"","sources":["../../../../lts/core/generated/Materials/multiMaterial.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;GAIG;AACH,MAAM,OAAO,aAAc,SAAQ,QAAQ;IAKvC;;;OAGG;IACH,IAAW,YAAY;QACnB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC;IAED,IAAW,YAAY,CAAC,KAA2B;QAC/C,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;QAC3B,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACI,WAAW;QACd,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IAED;;;;;;;OAOG;IACH,YAAY,IAAY,EAAE,KAAa;QACnC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QAjC7B,gBAAgB;QACT,kCAA6B,GAAa,EAAE,CAAC;QAkChD,IAAI,CAAC,QAAQ,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE1C,IAAI,CAAC,YAAY,GAAG,IAAI,KAAK,EAAY,CAAC;QAE1C,IAAI,CAAC,uBAAuB,GAAG,IAAI,CAAC,CAAC,mDAAmD;IAC5F,CAAC;IAEO,UAAU,CAAC,KAA2B;QAC1C,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC;QAC3B,KAAK,CAAC,IAAI,GAAG,CAAC,GAAG,KAA2B,EAAE,EAAE;YAC5C,MAAM,MAAM,GAAG,OAAO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kBAAkB,CAAC;SACxF;aAAM;YACH,mBAAmB,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAgB,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;SACrI;QAED,OAAO,aAAa,CAAC;IACzB,CAAC;CACJ;AAED,aAAa,CAAC,uBAAuB,EAAE,aAAa,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { Material } from \"../Materials/material\";\r\nimport { Tags } from \"../Misc/tags\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\n\r\n/**\r\n * A multi-material is used to apply different materials to different parts of the same object without the need of\r\n * separate meshes. This can be use to improve performances.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/multiMaterials\r\n */\r\nexport class MultiMaterial extends Material {\r\n private _subMaterials: Nullable<Material>[];\r\n /** @internal */\r\n public _waitingSubMaterialsUniqueIds: string[] = [];\r\n\r\n /**\r\n * Gets or Sets the list of Materials used within the multi material.\r\n * They need to be ordered according to the submeshes order in the associated mesh\r\n */\r\n public get subMaterials(): Nullable<Material>[] {\r\n return this._subMaterials;\r\n }\r\n\r\n public set subMaterials(value: Nullable<Material>[]) {\r\n this._subMaterials = value;\r\n this._hookArray(value);\r\n }\r\n\r\n /**\r\n * Function used to align with Node.getChildren()\r\n * @returns the list of Materials used within the multi material\r\n */\r\n public getChildren(): Nullable<Material>[] {\r\n return this.subMaterials;\r\n }\r\n\r\n /**\r\n * Instantiates a new Multi Material\r\n * A multi-material is used to apply different materials to different parts of the same object without the need of\r\n * separate meshes. This can be use to improve performances.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/multiMaterials\r\n * @param name Define the name in the scene\r\n * @param scene Define the scene the material belongs to\r\n */\r\n constructor(name: string, scene?: Scene) {\r\n super(name, scene, true);\r\n\r\n this.getScene().multiMaterials.push(this);\r\n\r\n this.subMaterials = new Array<Material>();\r\n\r\n this._storeEffectOnSubMeshes = true; // multimaterial is considered like a push material\r\n }\r\n\r\n private _hookArray(array: Nullable<Material>[]): void {\r\n const oldPush = array.push;\r\n array.push = (...items: Nullable<Material>[]) => {\r\n const result = oldPush.apply(array, items);\r\n\r\n this._markAllSubMeshesAsTexturesDirty();\r\n\r\n return result;\r\n };\r\n\r\n const oldSplice = array.splice;\r\n array.splice = (index: number, deleteCount?: number) => {\r\n const deleted = oldSplice.apply(array, [index, deleteCount]);\r\n\r\n this._markAllSubMeshesAsTexturesDirty();\r\n\r\n return deleted;\r\n };\r\n }\r\n\r\n /**\r\n * Get one of the submaterial by its index in the submaterials array\r\n * @param index The index to look the sub material at\r\n * @returns The Material if the index has been defined\r\n */\r\n public getSubMaterial(index: number): Nullable<Material> {\r\n if (index < 0 || index >= this.subMaterials.length) {\r\n return this.getScene().defaultMaterial;\r\n }\r\n\r\n return this.subMaterials[index];\r\n }\r\n\r\n /**\r\n * Get the list of active textures for the whole sub materials list.\r\n * @returns All the textures that will be used during the rendering\r\n */\r\n public getActiveTextures(): BaseTexture[] {\r\n return super.getActiveTextures().concat(\r\n ...this.subMaterials.map((subMaterial) => {\r\n if (subMaterial) {\r\n return subMaterial.getActiveTextures();\r\n } else {\r\n return [];\r\n }\r\n })\r\n );\r\n }\r\n\r\n /**\r\n * Specifies if any sub-materials of this multi-material use a given texture.\r\n * @param texture Defines the texture to check against this multi-material's sub-materials.\r\n * @returns A boolean specifying if any sub-material of this multi-material uses the texture.\r\n */\r\n public hasTexture(texture: BaseTexture): boolean {\r\n if (super.hasTexture(texture)) {\r\n return true;\r\n }\r\n\r\n for (let i = 0; i < this.subMaterials.length; i++) {\r\n if (this.subMaterials[i]?.hasTexture(texture)) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Gets the current class name of the material e.g. \"MultiMaterial\"\r\n * Mainly use in serialization.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"MultiMaterial\";\r\n }\r\n\r\n /**\r\n * Checks if the material is ready to render the requested sub mesh\r\n * @param mesh Define the mesh the submesh belongs to\r\n * @param subMesh Define the sub mesh to look readiness for\r\n * @param useInstances Define whether or not the material is used with instances\r\n * @returns true if ready, otherwise false\r\n */\r\n public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {\r\n for (let index = 0; index < this.subMaterials.length; index++) {\r\n const subMaterial = this.subMaterials[index];\r\n if (subMaterial) {\r\n if (subMaterial._storeEffectOnSubMeshes) {\r\n if (!subMaterial.isReadyForSubMesh(mesh, subMesh, useInstances)) {\r\n return false;\r\n }\r\n continue;\r\n }\r\n\r\n if (!subMaterial.isReady(mesh)) {\r\n return false;\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Clones the current material and its related sub materials\r\n * @param name Define the name of the newly cloned material\r\n * @param cloneChildren Define if submaterial will be cloned or shared with the parent instance\r\n * @returns the cloned material\r\n */\r\n public clone(name: string, cloneChildren?: boolean): MultiMaterial {\r\n const newMultiMaterial = new MultiMaterial(name, this.getScene());\r\n\r\n for (let index = 0; index < this.subMaterials.length; index++) {\r\n let subMaterial: Nullable<Material> = null;\r\n const current = this.subMaterials[index];\r\n if (cloneChildren && current) {\r\n subMaterial = current.clone(name + \"-\" + current.name);\r\n } else {\r\n subMaterial = this.subMaterials[index];\r\n }\r\n newMultiMaterial.subMaterials.push(subMaterial);\r\n }\r\n\r\n return newMultiMaterial;\r\n }\r\n\r\n /**\r\n * Serializes the materials into a JSON representation.\r\n * @returns the JSON representation\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = {};\r\n\r\n serializationObject.name = this.name;\r\n serializationObject.id = this.id;\r\n serializationObject.uniqueId = this.uniqueId;\r\n if (Tags) {\r\n serializationObject.tags = Tags.GetTags(this);\r\n }\r\n serializationObject.materialsUniqueIds = [];\r\n serializationObject.materials = [];\r\n\r\n for (let matIndex = 0; matIndex < this.subMaterials.length; matIndex++) {\r\n const subMat = this.subMaterials[matIndex];\r\n\r\n if (subMat) {\r\n serializationObject.materialsUniqueIds.push(subMat.uniqueId);\r\n serializationObject.materials.push(subMat.id);\r\n } else {\r\n serializationObject.materialsUniqueIds.push(null);\r\n serializationObject.materials.push(null);\r\n }\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Dispose the material and release its associated resources\r\n * @param forceDisposeEffect Define if we want to force disposing the associated effect (if false the shader is not released and could be reuse later on)\r\n * @param forceDisposeTextures Define if we want to force disposing the associated textures (if false, they will not be disposed and can still be use elsewhere in the app)\r\n * @param forceDisposeChildren Define if we want to force disposing the associated submaterials (if false, they will not be disposed and can still be use elsewhere in the app)\r\n */\r\n public dispose(forceDisposeEffect?: boolean, forceDisposeTextures?: boolean, forceDisposeChildren?: boolean): void {\r\n const scene = this.getScene();\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n if (forceDisposeChildren) {\r\n for (let index = 0; index < this.subMaterials.length; index++) {\r\n const subMaterial = this.subMaterials[index];\r\n if (subMaterial) {\r\n subMaterial.dispose(forceDisposeEffect, forceDisposeTextures);\r\n }\r\n }\r\n }\r\n\r\n const index = scene.multiMaterials.indexOf(this);\r\n if (index >= 0) {\r\n scene.multiMaterials.splice(index, 1);\r\n }\r\n\r\n super.dispose(forceDisposeEffect, forceDisposeTextures);\r\n }\r\n\r\n /**\r\n * Creates a MultiMaterial from parsed MultiMaterial data.\r\n * @param parsedMultiMaterial defines parsed MultiMaterial data.\r\n * @param scene defines the hosting scene\r\n * @returns a new MultiMaterial\r\n */\r\n public static ParseMultiMaterial(parsedMultiMaterial: any, scene: Scene): MultiMaterial {\r\n const multiMaterial = new MultiMaterial(parsedMultiMaterial.name, scene);\r\n\r\n multiMaterial.id = parsedMultiMaterial.id;\r\n multiMaterial._loadedUniqueId = parsedMultiMaterial.uniqueId;\r\n\r\n if (Tags) {\r\n Tags.AddTagsTo(multiMaterial, parsedMultiMaterial.tags);\r\n }\r\n\r\n if (parsedMultiMaterial.materialsUniqueIds) {\r\n multiMaterial._waitingSubMaterialsUniqueIds = parsedMultiMaterial.materialsUniqueIds;\r\n } else {\r\n parsedMultiMaterial.materials.forEach((subMatId: string) => multiMaterial.subMaterials.push(scene.getLastMaterialById(subMatId)));\r\n }\r\n\r\n return multiMaterial;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.MultiMaterial\", MultiMaterial);\r\n"]}
|
|
1
|
+
{"version":3,"file":"multiMaterial.js","sourceRoot":"","sources":["../../../../lts/core/generated/Materials/multiMaterial.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;GAIG;AACH,MAAM,OAAO,aAAc,SAAQ,QAAQ;IAKvC;;;OAGG;IACH,IAAW,YAAY;QACnB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC;IAED,IAAW,YAAY,CAAC,KAA2B;QAC/C,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;QAC3B,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACI,WAAW;QACd,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IAED;;;;;;;OAOG;IACH,YAAY,IAAY,EAAE,KAAa;QACnC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QAjC7B,gBAAgB;QACT,kCAA6B,GAAa,EAAE,CAAC;QAkChD,IAAI,CAAC,QAAQ,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAEv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,EAAE,GAAG,mBAAmB,CAAC,EAAE,CAAC;QAC1C,aAAa,CAAC,eAAe,GAAG,mBAAmB,CAAC,QAAQ,CAAC;QAE7D,IAAI,IAAI,EAAE;YACN,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;SAC3D;QAED,IAAI,mBAAmB,CAAC,kBAAkB,EAAE;YACxC,aAAa,CAAC,6BAA6B,GAAG,mBAAmB,CAAC,kBAAkB,CAAC;SACxF;aAAM;YACH,mBAAmB,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAgB,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;SACrI;QAED,OAAO,aAAa,CAAC;IACzB,CAAC;CACJ;AAED,aAAa,CAAC,uBAAuB,EAAE,aAAa,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { SubMesh } from \"../Meshes/subMesh\";\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { Material } from \"../Materials/material\";\r\nimport { Tags } from \"../Misc/tags\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\n\r\n/**\r\n * A multi-material is used to apply different materials to different parts of the same object without the need of\r\n * separate meshes. This can be use to improve performances.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/multiMaterials\r\n */\r\nexport class MultiMaterial extends Material {\r\n private _subMaterials: Nullable<Material>[];\r\n /** @internal */\r\n public _waitingSubMaterialsUniqueIds: string[] = [];\r\n\r\n /**\r\n * Gets or Sets the list of Materials used within the multi material.\r\n * They need to be ordered according to the submeshes order in the associated mesh\r\n */\r\n public get subMaterials(): Nullable<Material>[] {\r\n return this._subMaterials;\r\n }\r\n\r\n public set subMaterials(value: Nullable<Material>[]) {\r\n this._subMaterials = value;\r\n this._hookArray(value);\r\n }\r\n\r\n /**\r\n * Function used to align with Node.getChildren()\r\n * @returns the list of Materials used within the multi material\r\n */\r\n public getChildren(): Nullable<Material>[] {\r\n return this.subMaterials;\r\n }\r\n\r\n /**\r\n * Instantiates a new Multi Material\r\n * A multi-material is used to apply different materials to different parts of the same object without the need of\r\n * separate meshes. This can be use to improve performances.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/multiMaterials\r\n * @param name Define the name in the scene\r\n * @param scene Define the scene the material belongs to\r\n */\r\n constructor(name: string, scene?: Scene) {\r\n super(name, scene, true);\r\n\r\n this.getScene().addMultiMaterial(this);\r\n\r\n this.subMaterials = new Array<Material>();\r\n\r\n this._storeEffectOnSubMeshes = true; // multimaterial is considered like a push material\r\n }\r\n\r\n private _hookArray(array: Nullable<Material>[]): void {\r\n const oldPush = array.push;\r\n array.push = (...items: Nullable<Material>[]) => {\r\n const result = oldPush.apply(array, items);\r\n\r\n this._markAllSubMeshesAsTexturesDirty();\r\n\r\n return result;\r\n };\r\n\r\n const oldSplice = array.splice;\r\n array.splice = (index: number, deleteCount?: number) => {\r\n const deleted = oldSplice.apply(array, [index, deleteCount]);\r\n\r\n this._markAllSubMeshesAsTexturesDirty();\r\n\r\n return deleted;\r\n };\r\n }\r\n\r\n /**\r\n * Get one of the submaterial by its index in the submaterials array\r\n * @param index The index to look the sub material at\r\n * @returns The Material if the index has been defined\r\n */\r\n public getSubMaterial(index: number): Nullable<Material> {\r\n if (index < 0 || index >= this.subMaterials.length) {\r\n return this.getScene().defaultMaterial;\r\n }\r\n\r\n return this.subMaterials[index];\r\n }\r\n\r\n /**\r\n * Get the list of active textures for the whole sub materials list.\r\n * @returns All the textures that will be used during the rendering\r\n */\r\n public getActiveTextures(): BaseTexture[] {\r\n return super.getActiveTextures().concat(\r\n ...this.subMaterials.map((subMaterial) => {\r\n if (subMaterial) {\r\n return subMaterial.getActiveTextures();\r\n } else {\r\n return [];\r\n }\r\n })\r\n );\r\n }\r\n\r\n /**\r\n * Specifies if any sub-materials of this multi-material use a given texture.\r\n * @param texture Defines the texture to check against this multi-material's sub-materials.\r\n * @returns A boolean specifying if any sub-material of this multi-material uses the texture.\r\n */\r\n public hasTexture(texture: BaseTexture): boolean {\r\n if (super.hasTexture(texture)) {\r\n return true;\r\n }\r\n\r\n for (let i = 0; i < this.subMaterials.length; i++) {\r\n if (this.subMaterials[i]?.hasTexture(texture)) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Gets the current class name of the material e.g. \"MultiMaterial\"\r\n * Mainly use in serialization.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"MultiMaterial\";\r\n }\r\n\r\n /**\r\n * Checks if the material is ready to render the requested sub mesh\r\n * @param mesh Define the mesh the submesh belongs to\r\n * @param subMesh Define the sub mesh to look readiness for\r\n * @param useInstances Define whether or not the material is used with instances\r\n * @returns true if ready, otherwise false\r\n */\r\n public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {\r\n for (let index = 0; index < this.subMaterials.length; index++) {\r\n const subMaterial = this.subMaterials[index];\r\n if (subMaterial) {\r\n if (subMaterial._storeEffectOnSubMeshes) {\r\n if (!subMaterial.isReadyForSubMesh(mesh, subMesh, useInstances)) {\r\n return false;\r\n }\r\n continue;\r\n }\r\n\r\n if (!subMaterial.isReady(mesh)) {\r\n return false;\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Clones the current material and its related sub materials\r\n * @param name Define the name of the newly cloned material\r\n * @param cloneChildren Define if submaterial will be cloned or shared with the parent instance\r\n * @returns the cloned material\r\n */\r\n public clone(name: string, cloneChildren?: boolean): MultiMaterial {\r\n const newMultiMaterial = new MultiMaterial(name, this.getScene());\r\n\r\n for (let index = 0; index < this.subMaterials.length; index++) {\r\n let subMaterial: Nullable<Material> = null;\r\n const current = this.subMaterials[index];\r\n if (cloneChildren && current) {\r\n subMaterial = current.clone(name + \"-\" + current.name);\r\n } else {\r\n subMaterial = this.subMaterials[index];\r\n }\r\n newMultiMaterial.subMaterials.push(subMaterial);\r\n }\r\n\r\n return newMultiMaterial;\r\n }\r\n\r\n /**\r\n * Serializes the materials into a JSON representation.\r\n * @returns the JSON representation\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = {};\r\n\r\n serializationObject.name = this.name;\r\n serializationObject.id = this.id;\r\n serializationObject.uniqueId = this.uniqueId;\r\n if (Tags) {\r\n serializationObject.tags = Tags.GetTags(this);\r\n }\r\n serializationObject.materialsUniqueIds = [];\r\n serializationObject.materials = [];\r\n\r\n for (let matIndex = 0; matIndex < this.subMaterials.length; matIndex++) {\r\n const subMat = this.subMaterials[matIndex];\r\n\r\n if (subMat) {\r\n serializationObject.materialsUniqueIds.push(subMat.uniqueId);\r\n serializationObject.materials.push(subMat.id);\r\n } else {\r\n serializationObject.materialsUniqueIds.push(null);\r\n serializationObject.materials.push(null);\r\n }\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Dispose the material and release its associated resources\r\n * @param forceDisposeEffect Define if we want to force disposing the associated effect (if false the shader is not released and could be reuse later on)\r\n * @param forceDisposeTextures Define if we want to force disposing the associated textures (if false, they will not be disposed and can still be use elsewhere in the app)\r\n * @param forceDisposeChildren Define if we want to force disposing the associated submaterials (if false, they will not be disposed and can still be use elsewhere in the app)\r\n */\r\n public dispose(forceDisposeEffect?: boolean, forceDisposeTextures?: boolean, forceDisposeChildren?: boolean): void {\r\n const scene = this.getScene();\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n if (forceDisposeChildren) {\r\n for (let index = 0; index < this.subMaterials.length; index++) {\r\n const subMaterial = this.subMaterials[index];\r\n if (subMaterial) {\r\n subMaterial.dispose(forceDisposeEffect, forceDisposeTextures);\r\n }\r\n }\r\n }\r\n\r\n const index = scene.multiMaterials.indexOf(this);\r\n if (index >= 0) {\r\n scene.multiMaterials.splice(index, 1);\r\n }\r\n\r\n super.dispose(forceDisposeEffect, forceDisposeTextures);\r\n }\r\n\r\n /**\r\n * Creates a MultiMaterial from parsed MultiMaterial data.\r\n * @param parsedMultiMaterial defines parsed MultiMaterial data.\r\n * @param scene defines the hosting scene\r\n * @returns a new MultiMaterial\r\n */\r\n public static ParseMultiMaterial(parsedMultiMaterial: any, scene: Scene): MultiMaterial {\r\n const multiMaterial = new MultiMaterial(parsedMultiMaterial.name, scene);\r\n\r\n multiMaterial.id = parsedMultiMaterial.id;\r\n multiMaterial._loadedUniqueId = parsedMultiMaterial.uniqueId;\r\n\r\n if (Tags) {\r\n Tags.AddTagsTo(multiMaterial, parsedMultiMaterial.tags);\r\n }\r\n\r\n if (parsedMultiMaterial.materialsUniqueIds) {\r\n multiMaterial._waitingSubMaterialsUniqueIds = parsedMultiMaterial.materialsUniqueIds;\r\n } else {\r\n parsedMultiMaterial.materials.forEach((subMatId: string) => multiMaterial.subMaterials.push(scene.getLastMaterialById(subMatId)));\r\n }\r\n\r\n return multiMaterial;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.MultiMaterial\", MultiMaterial);\r\n"]}
|
|
@@ -105,6 +105,10 @@ export declare class ShaderMaterial extends PushMaterial {
|
|
|
105
105
|
private _cachedWorldViewMatrix;
|
|
106
106
|
private _cachedWorldViewProjectionMatrix;
|
|
107
107
|
private _multiview;
|
|
108
|
+
/**
|
|
109
|
+
* @internal
|
|
110
|
+
*/
|
|
111
|
+
_materialHelperNeedsPreviousMatrices: boolean;
|
|
108
112
|
/** Define the Url to load snippets */
|
|
109
113
|
static SnippetUrl: string;
|
|
110
114
|
/** Snippet ID if the material was created from the snippet server */
|
|
@@ -117,9 +121,9 @@ export declare class ShaderMaterial extends PushMaterial {
|
|
|
117
121
|
* @param name Define the name of the material in the scene
|
|
118
122
|
* @param scene Define the scene the material belongs to
|
|
119
123
|
* @param shaderPath Defines the route to the shader code in one of three ways:
|
|
120
|
-
* * object: { vertex: "custom", fragment: "custom" }, used with Effect.ShadersStore["customVertexShader"] and Effect.ShadersStore["customFragmentShader"]
|
|
121
|
-
* * object: { vertexElement: "vertexShaderCode", fragmentElement: "fragmentShaderCode" }, used with shader code in script tags
|
|
122
|
-
* * object: { vertexSource: "vertex shader code string", fragmentSource: "fragment shader code string" } using with strings containing the shaders code
|
|
124
|
+
* * object: \{ vertex: "custom", fragment: "custom" \}, used with Effect.ShadersStore["customVertexShader"] and Effect.ShadersStore["customFragmentShader"]
|
|
125
|
+
* * object: \{ vertexElement: "vertexShaderCode", fragmentElement: "fragmentShaderCode" \}, used with shader code in script tags
|
|
126
|
+
* * object: \{ vertexSource: "vertex shader code string", fragmentSource: "fragment shader code string" \} using with strings containing the shaders code
|
|
123
127
|
* * string: "./COMMON_NAME", used with external files COMMON_NAME.vertex.fx and COMMON_NAME.fragment.fx in index.html folder.
|
|
124
128
|
* @param options Define the options used to create the shader
|
|
125
129
|
* @param storeEffectOnSubMeshes true to store effect on submeshes, false to store the effect directly in the material class.
|
|
@@ -140,6 +144,10 @@ export declare class ShaderMaterial extends PushMaterial {
|
|
|
140
144
|
* They can be modified to trigger a new compilation
|
|
141
145
|
*/
|
|
142
146
|
get options(): IShaderMaterialOptions;
|
|
147
|
+
/**
|
|
148
|
+
* is multiview set to true?
|
|
149
|
+
*/
|
|
150
|
+
get isMultiview(): boolean;
|
|
143
151
|
/**
|
|
144
152
|
* Gets the current class name of the material e.g. "ShaderMaterial"
|
|
145
153
|
* Mainly use in serialization.
|
|
@@ -196,7 +204,7 @@ export declare class ShaderMaterial extends PushMaterial {
|
|
|
196
204
|
* Set a unsigned int in the shader.
|
|
197
205
|
* @param name Define the name of the uniform as defined in the shader
|
|
198
206
|
* @param value Define the value to give to the uniform
|
|
199
|
-
* @
|
|
207
|
+
* @returns the material itself allowing "fluent" like uniform updates
|
|
200
208
|
*/
|
|
201
209
|
setUInt(name: string, value: number): ShaderMaterial;
|
|
202
210
|
/**
|
|
@@ -339,6 +347,17 @@ export declare class ShaderMaterial extends PushMaterial {
|
|
|
339
347
|
* @returns the material itself allowing "fluent" like uniform updates
|
|
340
348
|
*/
|
|
341
349
|
setStorageBuffer(name: string, buffer: StorageBuffer): ShaderMaterial;
|
|
350
|
+
/**
|
|
351
|
+
* Adds, removes, or replaces the specified shader define and value.
|
|
352
|
+
* * setShaderDefine("MY_DEFINE", true); // enables a boolean define
|
|
353
|
+
* * setShaderDefine("MY_DEFINE", "0.5"); // adds "#define MY_DEFINE 0.5" to the shader (or sets and replaces the value of any existing define with that name)
|
|
354
|
+
* * setShaderDefine("MY_DEFINE", false); // disables and removes the define
|
|
355
|
+
* Note if the active defines do change, the shader will be recompiled and this can be expensive.
|
|
356
|
+
* @param define the define name e.g., "OUTPUT_TO_SRGB" or "#define OUTPUT_TO_SRGB". If the define was passed into the constructor already, the version used should match that, and in either case, it should not include any appended value.
|
|
357
|
+
* @param value either the value of the define (e.g. a numerical value) or for booleans, true if the define should be enabled or false if it should be disabled
|
|
358
|
+
* @returns the material itself allowing "fluent" like uniform updates
|
|
359
|
+
*/
|
|
360
|
+
setDefine(define: string, value: boolean | string): ShaderMaterial;
|
|
342
361
|
/**
|
|
343
362
|
* Specifies that the submesh is ready to be used
|
|
344
363
|
* @param mesh defines the mesh to check
|
|
@@ -28,9 +28,9 @@ export class ShaderMaterial extends PushMaterial {
|
|
|
28
28
|
* @param name Define the name of the material in the scene
|
|
29
29
|
* @param scene Define the scene the material belongs to
|
|
30
30
|
* @param shaderPath Defines the route to the shader code in one of three ways:
|
|
31
|
-
* * object: { vertex: "custom", fragment: "custom" }, used with Effect.ShadersStore["customVertexShader"] and Effect.ShadersStore["customFragmentShader"]
|
|
32
|
-
* * object: { vertexElement: "vertexShaderCode", fragmentElement: "fragmentShaderCode" }, used with shader code in script tags
|
|
33
|
-
* * object: { vertexSource: "vertex shader code string", fragmentSource: "fragment shader code string" } using with strings containing the shaders code
|
|
31
|
+
* * object: \{ vertex: "custom", fragment: "custom" \}, used with Effect.ShadersStore["customVertexShader"] and Effect.ShadersStore["customFragmentShader"]
|
|
32
|
+
* * object: \{ vertexElement: "vertexShaderCode", fragmentElement: "fragmentShaderCode" \}, used with shader code in script tags
|
|
33
|
+
* * object: \{ vertexSource: "vertex shader code string", fragmentSource: "fragment shader code string" \} using with strings containing the shaders code
|
|
34
34
|
* * string: "./COMMON_NAME", used with external files COMMON_NAME.vertex.fx and COMMON_NAME.fragment.fx in index.html folder.
|
|
35
35
|
* @param options Define the options used to create the shader
|
|
36
36
|
* @param storeEffectOnSubMeshes true to store effect on submeshes, false to store the effect directly in the material class.
|
|
@@ -66,6 +66,10 @@ export class ShaderMaterial extends PushMaterial {
|
|
|
66
66
|
this._cachedWorldViewMatrix = new Matrix();
|
|
67
67
|
this._cachedWorldViewProjectionMatrix = new Matrix();
|
|
68
68
|
this._multiview = false;
|
|
69
|
+
/**
|
|
70
|
+
* @internal
|
|
71
|
+
*/
|
|
72
|
+
this._materialHelperNeedsPreviousMatrices = false;
|
|
69
73
|
this._shaderPath = shaderPath;
|
|
70
74
|
this._options = {
|
|
71
75
|
needAlphaBlending: false,
|
|
@@ -103,6 +107,12 @@ export class ShaderMaterial extends PushMaterial {
|
|
|
103
107
|
get options() {
|
|
104
108
|
return this._options;
|
|
105
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* is multiview set to true?
|
|
112
|
+
*/
|
|
113
|
+
get isMultiview() {
|
|
114
|
+
return this._multiview;
|
|
115
|
+
}
|
|
106
116
|
/**
|
|
107
117
|
* Gets the current class name of the material e.g. "ShaderMaterial"
|
|
108
118
|
* Mainly use in serialization.
|
|
@@ -196,7 +206,7 @@ export class ShaderMaterial extends PushMaterial {
|
|
|
196
206
|
* Set a unsigned int in the shader.
|
|
197
207
|
* @param name Define the name of the uniform as defined in the shader
|
|
198
208
|
* @param value Define the value to give to the uniform
|
|
199
|
-
* @
|
|
209
|
+
* @returns the material itself allowing "fluent" like uniform updates
|
|
200
210
|
*/
|
|
201
211
|
setUInt(name, value) {
|
|
202
212
|
this._checkUniform(name);
|
|
@@ -443,6 +453,29 @@ export class ShaderMaterial extends PushMaterial {
|
|
|
443
453
|
this._storageBuffers[name] = buffer;
|
|
444
454
|
return this;
|
|
445
455
|
}
|
|
456
|
+
/**
|
|
457
|
+
* Adds, removes, or replaces the specified shader define and value.
|
|
458
|
+
* * setShaderDefine("MY_DEFINE", true); // enables a boolean define
|
|
459
|
+
* * setShaderDefine("MY_DEFINE", "0.5"); // adds "#define MY_DEFINE 0.5" to the shader (or sets and replaces the value of any existing define with that name)
|
|
460
|
+
* * setShaderDefine("MY_DEFINE", false); // disables and removes the define
|
|
461
|
+
* Note if the active defines do change, the shader will be recompiled and this can be expensive.
|
|
462
|
+
* @param define the define name e.g., "OUTPUT_TO_SRGB" or "#define OUTPUT_TO_SRGB". If the define was passed into the constructor already, the version used should match that, and in either case, it should not include any appended value.
|
|
463
|
+
* @param value either the value of the define (e.g. a numerical value) or for booleans, true if the define should be enabled or false if it should be disabled
|
|
464
|
+
* @returns the material itself allowing "fluent" like uniform updates
|
|
465
|
+
*/
|
|
466
|
+
setDefine(define, value) {
|
|
467
|
+
// First remove any existing define with this name.
|
|
468
|
+
const defineName = define.trimEnd() + " ";
|
|
469
|
+
const existingDefineIdx = this.options.defines.findIndex((x) => x === define || x.startsWith(defineName));
|
|
470
|
+
if (existingDefineIdx >= 0) {
|
|
471
|
+
this.options.defines.splice(existingDefineIdx, 1);
|
|
472
|
+
}
|
|
473
|
+
// Then add the new define value. (If it's a boolean value and false, don't add it.)
|
|
474
|
+
if (typeof value !== "boolean" || value) {
|
|
475
|
+
this.options.defines.push(defineName + value);
|
|
476
|
+
}
|
|
477
|
+
return this;
|
|
478
|
+
}
|
|
446
479
|
/**
|
|
447
480
|
* Specifies that the submesh is ready to be used
|
|
448
481
|
* @param mesh defines the mesh to check
|
|
@@ -504,7 +537,7 @@ export class ShaderMaterial extends PushMaterial {
|
|
|
504
537
|
}
|
|
505
538
|
if (useInstances) {
|
|
506
539
|
defines.push("#define INSTANCES");
|
|
507
|
-
MaterialHelper.PushAttributesForInstances(attribs);
|
|
540
|
+
MaterialHelper.PushAttributesForInstances(attribs, this._materialHelperNeedsPreviousMatrices);
|
|
508
541
|
if (mesh === null || mesh === void 0 ? void 0 : mesh.hasThinInstances) {
|
|
509
542
|
defines.push("#define THIN_INSTANCES");
|
|
510
543
|
if (mesh && mesh.isVerticesDataPresent(VertexBuffer.ColorInstanceKind)) {
|