@babylonjs/core 5.8.0 → 5.8.1
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/Engines/Extensions/engine.rawTexture.js +2 -0
- package/Engines/Extensions/engine.rawTexture.js.map +1 -1
- package/Engines/engine.d.ts +2 -31
- package/Engines/nullEngine.js +3 -1
- package/Engines/nullEngine.js.map +1 -1
- package/Engines/thinEngine.js +2 -2
- package/Engines/thinEngine.js.map +1 -1
- package/Inputs/scene.inputManager.js +5 -2
- package/Inputs/scene.inputManager.js.map +1 -1
- package/Materials/Node/nodeMaterial.d.ts +1 -1
- package/Materials/Node/nodeMaterial.js +1 -0
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Materials/effect.d.ts +1 -0
- package/Materials/effect.js +5 -0
- package/Materials/effect.js.map +1 -1
- package/Meshes/instancedMesh.js +1 -0
- package/Meshes/instancedMesh.js.map +1 -1
- package/Rendering/geometryBufferRenderer.d.ts +6 -2
- package/Rendering/geometryBufferRenderer.js +209 -18
- package/Rendering/geometryBufferRenderer.js.map +1 -1
- package/Shaders/default.fragment.js +1 -1
- package/Shaders/default.fragment.js.map +1 -1
- package/Shaders/geometry.fragment.d.ts +1 -0
- package/Shaders/geometry.fragment.js +2 -1
- package/Shaders/geometry.fragment.js.map +1 -1
- package/Shaders/geometry.vertex.js +1 -1
- package/Shaders/geometry.vertex.js.map +1 -1
- package/Shaders/pbr.fragment.js +1 -1
- package/Shaders/pbr.fragment.js.map +1 -1
- package/package.json +1 -1
- package/scene.d.ts +4 -0
- package/scene.js +4 -0
- package/scene.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instancedMesh.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Meshes/instancedMesh.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB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AC,4BAA4B,CAAC,kBAAkB,EAAE;QACrE,IAAI,CAAC,SAAS,EAAE,CAAC,wBAAwB,CAAC,IAAI,CAAC,4BAA4B,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;KACzG;IAED,IAAI,CAAC,4BAA4B,CAAC,kBAAkB,GAAG,EAAE,CAAC;AAC9D,CAAC,CAAC;AAEF,IAAI,CAAC,SAAS,CAAC,4BAA4B,GAAG;IAC1C,IAAI,IAAI,CAAC,oBAAoB,CAAC,eAAe,EAAE;QAC3C,IAAI,CAAC,oBAAoB,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC;QACpD,IAAI,CAAC,oBAAoB,CAAC,eAAe,GAAG,IAAI,CAAC;KACpD;IAED,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE;QAC1B,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;KAC/B;IAED,KAAK,IAAM,IAAI,IAAI,IAAI,CAAC,gBAAgB,EAAE;QACtC,IAAI,IAAI,CAAC,4BAA4B,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE;YACvD,IAAI,CAAC,4BAA4B,CAAC,aAAa,CAAC,IAAI,CAAE,CAAC,OAAO,EAAE,CAAC;SACpE;KACJ;IAED,IAAI,CAAC,oCAAoC,EAAE,CAAC;IAE5C,IAAI,CAAC,gBAAgB,GAAG,EAAE,CAAC;AAC/B,CAAC,CAAC","sourcesContent":["import type { Nullable, FloatArray, IndicesArray } from \"../types\";\r\nimport type { Vector3 } from \"../Maths/math.vector\";\r\nimport { Matrix, TmpVectors } from \"../Maths/math.vector\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport type { Node } from \"../node\";\r\nimport { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport type { Material } from \"../Materials/material\";\r\nimport type { Skeleton } from \"../Bones/skeleton\";\r\nimport { DeepCopier } from \"../Misc/deepCopier\";\r\nimport { TransformNode } from \"./transformNode\";\r\nimport type { Light } from \"../Lights/light\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { Tools } from \"../Misc/tools\";\r\n\r\nMesh._instancedMeshFactory = (name: string, mesh: Mesh): InstancedMesh => {\r\n const instance = new InstancedMesh(name, mesh);\r\n\r\n if (mesh.instancedBuffers) {\r\n instance.instancedBuffers = {};\r\n\r\n for (const key in mesh.instancedBuffers) {\r\n instance.instancedBuffers[key] = mesh.instancedBuffers[key];\r\n }\r\n }\r\n\r\n return instance;\r\n};\r\n\r\n/**\r\n * Creates an instance based on a source mesh.\r\n */\r\nexport class InstancedMesh extends AbstractMesh {\r\n private _sourceMesh: Mesh;\r\n private _currentLOD: Mesh;\r\n private _billboardWorldMatrix: Matrix;\r\n\r\n /** @hidden */\r\n public _indexInSourceMeshInstanceArray = -1;\r\n /** @hidden */\r\n public _distanceToCamera: number = 0;\r\n /** @hidden */\r\n public _previousWorldMatrix: Nullable<Matrix>;\r\n\r\n constructor(name: string, source: Mesh) {\r\n super(name, source.getScene());\r\n\r\n source.addInstance(this);\r\n\r\n this._sourceMesh = source;\r\n\r\n this._unIndexed = source._unIndexed;\r\n\r\n this.position.copyFrom(source.position);\r\n this.rotation.copyFrom(source.rotation);\r\n this.scaling.copyFrom(source.scaling);\r\n\r\n if (source.rotationQuaternion) {\r\n this.rotationQuaternion = source.rotationQuaternion.clone();\r\n }\r\n\r\n this.animations = Tools.Slice(source.animations);\r\n for (const range of source.getAnimationRanges()) {\r\n if (range != null) {\r\n this.createAnimationRange(range.name, range.from, range.to);\r\n }\r\n }\r\n\r\n this.infiniteDistance = source.infiniteDistance;\r\n\r\n this.setPivotMatrix(source.getPivotMatrix());\r\n\r\n this.refreshBoundingInfo(true, true);\r\n this._syncSubMeshes();\r\n }\r\n\r\n /**\r\n * Returns the string \"InstancedMesh\".\r\n */\r\n public getClassName(): string {\r\n return \"InstancedMesh\";\r\n }\r\n\r\n /** Gets the list of lights affecting that mesh */\r\n public get lightSources(): Light[] {\r\n return this._sourceMesh._lightSources;\r\n }\r\n\r\n public _resyncLightSources(): void {\r\n // Do nothing as all the work will be done by source mesh\r\n }\r\n\r\n public _resyncLightSource(): void {\r\n // Do nothing as all the work will be done by source mesh\r\n }\r\n\r\n public _removeLightSource(): void {\r\n // Do nothing as all the work will be done by source mesh\r\n }\r\n\r\n // Methods\r\n /**\r\n * If the source mesh receives shadows\r\n */\r\n public get receiveShadows(): boolean {\r\n return this._sourceMesh.receiveShadows;\r\n }\r\n\r\n /**\r\n * The material of the source mesh\r\n */\r\n public get material(): Nullable<Material> {\r\n return this._sourceMesh.material;\r\n }\r\n\r\n /**\r\n * Visibility of the source mesh\r\n */\r\n public get visibility(): number {\r\n return this._sourceMesh.visibility;\r\n }\r\n\r\n /**\r\n * Skeleton of the source mesh\r\n */\r\n public get skeleton(): Nullable<Skeleton> {\r\n return this._sourceMesh.skeleton;\r\n }\r\n\r\n /**\r\n * Rendering ground id of the source mesh\r\n */\r\n public get renderingGroupId(): number {\r\n return this._sourceMesh.renderingGroupId;\r\n }\r\n\r\n public set renderingGroupId(value: number) {\r\n if (!this._sourceMesh || value === this._sourceMesh.renderingGroupId) {\r\n return;\r\n }\r\n\r\n //no-op with warning\r\n Logger.Warn(\"Note - setting renderingGroupId of an instanced mesh has no effect on the scene\");\r\n }\r\n\r\n /**\r\n * Returns the total number of vertices (integer).\r\n */\r\n public getTotalVertices(): number {\r\n return this._sourceMesh ? this._sourceMesh.getTotalVertices() : 0;\r\n }\r\n\r\n /**\r\n * Returns a positive integer : the total number of indices in this mesh geometry.\r\n * @returns the number of indices or zero if the mesh has no geometry.\r\n */\r\n public getTotalIndices(): number {\r\n return this._sourceMesh.getTotalIndices();\r\n }\r\n\r\n /**\r\n * The source mesh of the instance\r\n */\r\n public get sourceMesh(): Mesh {\r\n return this._sourceMesh;\r\n }\r\n\r\n /**\r\n * Creates a new InstancedMesh object from the mesh model.\r\n * @see https://doc.babylonjs.com/how_to/how_to_use_instances\r\n * @param name defines the name of the new instance\r\n * @returns a new InstancedMesh\r\n */\r\n public createInstance(name: string): InstancedMesh {\r\n return this._sourceMesh.createInstance(name);\r\n }\r\n\r\n /**\r\n * Is this node ready to be used/rendered\r\n * @param completeCheck defines if a complete check (including materials and lights) has to be done (false by default)\r\n * @return {boolean} is it ready\r\n */\r\n public isReady(completeCheck = false): boolean {\r\n return this._sourceMesh.isReady(completeCheck, true);\r\n }\r\n\r\n /**\r\n * Returns an array of integers or a typed array (Int32Array, Uint32Array, Uint16Array) populated with the mesh indices.\r\n * @param kind kind of verticies to retrieve (eg. positions, normals, uvs, etc.)\r\n * @param copyWhenShared If true (default false) and and if the mesh geometry is shared among some other meshes, the returned array is a copy of the internal one.\r\n * @returns a float array or a Float32Array of the requested kind of data : positions, normals, uvs, etc.\r\n */\r\n public getVerticesData(kind: string, copyWhenShared?: boolean): Nullable<FloatArray> {\r\n return this._sourceMesh.getVerticesData(kind, copyWhenShared);\r\n }\r\n\r\n /**\r\n * Sets the vertex data of the mesh geometry for the requested `kind`.\r\n * If the mesh has no geometry, a new Geometry object is set to the mesh and then passed this vertex data.\r\n * The `data` are either a numeric array either a Float32Array.\r\n * The parameter `updatable` is passed as is to the underlying Geometry object constructor (if initially none) or updater.\r\n * The parameter `stride` is an optional positive integer, it is usually automatically deducted from the `kind` (3 for positions or normals, 2 for UV, etc).\r\n * Note that a new underlying VertexBuffer object is created each call.\r\n * If the `kind` is the `PositionKind`, the mesh BoundingInfo is renewed, so the bounding box and sphere, and the mesh World Matrix is recomputed.\r\n *\r\n * Possible `kind` values :\r\n * - VertexBuffer.PositionKind\r\n * - VertexBuffer.UVKind\r\n * - VertexBuffer.UV2Kind\r\n * - VertexBuffer.UV3Kind\r\n * - VertexBuffer.UV4Kind\r\n * - VertexBuffer.UV5Kind\r\n * - VertexBuffer.UV6Kind\r\n * - VertexBuffer.ColorKind\r\n * - VertexBuffer.MatricesIndicesKind\r\n * - VertexBuffer.MatricesIndicesExtraKind\r\n * - VertexBuffer.MatricesWeightsKind\r\n * - VertexBuffer.MatricesWeightsExtraKind\r\n *\r\n * Returns the Mesh.\r\n * @param kind\r\n * @param data\r\n * @param updatable\r\n * @param stride\r\n */\r\n public setVerticesData(kind: string, data: FloatArray, updatable?: boolean, stride?: number): AbstractMesh {\r\n if (this.sourceMesh) {\r\n this.sourceMesh.setVerticesData(kind, data, updatable, stride);\r\n }\r\n return this.sourceMesh;\r\n }\r\n\r\n /**\r\n * Updates the existing vertex data of the mesh geometry for the requested `kind`.\r\n * If the mesh has no geometry, it is simply returned as it is.\r\n * The `data` are either a numeric array either a Float32Array.\r\n * No new underlying VertexBuffer object is created.\r\n * If the `kind` is the `PositionKind` and if `updateExtends` is true, the mesh BoundingInfo is renewed, so the bounding box and sphere, and the mesh World Matrix is recomputed.\r\n * If the parameter `makeItUnique` is true, a new global geometry is created from this positions and is set to the mesh.\r\n *\r\n * Possible `kind` values :\r\n * - VertexBuffer.PositionKind\r\n * - VertexBuffer.UVKind\r\n * - VertexBuffer.UV2Kind\r\n * - VertexBuffer.UV3Kind\r\n * - VertexBuffer.UV4Kind\r\n * - VertexBuffer.UV5Kind\r\n * - VertexBuffer.UV6Kind\r\n * - VertexBuffer.ColorKind\r\n * - VertexBuffer.MatricesIndicesKind\r\n * - VertexBuffer.MatricesIndicesExtraKind\r\n * - VertexBuffer.MatricesWeightsKind\r\n * - VertexBuffer.MatricesWeightsExtraKind\r\n *\r\n * Returns the Mesh.\r\n * @param kind\r\n * @param data\r\n * @param updateExtends\r\n * @param makeItUnique\r\n */\r\n public updateVerticesData(kind: string, data: FloatArray, updateExtends?: boolean, makeItUnique?: boolean): Mesh {\r\n if (this.sourceMesh) {\r\n this.sourceMesh.updateVerticesData(kind, data, updateExtends, makeItUnique);\r\n }\r\n return this.sourceMesh;\r\n }\r\n\r\n /**\r\n * Sets the mesh indices.\r\n * Expects an array populated with integers or a typed array (Int32Array, Uint32Array, Uint16Array).\r\n * If the mesh has no geometry, a new Geometry object is created and set to the mesh.\r\n * This method creates a new index buffer each call.\r\n * Returns the Mesh.\r\n * @param indices\r\n * @param totalVertices\r\n */\r\n public setIndices(indices: IndicesArray, totalVertices: Nullable<number> = null): Mesh {\r\n if (this.sourceMesh) {\r\n this.sourceMesh.setIndices(indices, totalVertices);\r\n }\r\n return this.sourceMesh;\r\n }\r\n\r\n /**\r\n * Boolean : True if the mesh owns the requested kind of data.\r\n * @param kind\r\n */\r\n public isVerticesDataPresent(kind: string): boolean {\r\n return this._sourceMesh.isVerticesDataPresent(kind);\r\n }\r\n\r\n /**\r\n * Returns an array of indices (IndicesArray).\r\n */\r\n public getIndices(): Nullable<IndicesArray> {\r\n return this._sourceMesh.getIndices();\r\n }\r\n\r\n public get _positions(): Nullable<Vector3[]> {\r\n return this._sourceMesh._positions;\r\n }\r\n\r\n /**\r\n * This method recomputes and sets a new BoundingInfo to the mesh unless it is locked.\r\n * This means the mesh underlying bounding box and sphere are recomputed.\r\n * @param applySkeleton defines whether to apply the skeleton before computing the bounding info\r\n * @param applyMorph defines whether to apply the morph target before computing the bounding info\r\n * @returns the current mesh\r\n */\r\n public refreshBoundingInfo(applySkeleton: boolean = false, applyMorph: boolean = false): InstancedMesh {\r\n if (this.hasBoundingInfo && this.getBoundingInfo().isLocked) {\r\n return this;\r\n }\r\n\r\n const bias = this._sourceMesh.geometry ? this._sourceMesh.geometry.boundingBias : null;\r\n this._refreshBoundingInfo(this._sourceMesh._getPositionData(applySkeleton, applyMorph), bias);\r\n return this;\r\n }\r\n\r\n /** @hidden */\r\n public _preActivate(): InstancedMesh {\r\n if (this._currentLOD) {\r\n this._currentLOD._preActivate();\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * @param renderId\r\n * @param intermediateRendering\r\n * @hidden\r\n */\r\n public _activate(renderId: number, intermediateRendering: boolean): boolean {\r\n if (!this._sourceMesh.subMeshes) {\r\n Logger.Warn(\"Instances should only be created for meshes with geometry.\");\r\n }\r\n\r\n if (this._currentLOD) {\r\n const differentSign = this._currentLOD._getWorldMatrixDeterminant() >= 0 !== this._getWorldMatrixDeterminant() >= 0;\r\n if (differentSign) {\r\n this._internalAbstractMeshDataInfo._actAsRegularMesh = true;\r\n return true;\r\n }\r\n this._internalAbstractMeshDataInfo._actAsRegularMesh = false;\r\n\r\n this._currentLOD._registerInstanceForRenderId(this, renderId);\r\n\r\n if (intermediateRendering) {\r\n if (!this._currentLOD._internalAbstractMeshDataInfo._isActiveIntermediate) {\r\n this._currentLOD._internalAbstractMeshDataInfo._onlyForInstancesIntermediate = true;\r\n return true;\r\n }\r\n } else {\r\n if (!this._currentLOD._internalAbstractMeshDataInfo._isActive) {\r\n this._currentLOD._internalAbstractMeshDataInfo._onlyForInstances = true;\r\n return true;\r\n }\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n /** @hidden */\r\n public _postActivate(): void {\r\n if (this._sourceMesh.edgesShareWithInstances && this._sourceMesh._edgesRenderer && this._sourceMesh._edgesRenderer.isEnabled && this._sourceMesh._renderingGroup) {\r\n // we are using the edge renderer of the source mesh\r\n this._sourceMesh._renderingGroup._edgesRenderers.pushNoDuplicate(this._sourceMesh._edgesRenderer);\r\n this._sourceMesh._edgesRenderer.customInstances.push(this.getWorldMatrix());\r\n } else if (this._edgesRenderer && this._edgesRenderer.isEnabled && this._sourceMesh._renderingGroup) {\r\n // we are using the edge renderer defined for this instance\r\n this._sourceMesh._renderingGroup._edgesRenderers.push(this._edgesRenderer);\r\n }\r\n }\r\n\r\n public getWorldMatrix(): Matrix {\r\n if (this._currentLOD && this._currentLOD.billboardMode !== TransformNode.BILLBOARDMODE_NONE && this._currentLOD._masterMesh !== this) {\r\n if (!this._billboardWorldMatrix) {\r\n this._billboardWorldMatrix = new Matrix();\r\n }\r\n const tempMaster = this._currentLOD._masterMesh;\r\n this._currentLOD._masterMesh = this;\r\n TmpVectors.Vector3[7].copyFrom(this._currentLOD.position);\r\n this._currentLOD.position.set(0, 0, 0);\r\n this._billboardWorldMatrix.copyFrom(this._currentLOD.computeWorldMatrix(true));\r\n this._currentLOD.position.copyFrom(TmpVectors.Vector3[7]);\r\n this._currentLOD._masterMesh = tempMaster;\r\n return this._billboardWorldMatrix;\r\n }\r\n\r\n return super.getWorldMatrix();\r\n }\r\n\r\n public get isAnInstance(): boolean {\r\n return true;\r\n }\r\n\r\n /**\r\n * Returns the current associated LOD AbstractMesh.\r\n * @param camera\r\n */\r\n public getLOD(camera: Camera): AbstractMesh {\r\n if (!camera) {\r\n return this;\r\n }\r\n\r\n const sourceMeshLODLevels = this.sourceMesh.getLODLevels();\r\n if (!sourceMeshLODLevels || sourceMeshLODLevels.length === 0) {\r\n this._currentLOD = this.sourceMesh;\r\n } else {\r\n const boundingInfo = this.getBoundingInfo();\r\n this._currentLOD = <Mesh>this.sourceMesh.getLOD(camera, boundingInfo.boundingSphere);\r\n }\r\n\r\n return this._currentLOD;\r\n }\r\n\r\n /**\r\n * @param renderId\r\n * @hidden\r\n */\r\n public _preActivateForIntermediateRendering(renderId: number): Mesh {\r\n return <Mesh>this.sourceMesh._preActivateForIntermediateRendering(renderId);\r\n }\r\n\r\n /** @hidden */\r\n public _syncSubMeshes(): InstancedMesh {\r\n this.releaseSubMeshes();\r\n if (this._sourceMesh.subMeshes) {\r\n for (let index = 0; index < this._sourceMesh.subMeshes.length; index++) {\r\n this._sourceMesh.subMeshes[index].clone(this, this._sourceMesh);\r\n }\r\n }\r\n return this;\r\n }\r\n\r\n /** @hidden */\r\n public _generatePointsArray(): boolean {\r\n return this._sourceMesh._generatePointsArray();\r\n }\r\n\r\n /** @hidden */\r\n public _updateBoundingInfo(): AbstractMesh {\r\n if (this.hasBoundingInfo) {\r\n this.getBoundingInfo().update(this.worldMatrixFromCache);\r\n } else {\r\n this.buildBoundingInfo(this.absolutePosition, this.absolutePosition, this.worldMatrixFromCache);\r\n }\r\n this._updateSubMeshesBoundingInfo(this.worldMatrixFromCache);\r\n return this;\r\n }\r\n\r\n /**\r\n * Creates a new InstancedMesh from the current mesh.\r\n * - name (string) : the cloned mesh name\r\n * - newParent (optional Node) : the optional Node to parent the clone to.\r\n * - doNotCloneChildren (optional boolean, default `false`) : if `true` the model children aren't cloned.\r\n *\r\n * Returns the clone.\r\n * @param name\r\n * @param newParent\r\n * @param doNotCloneChildren\r\n */\r\n public clone(name: string, newParent: Nullable<Node> = null, doNotCloneChildren?: boolean): InstancedMesh {\r\n const result = this._sourceMesh.createInstance(name);\r\n\r\n // Deep copy\r\n DeepCopier.DeepCopy(\r\n this,\r\n result,\r\n [\r\n \"name\",\r\n \"subMeshes\",\r\n \"uniqueId\",\r\n \"parent\",\r\n \"lightSources\",\r\n \"receiveShadows\",\r\n \"material\",\r\n \"visibility\",\r\n \"skeleton\",\r\n \"sourceMesh\",\r\n \"isAnInstance\",\r\n \"facetNb\",\r\n \"isFacetDataEnabled\",\r\n \"isBlocked\",\r\n \"useBones\",\r\n \"hasInstances\",\r\n \"collider\",\r\n \"edgesRenderer\",\r\n \"forward\",\r\n \"up\",\r\n \"right\",\r\n \"absolutePosition\",\r\n \"absoluteScaling\",\r\n \"absoluteRotationQuaternion\",\r\n \"isWorldMatrixFrozen\",\r\n \"nonUniformScaling\",\r\n \"behaviors\",\r\n \"worldMatrixFromCache\",\r\n \"hasThinInstances\",\r\n \"hasBoundingInfo\",\r\n ],\r\n []\r\n );\r\n\r\n // Bounding info\r\n this.refreshBoundingInfo();\r\n\r\n // Parent\r\n if (newParent) {\r\n result.parent = newParent;\r\n }\r\n\r\n if (!doNotCloneChildren) {\r\n // Children\r\n for (let index = 0; index < this.getScene().meshes.length; index++) {\r\n const mesh = this.getScene().meshes[index];\r\n\r\n if (mesh.parent === this) {\r\n mesh.clone(mesh.name, result);\r\n }\r\n }\r\n }\r\n\r\n result.computeWorldMatrix(true);\r\n\r\n this.onClonedObservable.notifyObservers(result);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Disposes the InstancedMesh.\r\n * Returns nothing.\r\n * @param doNotRecurse\r\n * @param disposeMaterialAndTextures\r\n */\r\n public dispose(doNotRecurse?: boolean, disposeMaterialAndTextures = false): void {\r\n // Remove from mesh\r\n this._sourceMesh.removeInstance(this);\r\n super.dispose(doNotRecurse, disposeMaterialAndTextures);\r\n }\r\n}\r\n\r\ndeclare module \"./mesh\" {\r\n export interface Mesh {\r\n /**\r\n * Register a custom buffer that will be instanced\r\n * @see https://doc.babylonjs.com/how_to/how_to_use_instances#custom-buffers\r\n * @param kind defines the buffer kind\r\n * @param stride defines the stride in floats\r\n */\r\n registerInstancedBuffer(kind: string, stride: number): void;\r\n\r\n /**\r\n * Invalidate VertexArrayObjects belonging to the mesh (but not to the Geometry of the mesh).\r\n */\r\n _invalidateInstanceVertexArrayObject(): void;\r\n\r\n /**\r\n * true to use the edge renderer for all instances of this mesh\r\n */\r\n edgesShareWithInstances: boolean;\r\n\r\n /** @hidden */\r\n _userInstancedBuffersStorage: {\r\n data: { [key: string]: Float32Array };\r\n sizes: { [key: string]: number };\r\n vertexBuffers: { [key: string]: Nullable<VertexBuffer> };\r\n strides: { [key: string]: number };\r\n vertexArrayObjects?: { [key: string]: WebGLVertexArrayObject };\r\n };\r\n }\r\n}\r\n\r\ndeclare module \"./abstractMesh\" {\r\n export interface AbstractMesh {\r\n /**\r\n * Object used to store instanced buffers defined by user\r\n * @see https://doc.babylonjs.com/how_to/how_to_use_instances#custom-buffers\r\n */\r\n instancedBuffers: { [key: string]: any };\r\n }\r\n}\r\n\r\nMesh.prototype.registerInstancedBuffer = function (kind: string, stride: number): void {\r\n // Remove existing one\r\n this._userInstancedBuffersStorage?.vertexBuffers[kind]?.dispose();\r\n\r\n // Creates the instancedBuffer field if not present\r\n if (!this.instancedBuffers) {\r\n this.instancedBuffers = {};\r\n\r\n for (const instance of this.instances) {\r\n instance.instancedBuffers = {};\r\n }\r\n\r\n this._userInstancedBuffersStorage = {\r\n data: {},\r\n vertexBuffers: {},\r\n strides: {},\r\n sizes: {},\r\n vertexArrayObjects: this.getEngine().getCaps().vertexArrayObject ? {} : undefined,\r\n };\r\n }\r\n\r\n // Creates an empty property for this kind\r\n this.instancedBuffers[kind] = null;\r\n\r\n this._userInstancedBuffersStorage.strides[kind] = stride;\r\n this._userInstancedBuffersStorage.sizes[kind] = stride * 32; // Initial size\r\n this._userInstancedBuffersStorage.data[kind] = new Float32Array(this._userInstancedBuffersStorage.sizes[kind]);\r\n this._userInstancedBuffersStorage.vertexBuffers[kind] = new VertexBuffer(this.getEngine(), this._userInstancedBuffersStorage.data[kind], kind, true, false, stride, true);\r\n\r\n for (const instance of this.instances) {\r\n instance.instancedBuffers[kind] = null;\r\n }\r\n\r\n this._invalidateInstanceVertexArrayObject();\r\n};\r\n\r\nMesh.prototype._processInstancedBuffers = function (visibleInstances: InstancedMesh[], renderSelf: boolean) {\r\n const instanceCount = visibleInstances.length;\r\n\r\n for (const kind in this.instancedBuffers) {\r\n let size = this._userInstancedBuffersStorage.sizes[kind];\r\n const stride = this._userInstancedBuffersStorage.strides[kind];\r\n\r\n // Resize if required\r\n const expectedSize = (instanceCount + 1) * stride;\r\n\r\n while (size < expectedSize) {\r\n size *= 2;\r\n }\r\n\r\n if (this._userInstancedBuffersStorage.data[kind].length != size) {\r\n this._userInstancedBuffersStorage.data[kind] = new Float32Array(size);\r\n this._userInstancedBuffersStorage.sizes[kind] = size;\r\n if (this._userInstancedBuffersStorage.vertexBuffers[kind]) {\r\n this._userInstancedBuffersStorage.vertexBuffers[kind]!.dispose();\r\n this._userInstancedBuffersStorage.vertexBuffers[kind] = null;\r\n }\r\n }\r\n\r\n const data = this._userInstancedBuffersStorage.data[kind];\r\n\r\n // Update data buffer\r\n let offset = 0;\r\n if (renderSelf) {\r\n const value = this.instancedBuffers[kind];\r\n\r\n if (value.toArray) {\r\n value.toArray(data, offset);\r\n } else if (value.copyToArray) {\r\n value.copyToArray(data, offset);\r\n } else {\r\n data[offset] = value;\r\n }\r\n\r\n offset += stride;\r\n }\r\n\r\n for (let instanceIndex = 0; instanceIndex < instanceCount; instanceIndex++) {\r\n const instance = visibleInstances[instanceIndex]!;\r\n\r\n const value = instance.instancedBuffers[kind];\r\n\r\n if (value.toArray) {\r\n value.toArray(data, offset);\r\n } else if (value.copyToArray) {\r\n value.copyToArray(data, offset);\r\n } else {\r\n data[offset] = value;\r\n }\r\n\r\n offset += stride;\r\n }\r\n\r\n // Update vertex buffer\r\n if (!this._userInstancedBuffersStorage.vertexBuffers[kind]) {\r\n this._userInstancedBuffersStorage.vertexBuffers[kind] = new VertexBuffer(\r\n this.getEngine(),\r\n this._userInstancedBuffersStorage.data[kind],\r\n kind,\r\n true,\r\n false,\r\n stride,\r\n true\r\n );\r\n this._invalidateInstanceVertexArrayObject();\r\n } else {\r\n this._userInstancedBuffersStorage.vertexBuffers[kind]!.updateDirectly(data, 0);\r\n }\r\n }\r\n};\r\n\r\nMesh.prototype._invalidateInstanceVertexArrayObject = function () {\r\n if (!this._userInstancedBuffersStorage || this._userInstancedBuffersStorage.vertexArrayObjects === undefined) {\r\n return;\r\n }\r\n\r\n for (const kind in this._userInstancedBuffersStorage.vertexArrayObjects) {\r\n this.getEngine().releaseVertexArrayObject(this._userInstancedBuffersStorage.vertexArrayObjects[kind]);\r\n }\r\n\r\n this._userInstancedBuffersStorage.vertexArrayObjects = {};\r\n};\r\n\r\nMesh.prototype._disposeInstanceSpecificData = function () {\r\n if (this._instanceDataStorage.instancesBuffer) {\r\n this._instanceDataStorage.instancesBuffer.dispose();\r\n this._instanceDataStorage.instancesBuffer = null;\r\n }\r\n\r\n while (this.instances.length) {\r\n this.instances[0].dispose();\r\n }\r\n\r\n for (const kind in this.instancedBuffers) {\r\n if (this._userInstancedBuffersStorage.vertexBuffers[kind]) {\r\n this._userInstancedBuffersStorage.vertexBuffers[kind]!.dispose();\r\n }\r\n }\r\n\r\n this._invalidateInstanceVertexArrayObject();\r\n\r\n this.instancedBuffers = {};\r\n};\r\n"]}
|
|
1
|
+
{"version":3,"file":"instancedMesh.js","sourceRoot":"","s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ACJ;AACL,CAAC,CAAC;AAEF,IAAI,CAAC,SAAS,CAAC,oCAAoC,GAAG;IAClD,IAAI,CAAC,IAAI,CAAC,4BAA4B,IAAI,IAAI,CAAC,4BAA4B,CAAC,kBAAkB,KAAK,SAAS,EAAE;QAC1G,OAAO;KACV;IAED,KAAK,IAAM,IAAI,IAAI,IAAI,CAAC,4BAA4B,CAAC,kBAAkB,EAAE;QACrE,IAAI,CAAC,SAAS,EAAE,CAAC,wBAAwB,CAAC,IAAI,CAAC,4BAA4B,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;KACzG;IAED,IAAI,CAAC,4BAA4B,CAAC,kBAAkB,GAAG,EAAE,CAAC;AAC9D,CAAC,CAAC;AAEF,IAAI,CAAC,SAAS,CAAC,4BAA4B,GAAG;IAC1C,IAAI,IAAI,CAAC,oBAAoB,CAAC,eAAe,EAAE;QAC3C,IAAI,CAAC,oBAAoB,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC;QACpD,IAAI,CAAC,oBAAoB,CAAC,eAAe,GAAG,IAAI,CAAC;KACpD;IAED,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE;QAC1B,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;KAC/B;IAED,KAAK,IAAM,IAAI,IAAI,IAAI,CAAC,gBAAgB,EAAE;QACtC,IAAI,IAAI,CAAC,4BAA4B,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE;YACvD,IAAI,CAAC,4BAA4B,CAAC,aAAa,CAAC,IAAI,CAAE,CAAC,OAAO,EAAE,CAAC;SACpE;KACJ;IAED,IAAI,CAAC,oCAAoC,EAAE,CAAC;IAE5C,IAAI,CAAC,gBAAgB,GAAG,EAAE,CAAC;AAC/B,CAAC,CAAC","sourcesContent":["import type { Nullable, FloatArray, IndicesArray } from \"../types\";\r\nimport type { Vector3 } from \"../Maths/math.vector\";\r\nimport { Matrix, TmpVectors } from \"../Maths/math.vector\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport type { Node } from \"../node\";\r\nimport { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport type { Material } from \"../Materials/material\";\r\nimport type { Skeleton } from \"../Bones/skeleton\";\r\nimport { DeepCopier } from \"../Misc/deepCopier\";\r\nimport { TransformNode } from \"./transformNode\";\r\nimport type { Light } from \"../Lights/light\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { Tools } from \"../Misc/tools\";\r\n\r\nMesh._instancedMeshFactory = (name: string, mesh: Mesh): InstancedMesh => {\r\n const instance = new InstancedMesh(name, mesh);\r\n\r\n if (mesh.instancedBuffers) {\r\n instance.instancedBuffers = {};\r\n\r\n for (const key in mesh.instancedBuffers) {\r\n instance.instancedBuffers[key] = mesh.instancedBuffers[key];\r\n }\r\n }\r\n\r\n return instance;\r\n};\r\n\r\n/**\r\n * Creates an instance based on a source mesh.\r\n */\r\nexport class InstancedMesh extends AbstractMesh {\r\n private _sourceMesh: Mesh;\r\n private _currentLOD: Mesh;\r\n private _billboardWorldMatrix: Matrix;\r\n\r\n /** @hidden */\r\n public _indexInSourceMeshInstanceArray = -1;\r\n /** @hidden */\r\n public _distanceToCamera: number = 0;\r\n /** @hidden */\r\n public _previousWorldMatrix: Nullable<Matrix>;\r\n\r\n constructor(name: string, source: Mesh) {\r\n super(name, source.getScene());\r\n\r\n source.addInstance(this);\r\n\r\n this._sourceMesh = source;\r\n\r\n this._unIndexed = source._unIndexed;\r\n\r\n this.position.copyFrom(source.position);\r\n this.rotation.copyFrom(source.rotation);\r\n this.scaling.copyFrom(source.scaling);\r\n\r\n if (source.rotationQuaternion) {\r\n this.rotationQuaternion = source.rotationQuaternion.clone();\r\n }\r\n\r\n this.animations = Tools.Slice(source.animations);\r\n for (const range of source.getAnimationRanges()) {\r\n if (range != null) {\r\n this.createAnimationRange(range.name, range.from, range.to);\r\n }\r\n }\r\n\r\n this.infiniteDistance = source.infiniteDistance;\r\n\r\n this.setPivotMatrix(source.getPivotMatrix());\r\n\r\n this.refreshBoundingInfo(true, true);\r\n this._syncSubMeshes();\r\n }\r\n\r\n /**\r\n * Returns the string \"InstancedMesh\".\r\n */\r\n public getClassName(): string {\r\n return \"InstancedMesh\";\r\n }\r\n\r\n /** Gets the list of lights affecting that mesh */\r\n public get lightSources(): Light[] {\r\n return this._sourceMesh._lightSources;\r\n }\r\n\r\n public _resyncLightSources(): void {\r\n // Do nothing as all the work will be done by source mesh\r\n }\r\n\r\n public _resyncLightSource(): void {\r\n // Do nothing as all the work will be done by source mesh\r\n }\r\n\r\n public _removeLightSource(): void {\r\n // Do nothing as all the work will be done by source mesh\r\n }\r\n\r\n // Methods\r\n /**\r\n * If the source mesh receives shadows\r\n */\r\n public get receiveShadows(): boolean {\r\n return this._sourceMesh.receiveShadows;\r\n }\r\n\r\n /**\r\n * The material of the source mesh\r\n */\r\n public get material(): Nullable<Material> {\r\n return this._sourceMesh.material;\r\n }\r\n\r\n /**\r\n * Visibility of the source mesh\r\n */\r\n public get visibility(): number {\r\n return this._sourceMesh.visibility;\r\n }\r\n\r\n /**\r\n * Skeleton of the source mesh\r\n */\r\n public get skeleton(): Nullable<Skeleton> {\r\n return this._sourceMesh.skeleton;\r\n }\r\n\r\n /**\r\n * Rendering ground id of the source mesh\r\n */\r\n public get renderingGroupId(): number {\r\n return this._sourceMesh.renderingGroupId;\r\n }\r\n\r\n public set renderingGroupId(value: number) {\r\n if (!this._sourceMesh || value === this._sourceMesh.renderingGroupId) {\r\n return;\r\n }\r\n\r\n //no-op with warning\r\n Logger.Warn(\"Note - setting renderingGroupId of an instanced mesh has no effect on the scene\");\r\n }\r\n\r\n /**\r\n * Returns the total number of vertices (integer).\r\n */\r\n public getTotalVertices(): number {\r\n return this._sourceMesh ? this._sourceMesh.getTotalVertices() : 0;\r\n }\r\n\r\n /**\r\n * Returns a positive integer : the total number of indices in this mesh geometry.\r\n * @returns the number of indices or zero if the mesh has no geometry.\r\n */\r\n public getTotalIndices(): number {\r\n return this._sourceMesh.getTotalIndices();\r\n }\r\n\r\n /**\r\n * The source mesh of the instance\r\n */\r\n public get sourceMesh(): Mesh {\r\n return this._sourceMesh;\r\n }\r\n\r\n /**\r\n * Creates a new InstancedMesh object from the mesh model.\r\n * @see https://doc.babylonjs.com/how_to/how_to_use_instances\r\n * @param name defines the name of the new instance\r\n * @returns a new InstancedMesh\r\n */\r\n public createInstance(name: string): InstancedMesh {\r\n return this._sourceMesh.createInstance(name);\r\n }\r\n\r\n /**\r\n * Is this node ready to be used/rendered\r\n * @param completeCheck defines if a complete check (including materials and lights) has to be done (false by default)\r\n * @return {boolean} is it ready\r\n */\r\n public isReady(completeCheck = false): boolean {\r\n return this._sourceMesh.isReady(completeCheck, true);\r\n }\r\n\r\n /**\r\n * Returns an array of integers or a typed array (Int32Array, Uint32Array, Uint16Array) populated with the mesh indices.\r\n * @param kind kind of verticies to retrieve (eg. positions, normals, uvs, etc.)\r\n * @param copyWhenShared If true (default false) and and if the mesh geometry is shared among some other meshes, the returned array is a copy of the internal one.\r\n * @returns a float array or a Float32Array of the requested kind of data : positions, normals, uvs, etc.\r\n */\r\n public getVerticesData(kind: string, copyWhenShared?: boolean): Nullable<FloatArray> {\r\n return this._sourceMesh.getVerticesData(kind, copyWhenShared);\r\n }\r\n\r\n /**\r\n * Sets the vertex data of the mesh geometry for the requested `kind`.\r\n * If the mesh has no geometry, a new Geometry object is set to the mesh and then passed this vertex data.\r\n * The `data` are either a numeric array either a Float32Array.\r\n * The parameter `updatable` is passed as is to the underlying Geometry object constructor (if initially none) or updater.\r\n * The parameter `stride` is an optional positive integer, it is usually automatically deducted from the `kind` (3 for positions or normals, 2 for UV, etc).\r\n * Note that a new underlying VertexBuffer object is created each call.\r\n * If the `kind` is the `PositionKind`, the mesh BoundingInfo is renewed, so the bounding box and sphere, and the mesh World Matrix is recomputed.\r\n *\r\n * Possible `kind` values :\r\n * - VertexBuffer.PositionKind\r\n * - VertexBuffer.UVKind\r\n * - VertexBuffer.UV2Kind\r\n * - VertexBuffer.UV3Kind\r\n * - VertexBuffer.UV4Kind\r\n * - VertexBuffer.UV5Kind\r\n * - VertexBuffer.UV6Kind\r\n * - VertexBuffer.ColorKind\r\n * - VertexBuffer.MatricesIndicesKind\r\n * - VertexBuffer.MatricesIndicesExtraKind\r\n * - VertexBuffer.MatricesWeightsKind\r\n * - VertexBuffer.MatricesWeightsExtraKind\r\n *\r\n * Returns the Mesh.\r\n * @param kind\r\n * @param data\r\n * @param updatable\r\n * @param stride\r\n */\r\n public setVerticesData(kind: string, data: FloatArray, updatable?: boolean, stride?: number): AbstractMesh {\r\n if (this.sourceMesh) {\r\n this.sourceMesh.setVerticesData(kind, data, updatable, stride);\r\n }\r\n return this.sourceMesh;\r\n }\r\n\r\n /**\r\n * Updates the existing vertex data of the mesh geometry for the requested `kind`.\r\n * If the mesh has no geometry, it is simply returned as it is.\r\n * The `data` are either a numeric array either a Float32Array.\r\n * No new underlying VertexBuffer object is created.\r\n * If the `kind` is the `PositionKind` and if `updateExtends` is true, the mesh BoundingInfo is renewed, so the bounding box and sphere, and the mesh World Matrix is recomputed.\r\n * If the parameter `makeItUnique` is true, a new global geometry is created from this positions and is set to the mesh.\r\n *\r\n * Possible `kind` values :\r\n * - VertexBuffer.PositionKind\r\n * - VertexBuffer.UVKind\r\n * - VertexBuffer.UV2Kind\r\n * - VertexBuffer.UV3Kind\r\n * - VertexBuffer.UV4Kind\r\n * - VertexBuffer.UV5Kind\r\n * - VertexBuffer.UV6Kind\r\n * - VertexBuffer.ColorKind\r\n * - VertexBuffer.MatricesIndicesKind\r\n * - VertexBuffer.MatricesIndicesExtraKind\r\n * - VertexBuffer.MatricesWeightsKind\r\n * - VertexBuffer.MatricesWeightsExtraKind\r\n *\r\n * Returns the Mesh.\r\n * @param kind\r\n * @param data\r\n * @param updateExtends\r\n * @param makeItUnique\r\n */\r\n public updateVerticesData(kind: string, data: FloatArray, updateExtends?: boolean, makeItUnique?: boolean): Mesh {\r\n if (this.sourceMesh) {\r\n this.sourceMesh.updateVerticesData(kind, data, updateExtends, makeItUnique);\r\n }\r\n return this.sourceMesh;\r\n }\r\n\r\n /**\r\n * Sets the mesh indices.\r\n * Expects an array populated with integers or a typed array (Int32Array, Uint32Array, Uint16Array).\r\n * If the mesh has no geometry, a new Geometry object is created and set to the mesh.\r\n * This method creates a new index buffer each call.\r\n * Returns the Mesh.\r\n * @param indices\r\n * @param totalVertices\r\n */\r\n public setIndices(indices: IndicesArray, totalVertices: Nullable<number> = null): Mesh {\r\n if (this.sourceMesh) {\r\n this.sourceMesh.setIndices(indices, totalVertices);\r\n }\r\n return this.sourceMesh;\r\n }\r\n\r\n /**\r\n * Boolean : True if the mesh owns the requested kind of data.\r\n * @param kind\r\n */\r\n public isVerticesDataPresent(kind: string): boolean {\r\n return this._sourceMesh.isVerticesDataPresent(kind);\r\n }\r\n\r\n /**\r\n * Returns an array of indices (IndicesArray).\r\n */\r\n public getIndices(): Nullable<IndicesArray> {\r\n return this._sourceMesh.getIndices();\r\n }\r\n\r\n public get _positions(): Nullable<Vector3[]> {\r\n return this._sourceMesh._positions;\r\n }\r\n\r\n /**\r\n * This method recomputes and sets a new BoundingInfo to the mesh unless it is locked.\r\n * This means the mesh underlying bounding box and sphere are recomputed.\r\n * @param applySkeleton defines whether to apply the skeleton before computing the bounding info\r\n * @param applyMorph defines whether to apply the morph target before computing the bounding info\r\n * @returns the current mesh\r\n */\r\n public refreshBoundingInfo(applySkeleton: boolean = false, applyMorph: boolean = false): InstancedMesh {\r\n if (this.hasBoundingInfo && this.getBoundingInfo().isLocked) {\r\n return this;\r\n }\r\n\r\n const bias = this._sourceMesh.geometry ? this._sourceMesh.geometry.boundingBias : null;\r\n this._refreshBoundingInfo(this._sourceMesh._getPositionData(applySkeleton, applyMorph), bias);\r\n return this;\r\n }\r\n\r\n /** @hidden */\r\n public _preActivate(): InstancedMesh {\r\n if (this._currentLOD) {\r\n this._currentLOD._preActivate();\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * @param renderId\r\n * @param intermediateRendering\r\n * @hidden\r\n */\r\n public _activate(renderId: number, intermediateRendering: boolean): boolean {\r\n super._activate(renderId, intermediateRendering);\r\n\r\n if (!this._sourceMesh.subMeshes) {\r\n Logger.Warn(\"Instances should only be created for meshes with geometry.\");\r\n }\r\n\r\n if (this._currentLOD) {\r\n const differentSign = this._currentLOD._getWorldMatrixDeterminant() >= 0 !== this._getWorldMatrixDeterminant() >= 0;\r\n if (differentSign) {\r\n this._internalAbstractMeshDataInfo._actAsRegularMesh = true;\r\n return true;\r\n }\r\n this._internalAbstractMeshDataInfo._actAsRegularMesh = false;\r\n\r\n this._currentLOD._registerInstanceForRenderId(this, renderId);\r\n\r\n if (intermediateRendering) {\r\n if (!this._currentLOD._internalAbstractMeshDataInfo._isActiveIntermediate) {\r\n this._currentLOD._internalAbstractMeshDataInfo._onlyForInstancesIntermediate = true;\r\n return true;\r\n }\r\n } else {\r\n if (!this._currentLOD._internalAbstractMeshDataInfo._isActive) {\r\n this._currentLOD._internalAbstractMeshDataInfo._onlyForInstances = true;\r\n return true;\r\n }\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n /** @hidden */\r\n public _postActivate(): void {\r\n if (this._sourceMesh.edgesShareWithInstances && this._sourceMesh._edgesRenderer && this._sourceMesh._edgesRenderer.isEnabled && this._sourceMesh._renderingGroup) {\r\n // we are using the edge renderer of the source mesh\r\n this._sourceMesh._renderingGroup._edgesRenderers.pushNoDuplicate(this._sourceMesh._edgesRenderer);\r\n this._sourceMesh._edgesRenderer.customInstances.push(this.getWorldMatrix());\r\n } else if (this._edgesRenderer && this._edgesRenderer.isEnabled && this._sourceMesh._renderingGroup) {\r\n // we are using the edge renderer defined for this instance\r\n this._sourceMesh._renderingGroup._edgesRenderers.push(this._edgesRenderer);\r\n }\r\n }\r\n\r\n public getWorldMatrix(): Matrix {\r\n if (this._currentLOD && this._currentLOD.billboardMode !== TransformNode.BILLBOARDMODE_NONE && this._currentLOD._masterMesh !== this) {\r\n if (!this._billboardWorldMatrix) {\r\n this._billboardWorldMatrix = new Matrix();\r\n }\r\n const tempMaster = this._currentLOD._masterMesh;\r\n this._currentLOD._masterMesh = this;\r\n TmpVectors.Vector3[7].copyFrom(this._currentLOD.position);\r\n this._currentLOD.position.set(0, 0, 0);\r\n this._billboardWorldMatrix.copyFrom(this._currentLOD.computeWorldMatrix(true));\r\n this._currentLOD.position.copyFrom(TmpVectors.Vector3[7]);\r\n this._currentLOD._masterMesh = tempMaster;\r\n return this._billboardWorldMatrix;\r\n }\r\n\r\n return super.getWorldMatrix();\r\n }\r\n\r\n public get isAnInstance(): boolean {\r\n return true;\r\n }\r\n\r\n /**\r\n * Returns the current associated LOD AbstractMesh.\r\n * @param camera\r\n */\r\n public getLOD(camera: Camera): AbstractMesh {\r\n if (!camera) {\r\n return this;\r\n }\r\n\r\n const sourceMeshLODLevels = this.sourceMesh.getLODLevels();\r\n if (!sourceMeshLODLevels || sourceMeshLODLevels.length === 0) {\r\n this._currentLOD = this.sourceMesh;\r\n } else {\r\n const boundingInfo = this.getBoundingInfo();\r\n this._currentLOD = <Mesh>this.sourceMesh.getLOD(camera, boundingInfo.boundingSphere);\r\n }\r\n\r\n return this._currentLOD;\r\n }\r\n\r\n /**\r\n * @param renderId\r\n * @hidden\r\n */\r\n public _preActivateForIntermediateRendering(renderId: number): Mesh {\r\n return <Mesh>this.sourceMesh._preActivateForIntermediateRendering(renderId);\r\n }\r\n\r\n /** @hidden */\r\n public _syncSubMeshes(): InstancedMesh {\r\n this.releaseSubMeshes();\r\n if (this._sourceMesh.subMeshes) {\r\n for (let index = 0; index < this._sourceMesh.subMeshes.length; index++) {\r\n this._sourceMesh.subMeshes[index].clone(this, this._sourceMesh);\r\n }\r\n }\r\n return this;\r\n }\r\n\r\n /** @hidden */\r\n public _generatePointsArray(): boolean {\r\n return this._sourceMesh._generatePointsArray();\r\n }\r\n\r\n /** @hidden */\r\n public _updateBoundingInfo(): AbstractMesh {\r\n if (this.hasBoundingInfo) {\r\n this.getBoundingInfo().update(this.worldMatrixFromCache);\r\n } else {\r\n this.buildBoundingInfo(this.absolutePosition, this.absolutePosition, this.worldMatrixFromCache);\r\n }\r\n this._updateSubMeshesBoundingInfo(this.worldMatrixFromCache);\r\n return this;\r\n }\r\n\r\n /**\r\n * Creates a new InstancedMesh from the current mesh.\r\n * - name (string) : the cloned mesh name\r\n * - newParent (optional Node) : the optional Node to parent the clone to.\r\n * - doNotCloneChildren (optional boolean, default `false`) : if `true` the model children aren't cloned.\r\n *\r\n * Returns the clone.\r\n * @param name\r\n * @param newParent\r\n * @param doNotCloneChildren\r\n */\r\n public clone(name: string, newParent: Nullable<Node> = null, doNotCloneChildren?: boolean): InstancedMesh {\r\n const result = this._sourceMesh.createInstance(name);\r\n\r\n // Deep copy\r\n DeepCopier.DeepCopy(\r\n this,\r\n result,\r\n [\r\n \"name\",\r\n \"subMeshes\",\r\n \"uniqueId\",\r\n \"parent\",\r\n \"lightSources\",\r\n \"receiveShadows\",\r\n \"material\",\r\n \"visibility\",\r\n \"skeleton\",\r\n \"sourceMesh\",\r\n \"isAnInstance\",\r\n \"facetNb\",\r\n \"isFacetDataEnabled\",\r\n \"isBlocked\",\r\n \"useBones\",\r\n \"hasInstances\",\r\n \"collider\",\r\n \"edgesRenderer\",\r\n \"forward\",\r\n \"up\",\r\n \"right\",\r\n \"absolutePosition\",\r\n \"absoluteScaling\",\r\n \"absoluteRotationQuaternion\",\r\n \"isWorldMatrixFrozen\",\r\n \"nonUniformScaling\",\r\n \"behaviors\",\r\n \"worldMatrixFromCache\",\r\n \"hasThinInstances\",\r\n \"hasBoundingInfo\",\r\n ],\r\n []\r\n );\r\n\r\n // Bounding info\r\n this.refreshBoundingInfo();\r\n\r\n // Parent\r\n if (newParent) {\r\n result.parent = newParent;\r\n }\r\n\r\n if (!doNotCloneChildren) {\r\n // Children\r\n for (let index = 0; index < this.getScene().meshes.length; index++) {\r\n const mesh = this.getScene().meshes[index];\r\n\r\n if (mesh.parent === this) {\r\n mesh.clone(mesh.name, result);\r\n }\r\n }\r\n }\r\n\r\n result.computeWorldMatrix(true);\r\n\r\n this.onClonedObservable.notifyObservers(result);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Disposes the InstancedMesh.\r\n * Returns nothing.\r\n * @param doNotRecurse\r\n * @param disposeMaterialAndTextures\r\n */\r\n public dispose(doNotRecurse?: boolean, disposeMaterialAndTextures = false): void {\r\n // Remove from mesh\r\n this._sourceMesh.removeInstance(this);\r\n super.dispose(doNotRecurse, disposeMaterialAndTextures);\r\n }\r\n}\r\n\r\ndeclare module \"./mesh\" {\r\n export interface Mesh {\r\n /**\r\n * Register a custom buffer that will be instanced\r\n * @see https://doc.babylonjs.com/how_to/how_to_use_instances#custom-buffers\r\n * @param kind defines the buffer kind\r\n * @param stride defines the stride in floats\r\n */\r\n registerInstancedBuffer(kind: string, stride: number): void;\r\n\r\n /**\r\n * Invalidate VertexArrayObjects belonging to the mesh (but not to the Geometry of the mesh).\r\n */\r\n _invalidateInstanceVertexArrayObject(): void;\r\n\r\n /**\r\n * true to use the edge renderer for all instances of this mesh\r\n */\r\n edgesShareWithInstances: boolean;\r\n\r\n /** @hidden */\r\n _userInstancedBuffersStorage: {\r\n data: { [key: string]: Float32Array };\r\n sizes: { [key: string]: number };\r\n vertexBuffers: { [key: string]: Nullable<VertexBuffer> };\r\n strides: { [key: string]: number };\r\n vertexArrayObjects?: { [key: string]: WebGLVertexArrayObject };\r\n };\r\n }\r\n}\r\n\r\ndeclare module \"./abstractMesh\" {\r\n export interface AbstractMesh {\r\n /**\r\n * Object used to store instanced buffers defined by user\r\n * @see https://doc.babylonjs.com/how_to/how_to_use_instances#custom-buffers\r\n */\r\n instancedBuffers: { [key: string]: any };\r\n }\r\n}\r\n\r\nMesh.prototype.registerInstancedBuffer = function (kind: string, stride: number): void {\r\n // Remove existing one\r\n this._userInstancedBuffersStorage?.vertexBuffers[kind]?.dispose();\r\n\r\n // Creates the instancedBuffer field if not present\r\n if (!this.instancedBuffers) {\r\n this.instancedBuffers = {};\r\n\r\n for (const instance of this.instances) {\r\n instance.instancedBuffers = {};\r\n }\r\n\r\n this._userInstancedBuffersStorage = {\r\n data: {},\r\n vertexBuffers: {},\r\n strides: {},\r\n sizes: {},\r\n vertexArrayObjects: this.getEngine().getCaps().vertexArrayObject ? {} : undefined,\r\n };\r\n }\r\n\r\n // Creates an empty property for this kind\r\n this.instancedBuffers[kind] = null;\r\n\r\n this._userInstancedBuffersStorage.strides[kind] = stride;\r\n this._userInstancedBuffersStorage.sizes[kind] = stride * 32; // Initial size\r\n this._userInstancedBuffersStorage.data[kind] = new Float32Array(this._userInstancedBuffersStorage.sizes[kind]);\r\n this._userInstancedBuffersStorage.vertexBuffers[kind] = new VertexBuffer(this.getEngine(), this._userInstancedBuffersStorage.data[kind], kind, true, false, stride, true);\r\n\r\n for (const instance of this.instances) {\r\n instance.instancedBuffers[kind] = null;\r\n }\r\n\r\n this._invalidateInstanceVertexArrayObject();\r\n};\r\n\r\nMesh.prototype._processInstancedBuffers = function (visibleInstances: InstancedMesh[], renderSelf: boolean) {\r\n const instanceCount = visibleInstances.length;\r\n\r\n for (const kind in this.instancedBuffers) {\r\n let size = this._userInstancedBuffersStorage.sizes[kind];\r\n const stride = this._userInstancedBuffersStorage.strides[kind];\r\n\r\n // Resize if required\r\n const expectedSize = (instanceCount + 1) * stride;\r\n\r\n while (size < expectedSize) {\r\n size *= 2;\r\n }\r\n\r\n if (this._userInstancedBuffersStorage.data[kind].length != size) {\r\n this._userInstancedBuffersStorage.data[kind] = new Float32Array(size);\r\n this._userInstancedBuffersStorage.sizes[kind] = size;\r\n if (this._userInstancedBuffersStorage.vertexBuffers[kind]) {\r\n this._userInstancedBuffersStorage.vertexBuffers[kind]!.dispose();\r\n this._userInstancedBuffersStorage.vertexBuffers[kind] = null;\r\n }\r\n }\r\n\r\n const data = this._userInstancedBuffersStorage.data[kind];\r\n\r\n // Update data buffer\r\n let offset = 0;\r\n if (renderSelf) {\r\n const value = this.instancedBuffers[kind];\r\n\r\n if (value.toArray) {\r\n value.toArray(data, offset);\r\n } else if (value.copyToArray) {\r\n value.copyToArray(data, offset);\r\n } else {\r\n data[offset] = value;\r\n }\r\n\r\n offset += stride;\r\n }\r\n\r\n for (let instanceIndex = 0; instanceIndex < instanceCount; instanceIndex++) {\r\n const instance = visibleInstances[instanceIndex]!;\r\n\r\n const value = instance.instancedBuffers[kind];\r\n\r\n if (value.toArray) {\r\n value.toArray(data, offset);\r\n } else if (value.copyToArray) {\r\n value.copyToArray(data, offset);\r\n } else {\r\n data[offset] = value;\r\n }\r\n\r\n offset += stride;\r\n }\r\n\r\n // Update vertex buffer\r\n if (!this._userInstancedBuffersStorage.vertexBuffers[kind]) {\r\n this._userInstancedBuffersStorage.vertexBuffers[kind] = new VertexBuffer(\r\n this.getEngine(),\r\n this._userInstancedBuffersStorage.data[kind],\r\n kind,\r\n true,\r\n false,\r\n stride,\r\n true\r\n );\r\n this._invalidateInstanceVertexArrayObject();\r\n } else {\r\n this._userInstancedBuffersStorage.vertexBuffers[kind]!.updateDirectly(data, 0);\r\n }\r\n }\r\n};\r\n\r\nMesh.prototype._invalidateInstanceVertexArrayObject = function () {\r\n if (!this._userInstancedBuffersStorage || this._userInstancedBuffersStorage.vertexArrayObjects === undefined) {\r\n return;\r\n }\r\n\r\n for (const kind in this._userInstancedBuffersStorage.vertexArrayObjects) {\r\n this.getEngine().releaseVertexArrayObject(this._userInstancedBuffersStorage.vertexArrayObjects[kind]);\r\n }\r\n\r\n this._userInstancedBuffersStorage.vertexArrayObjects = {};\r\n};\r\n\r\nMesh.prototype._disposeInstanceSpecificData = function () {\r\n if (this._instanceDataStorage.instancesBuffer) {\r\n this._instanceDataStorage.instancesBuffer.dispose();\r\n this._instanceDataStorage.instancesBuffer = null;\r\n }\r\n\r\n while (this.instances.length) {\r\n this.instances[0].dispose();\r\n }\r\n\r\n for (const kind in this.instancedBuffers) {\r\n if (this._userInstancedBuffersStorage.vertexBuffers[kind]) {\r\n this._userInstancedBuffersStorage.vertexBuffers[kind]!.dispose();\r\n }\r\n }\r\n\r\n this._invalidateInstanceVertexArrayObject();\r\n\r\n this.instancedBuffers = {};\r\n};\r\n"]}
|
|
@@ -158,11 +158,15 @@ export declare class GeometryBufferRenderer {
|
|
|
158
158
|
*/
|
|
159
159
|
set enableVelocity(enable: boolean);
|
|
160
160
|
/**
|
|
161
|
-
* Gets a boolean indicating if objects
|
|
161
|
+
* Gets a boolean indicating if objects reflectivity are enabled in the G buffer.
|
|
162
162
|
*/
|
|
163
163
|
get enableReflectivity(): boolean;
|
|
164
164
|
/**
|
|
165
|
-
* Sets whether or not objects
|
|
165
|
+
* Sets whether or not objects reflectivity are enabled for the G buffer.
|
|
166
|
+
* For Metallic-Roughness workflow with ORM texture, we assume that ORM texture is defined according to the default layout:
|
|
167
|
+
* pbr.useRoughnessFromMetallicTextureAlpha = false;
|
|
168
|
+
* pbr.useRoughnessFromMetallicTextureGreen = true;
|
|
169
|
+
* pbr.useMetallnessFromMetallicTextureBlue = true;
|
|
166
170
|
*/
|
|
167
171
|
set enableReflectivity(enable: boolean);
|
|
168
172
|
/**
|
|
@@ -229,13 +229,17 @@ var GeometryBufferRenderer = /** @class */ (function () {
|
|
|
229
229
|
});
|
|
230
230
|
Object.defineProperty(GeometryBufferRenderer.prototype, "enableReflectivity", {
|
|
231
231
|
/**
|
|
232
|
-
* Gets a boolean indicating if objects
|
|
232
|
+
* Gets a boolean indicating if objects reflectivity are enabled in the G buffer.
|
|
233
233
|
*/
|
|
234
234
|
get: function () {
|
|
235
235
|
return this._enableReflectivity;
|
|
236
236
|
},
|
|
237
237
|
/**
|
|
238
|
-
* Sets whether or not objects
|
|
238
|
+
* Sets whether or not objects reflectivity are enabled for the G buffer.
|
|
239
|
+
* For Metallic-Roughness workflow with ORM texture, we assume that ORM texture is defined according to the default layout:
|
|
240
|
+
* pbr.useRoughnessFromMetallicTextureAlpha = false;
|
|
241
|
+
* pbr.useRoughnessFromMetallicTextureGreen = true;
|
|
242
|
+
* pbr.useMetallnessFromMetallicTextureBlue = true;
|
|
239
243
|
*/
|
|
240
244
|
set: function (enable) {
|
|
241
245
|
this._enableReflectivity = enable;
|
|
@@ -296,15 +300,123 @@ var GeometryBufferRenderer = /** @class */ (function () {
|
|
|
296
300
|
needUv = true;
|
|
297
301
|
}
|
|
298
302
|
if (this._enableReflectivity) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
+
var metallicWorkflow = false;
|
|
304
|
+
// for PBR materials: cf. https://doc.babylonjs.com/divingDeeper/materials/using/masterPBR
|
|
305
|
+
if (material.getClassName() === "PBRMetallicRoughnessMaterial") {
|
|
306
|
+
// if it is a PBR material in MetallicRoughness Mode:
|
|
307
|
+
if (material.metallicRoughnessTexture !== null) {
|
|
308
|
+
defines.push("#define ORMTEXTURE");
|
|
309
|
+
defines.push("#define REFLECTIVITY_UV".concat(material.metallicRoughnessTexture.coordinatesIndex + 1));
|
|
310
|
+
defines.push("#define METALLICWORKFLOW");
|
|
311
|
+
needUv = true;
|
|
312
|
+
metallicWorkflow = true;
|
|
313
|
+
}
|
|
314
|
+
if (material.metallic !== null) {
|
|
315
|
+
defines.push("#define METALLIC");
|
|
316
|
+
defines.push("#define METALLICWORKFLOW");
|
|
317
|
+
metallicWorkflow = true;
|
|
318
|
+
}
|
|
319
|
+
if (material.roughness !== null) {
|
|
320
|
+
defines.push("#define ROUGHNESS");
|
|
321
|
+
defines.push("#define METALLICWORKFLOW");
|
|
322
|
+
metallicWorkflow = true;
|
|
323
|
+
}
|
|
324
|
+
if (metallicWorkflow) {
|
|
325
|
+
if (material.baseTexture !== null) {
|
|
326
|
+
defines.push("#define ALBEDOTEXTURE");
|
|
327
|
+
defines.push("#define ALBEDO_UV".concat(material.baseTexture.coordinatesIndex + 1));
|
|
328
|
+
if (material.baseTexture.gammaSpace) {
|
|
329
|
+
defines.push("#define GAMMAALBEDO");
|
|
330
|
+
}
|
|
331
|
+
needUv = true;
|
|
332
|
+
}
|
|
333
|
+
if (material.baseColor !== null) {
|
|
334
|
+
defines.push("#define ALBEDOCOLOR");
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
else if (material.getClassName() === "PBRSpecularGlossinessMaterial") {
|
|
339
|
+
// if it is a PBR material in Specular/Glossiness Mode:
|
|
340
|
+
if (material.specularGlossinessTexture !== null) {
|
|
341
|
+
defines.push("#define SPECULARGLOSSINESSTEXTURE");
|
|
342
|
+
defines.push("#define REFLECTIVITY_UV".concat(material.specularGlossinessTexture.coordinatesIndex + 1));
|
|
343
|
+
needUv = true;
|
|
344
|
+
if (material.specularGlossinessTexture.gammaSpace) {
|
|
345
|
+
defines.push("#define GAMMAREFLECTIVITYTEXTURE");
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
if (material.specularColor !== null) {
|
|
350
|
+
defines.push("#define REFLECTIVITYCOLOR");
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
if (material.glossiness !== null) {
|
|
354
|
+
defines.push("#define GLOSSINESSS");
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
else if (material.getClassName() === "PBRMaterial") {
|
|
358
|
+
// if it is the bigger PBRMaterial
|
|
359
|
+
if (material.metallicTexture !== null) {
|
|
360
|
+
defines.push("#define ORMTEXTURE");
|
|
361
|
+
defines.push("#define REFLECTIVITY_UV".concat(material.metallicTexture.coordinatesIndex + 1));
|
|
362
|
+
defines.push("#define METALLICWORKFLOW");
|
|
363
|
+
needUv = true;
|
|
364
|
+
metallicWorkflow = true;
|
|
365
|
+
}
|
|
366
|
+
if (material.metallic !== null) {
|
|
367
|
+
defines.push("#define METALLIC");
|
|
368
|
+
defines.push("#define METALLICWORKFLOW");
|
|
369
|
+
metallicWorkflow = true;
|
|
370
|
+
}
|
|
371
|
+
if (material.roughness !== null) {
|
|
372
|
+
defines.push("#define ROUGHNESS");
|
|
373
|
+
defines.push("#define METALLICWORKFLOW");
|
|
374
|
+
metallicWorkflow = true;
|
|
375
|
+
}
|
|
376
|
+
if (metallicWorkflow) {
|
|
377
|
+
if (material.albedoTexture !== null) {
|
|
378
|
+
defines.push("#define ALBEDOTEXTURE");
|
|
379
|
+
defines.push("#define ALBEDO_UV".concat(material.albedoTexture.coordinatesIndex + 1));
|
|
380
|
+
if (material.albedoTexture.gammaSpace) {
|
|
381
|
+
defines.push("#define GAMMAALBEDO");
|
|
382
|
+
}
|
|
383
|
+
needUv = true;
|
|
384
|
+
}
|
|
385
|
+
if (material.albedoColor !== null) {
|
|
386
|
+
defines.push("#define ALBEDOCOLOR");
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
// SpecularGlossiness Model
|
|
391
|
+
if (material.reflectivityTexture !== null) {
|
|
392
|
+
defines.push("#define SPECULARGLOSSINESSTEXTURE");
|
|
393
|
+
defines.push("#define REFLECTIVITY_UV".concat(material.reflectivityTexture.coordinatesIndex + 1));
|
|
394
|
+
if (material.reflectivityTexture.gammaSpace) {
|
|
395
|
+
defines.push("#define GAMMAREFLECTIVITYTEXTURE");
|
|
396
|
+
}
|
|
397
|
+
needUv = true;
|
|
398
|
+
}
|
|
399
|
+
else if (material.reflectivityColor !== null) {
|
|
400
|
+
defines.push("#define REFLECTIVITYCOLOR");
|
|
401
|
+
}
|
|
402
|
+
if (material.microSurface !== null) {
|
|
403
|
+
defines.push("#define GLOSSINESSS");
|
|
404
|
+
}
|
|
405
|
+
}
|
|
303
406
|
}
|
|
304
|
-
else if (material.
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
407
|
+
else if (material.getClassName() === "StandardMaterial") {
|
|
408
|
+
// if StandardMaterial:
|
|
409
|
+
if (material.specularTexture !== null) {
|
|
410
|
+
defines.push("#define REFLECTIVITYTEXTURE");
|
|
411
|
+
defines.push("#define REFLECTIVITY_UV".concat(material.specularTexture.coordinatesIndex + 1));
|
|
412
|
+
if (material.specularTexture.gammaSpace) {
|
|
413
|
+
defines.push("#define GAMMAREFLECTIVITYTEXTURE");
|
|
414
|
+
}
|
|
415
|
+
needUv = true;
|
|
416
|
+
}
|
|
417
|
+
if (material.specularColor !== null) {
|
|
418
|
+
defines.push("#define REFLECTIVITYCOLOR");
|
|
419
|
+
}
|
|
308
420
|
}
|
|
309
421
|
}
|
|
310
422
|
if (needUv) {
|
|
@@ -408,13 +520,18 @@ var GeometryBufferRenderer = /** @class */ (function () {
|
|
|
408
520
|
"mPreviousBones",
|
|
409
521
|
"bumpMatrix",
|
|
410
522
|
"reflectivityMatrix",
|
|
523
|
+
"albedoMatrix",
|
|
524
|
+
"reflectivityColor",
|
|
525
|
+
"albedoColor",
|
|
526
|
+
"metallic",
|
|
527
|
+
"glossiness",
|
|
411
528
|
"vTangentSpaceParams",
|
|
412
529
|
"vBumpInfos",
|
|
413
530
|
"morphTargetInfluences",
|
|
414
531
|
"morphTargetTextureInfo",
|
|
415
532
|
"morphTargetTextureIndices",
|
|
416
533
|
],
|
|
417
|
-
samplers: ["diffuseSampler", "bumpSampler", "reflectivitySampler", "morphTargets"],
|
|
534
|
+
samplers: ["diffuseSampler", "bumpSampler", "reflectivitySampler", "albedoSampler", "morphTargets"],
|
|
418
535
|
defines: join,
|
|
419
536
|
onCompiled: null,
|
|
420
537
|
fallbacks: null,
|
|
@@ -588,15 +705,89 @@ var GeometryBufferRenderer = /** @class */ (function () {
|
|
|
588
705
|
effect_1.setTexture("bumpSampler", material.bumpTexture);
|
|
589
706
|
effect_1.setFloat2("vTangentSpaceParams", material.invertNormalMapX ? -1.0 : 1.0, material.invertNormalMapY ? -1.0 : 1.0);
|
|
590
707
|
}
|
|
591
|
-
//
|
|
708
|
+
// Reflectivity
|
|
592
709
|
if (_this._enableReflectivity) {
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
710
|
+
// for PBR materials: cf. https://doc.babylonjs.com/divingDeeper/materials/using/masterPBR
|
|
711
|
+
if (material.getClassName() === "PBRMetallicRoughnessMaterial") {
|
|
712
|
+
// if it is a PBR material in MetallicRoughness Mode:
|
|
713
|
+
if (material.metallicRoughnessTexture !== null) {
|
|
714
|
+
effect_1.setTexture("reflectivitySampler", material.metallicRoughnessTexture);
|
|
715
|
+
effect_1.setMatrix("reflectivityMatrix", material.metallicRoughnessTexture.getTextureMatrix());
|
|
716
|
+
}
|
|
717
|
+
if (material.metallic !== null) {
|
|
718
|
+
effect_1.setFloat("metallic", material.metallic);
|
|
719
|
+
}
|
|
720
|
+
if (material.roughness !== null) {
|
|
721
|
+
effect_1.setFloat("glossiness", 1.0 - material.roughness);
|
|
722
|
+
}
|
|
723
|
+
if (material.baseTexture !== null) {
|
|
724
|
+
effect_1.setTexture("albedoSampler", material.baseTexture);
|
|
725
|
+
effect_1.setMatrix("albedoMatrix", material.baseTexture.getTextureMatrix());
|
|
726
|
+
}
|
|
727
|
+
if (material.baseColor !== null) {
|
|
728
|
+
effect_1.setColor3("albedoColor", material.baseColor);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
else if (material.getClassName() === "PBRSpecularGlossinessMaterial") {
|
|
732
|
+
// if it is a PBR material in Specular/Glossiness Mode:
|
|
733
|
+
if (material.specularGlossinessTexture !== null) {
|
|
734
|
+
effect_1.setTexture("reflectivitySampler", material.specularGlossinessTexture);
|
|
735
|
+
effect_1.setMatrix("reflectivityMatrix", material.specularGlossinessTexture.getTextureMatrix());
|
|
736
|
+
}
|
|
737
|
+
else {
|
|
738
|
+
if (material.specularColor !== null) {
|
|
739
|
+
effect_1.setColor3("reflectivityColor", material.specularColor);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
if (material.glossiness !== null) {
|
|
743
|
+
effect_1.setFloat("glossiness", material.glossiness);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
else if (material.getClassName() === "PBRMaterial") {
|
|
747
|
+
// if it is the bigger PBRMaterial
|
|
748
|
+
if (material.metallicTexture !== null) {
|
|
749
|
+
effect_1.setTexture("reflectivitySampler", material.metallicTexture);
|
|
750
|
+
effect_1.setMatrix("reflectivityMatrix", material.metallicTexture.getTextureMatrix());
|
|
751
|
+
}
|
|
752
|
+
if (material.metallic !== null) {
|
|
753
|
+
effect_1.setFloat("metallic", material.metallic);
|
|
754
|
+
}
|
|
755
|
+
if (material.roughness !== null) {
|
|
756
|
+
effect_1.setFloat("glossiness", 1.0 - material.roughness);
|
|
757
|
+
}
|
|
758
|
+
if (material.roughness !== null || material.metallic !== null || material.metallicTexture !== null) {
|
|
759
|
+
// MetallicRoughness Model
|
|
760
|
+
if (material.albedoTexture !== null) {
|
|
761
|
+
effect_1.setTexture("albedoSampler", material.albedoTexture);
|
|
762
|
+
effect_1.setMatrix("albedoMatrix", material.albedoTexture.getTextureMatrix());
|
|
763
|
+
}
|
|
764
|
+
if (material.albedoColor !== null) {
|
|
765
|
+
effect_1.setColor3("albedoColor", material.albedoColor);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
else {
|
|
769
|
+
// SpecularGlossiness Model
|
|
770
|
+
if (material.reflectivityTexture !== null) {
|
|
771
|
+
effect_1.setTexture("reflectivitySampler", material.reflectivityTexture);
|
|
772
|
+
effect_1.setMatrix("reflectivityMatrix", material.reflectivityTexture.getTextureMatrix());
|
|
773
|
+
}
|
|
774
|
+
else if (material.reflectivityColor !== null) {
|
|
775
|
+
effect_1.setColor3("reflectivityColor", material.reflectivityColor);
|
|
776
|
+
}
|
|
777
|
+
if (material.microSurface !== null) {
|
|
778
|
+
effect_1.setFloat("glossiness", material.microSurface);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
596
781
|
}
|
|
597
|
-
else if (material.
|
|
598
|
-
|
|
599
|
-
|
|
782
|
+
else if (material.getClassName() === "StandardMaterial") {
|
|
783
|
+
// if StandardMaterial:
|
|
784
|
+
if (material.specularTexture !== null) {
|
|
785
|
+
effect_1.setTexture("reflectivitySampler", material.specularTexture);
|
|
786
|
+
effect_1.setMatrix("reflectivityMatrix", material.specularTexture.getTextureMatrix());
|
|
787
|
+
}
|
|
788
|
+
if (material.specularColor !== null) {
|
|
789
|
+
effect_1.setColor3("reflectivityColor", material.specularColor);
|
|
790
|
+
}
|
|
600
791
|
}
|
|
601
792
|
}
|
|
602
793
|
}
|